代码之家  ›  专栏  ›  技术社区  ›  Ωmega

Chrome扩展称“希望访问此站点”

  •  0
  • Ωmega  · 技术社区  · 3 年前

    manifest.json 包含以下部分:

    "permissions": [
      "activeTab",
      "webNavigation",
      "webRequest",
      "webRequestBlocking",
      "*://example.com/*",
      "*://*.example.com/*"
    ],
    
    "content_scripts": [
        {
          "run_at": "document_start",
          "matches": [
            "*://example.com/*",
            "*://*.example.com/*"
          ],
          "all_frames": true,
          "match_about_blank": true,
          "js": [ "scripts/init.js" ]
        }
      ]
    

    所以它只在一个域名上运行 (例如) example.com


    我的 background.js 脚本包含以下代码:

    async function setIcon(tabId, path) {
      // based on several parameters show the icon in different colors
      // calls chrome.browserAction.setIcon with customized imageData
    }
    
    chrome.tabs.onUpdated.addListener((tabId, changeInfo, tab) => {
      if (changeInfo && (changeInfo.status === 'loading') && (tabId === tab.id)) {
        setIcon(tabId, (tab.url != undefined) ? '../icons/active/scalable.svg' :
                                                '../icons/inactive/scalable.svg');
      }
    });
    

    它根据选项卡的匹配URL在灰色(非活动)和彩色(活动)之间切换扩展图标。


    匹配 有权访问此网站

    当选项卡显示 URL文档,图标为灰色(非活动),当我将鼠标悬停在该图标上时,工具提示显示“ 希望访问此站点

    为什么工具提示说扩展需要访问不匹配的站点 https://stackoverflow.com ) 什么时候不是真的?这肯定会让用户感到困惑。我可以阻止显示这样的消息吗?

    0 回复  |  直到 3 年前
        1
  •  1
  •   Ωmega    3 年前

    我发现了这条消息的原因。

    它是 webNavigation 准许添加此权限时,将显示这样的消息。