【问题标题】:Chrome extension says "Wants access to this site"Chrome 扩展程序显示“想要访问此站点”
【发布时间】:2021-03-03 22:23:25
【问题描述】:

我的 Chrome 扩展程序的 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 在灰色(非活动)和彩色(活动)之间切换扩展图标。


When the tab shows the content of the ma​​tching URL document, the icon is colored (active) and when I hover my mouse over this icon, the tooltip says "Has access to this网站”。

当标签显示 不匹配 URL 文档的内容时,图标变灰(无效),当我将鼠标悬停在该图标上时,工具提示显示“想要访问到这个网站”。

为什么工具提示说扩展程序想要访问一个不匹配的站点(例如https://stackoverflow.com,但它不是真的?这肯定会让用户感到困惑。我可以阻止显示这样的消息吗?

【问题讨论】:

  • tabId = tab.id - 这是错字吗?你不是说 tabId == tab.id 吗?
  • 您需要删除activeTab 权限。这也应该自动处理图标颜色,所以你甚至不需要 onUpdated。

标签: javascript google-chrome google-chrome-extension


【解决方案1】:

我找到了导致此消息的原因。

这是webNavigation 权限。添加此权限时,会显示这样的消息。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-07-09
    • 1970-01-01
    • 1970-01-01
    • 2016-09-13
    • 2010-11-29
    • 2014-02-07
    相关资源
    最近更新 更多