gpt4 book ai didi

google-chrome - chrome 内容脚本和 newtab

转载 作者:行者123 更新时间:2023-12-03 21:09:29 25 4
gpt4 key购买 nike

我无法在新标签页上运行我的内容脚本(它没有分配给任何 url)。

我查看了有关该主题的各种帖子,即 Does content script have access to newtab page?
What is the URL of the google chrome new tab page and how to exclude it from manifest.json

这似乎表明这是可能的。

我启用了 chrome://flags/#extensions-on-chrome-urls

我有:

"permissions": [
"http://*/*",
"https://*/*",
"chrome://*/*"
],

(也试过 "*://*/_/chrome/newtab*" )

仍然没有运气......我错过了什么?

这个答案 Can you access chrome:// pages from an extension? 提到“不接受通配符”。这是真的 ?如果是这样如何指定新标签页?

谢谢!

最佳答案

默认新标签页 (NTP) 上的 Chrome 61 和更新的 explicitly forbid 内容脚本。
解决方案是将整个替换页面创建为扩展中的 html 文件,并在 chrome_url_overrides 中指定它。
引用 rdevlin,chrome 扩展 API 的开发者之一:

There's a few reasons for this change. One is to enforce policy,the other is for consistency.

  • We've had a public policy for awhile now that states that modification ofthe NTP through anything other than Chrome URL overrides isn't allowed (thoughwe didn't begin enforcing this policy in many cases until July 1st). This ismerely bringing chrome code more inline with that same policy to help preventsurprise if an extension is modifying the NTP and is taken down for policyviolations.
  • This is also for consistency, since we've actually treated scripts on the NTPdifferently for years now, due to certain NTP magic. For example, the URL seenby the browser on the NTP is chrome://newtab, but the url in the renderer ishttps://www.google.com/_/chrome/newtab. Since chrome.tabs.executeScript checksthe URL in the browser, the script would be denied, even though content scripts(checked in the renderer) would be allowed. In theory, these permissions shouldnot be different. Similarly odd, if the user is using the local ntp(chrome-search://local-ntp/local-ntp.html), injection would already bedisallowed in both the renderer and the browser. And, if we go waaaaay back,the NTP used to be pure WebUI with an URL of chrome://newtab, where injectionswere again disallowed. Rather than have inconsistent behavior depending on thetype of script injection the extension uses, we want to have consistencythroughout the system.

关于google-chrome - chrome 内容脚本和 newtab,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45659294/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com