You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何让Firefox扩展默认启用chess.com的「始终允许」选项

Firefox Chess.com扩展权限问题解决方案

问题原因

Firefox 对 Manifest V3 扩展的权限策略默认是「按需启用」,哪怕你已经配置了 host_permissions,扩展也不会自动在 chess.com 上运行,必须用户手动右键扩展图标选择「始终允许在chess.com上运行」,否则只能点击绿色圆点临时启动。


解决办法

1. 给用户添加引导提示

你可以在扩展里加入检测逻辑,当用户未授权时主动提示操作:

方案一:在内容脚本中弹窗提示

修改 content.js,加入权限检测和提示代码:

// content.js
async function checkAndPromptPermission() {
  const requiredPermissions = { origins: ["https://www.chess.com/*"] };
  const hasPermission = await browser.permissions.contains(requiredPermissions);
  
  if (!hasPermission) {
    // 创建提示弹窗
    const promptDiv = document.createElement('div');
    promptDiv.style.cssText = `
      position: fixed;
      top: 30px;
      right: 30px;
      background: #ffffff;
      border: 1px solid #e0e0e0;
      border-radius: 8px;
      padding: 20px;
      box-shadow: 0 2px 10px rgba(0,0,0,0.1);
      z-index: 99999;
      max-width: 300px;
    `;
    promptDiv.innerHTML = `
      <h4 style="margin-top:0;">启用扩展全部功能</h4>
      <p style="font-size:14px;">请右键点击浏览器右上角的扩展图标,选择「始终允许在chess.com上运行」</p>
      <button onclick="this.parentElement.remove()" style="margin-top:15px;padding:8px 16px;background:#0078d4;color:white;border:none;border-radius:4px;cursor:pointer;">
        知道了
      </button>
    `;
    document.body.appendChild(promptDiv);
  }
}

// 页面加载时检测
checkAndPromptPermission();
方案二:在扩展弹窗中添加说明

修改 options.html,当用户点击扩展图标时直接看到引导:

<!-- options.html -->
<!DOCTYPE html>
<html>
<head>
  <style>
    body { width: 280px; padding: 15px; font-family: Arial, sans-serif; }
    .tip { color: #333; line-height: 1.5; }
  </style>
</head>
<body>
  <h3>扩展使用提示</h3>
  <p class="tip">请右键点击浏览器右上角的扩展图标,选择「始终允许在chess.com上运行」,否则扩展无法自动生效哦~</p>
</body>
</html>

2. 关于「默认自动启用」的说明

Firefox 出于安全和隐私保护,不允许扩展通过代码自动设置「始终允许在站点运行」,这个权限必须由用户手动操作授予,没有办法绕过这个限制,所以引导提示是最可行的方案。


确认现有Manifest配置

你的 manifest.json 配置是正确的,不需要修改:

{
    "manifest_version": 3,
    "name": "Name",
    "version": "2.1",
    "permissions": [
        "storage"
    ],
    "host_permissions": [
        "https://api.chess.com/*",
        "*://*.chess.com/*"
    ],
    "background": {
        "scripts": ["background.js"]
    },
    "content_scripts": [{
        "matches": ["https://www.chess.com/*"],
        "js": ["content.js"]
    }],
    "action": {
        "default_icon": "knook.png",
        "default_popup": "options.html"
    },
    "options_ui": {
        "page": "options.html"
    },
    "browser_specific_settings": {
        "gecko": {
            "id": "identifier@name.com"
        }
    }
}

内容的提问来源于stack exchange,提问作者Zinkelburger

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.12 09:43:35