Chrome内容脚本和newtab [英] chrome content scripts and newtab

查看:244
本文介绍了Chrome内容脚本和newtab的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I am not able to run my content script on the new tab page (where it is not assigned to any url).

我查看了主题,即内容脚本是否可以访问newtab页面?
什么是google chrome新标签页的网址,以及如何将它从manifest.json中排除

其中似乎暗示它是可能的。

which seem to suggest it is possible.

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

I enabled chrome://flags/#extensions-on-chrome-urls

我有:

I have:

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

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

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

still no luck ... what am I missing ?

thi s答案你可以从扩展中访问chrome://页面吗? mentsions通配符不被接受。这是真的 ?如果是的话如何指定newtab页面?

this answer Can you access chrome:// pages from an extension? mentsions "wildcards are not accepted". Is this true ? and if so how to specify the newtab page ?

Thx!

推荐答案

Chrome 61和更新的在默认新标签页(NTP)上明确禁止内容脚本。

Chrome 61 and newer explicitly forbid content scripts on the default new tab page (NTP).

引用rdevlin,Chrome扩展API的开发人员之一: b
$ b

Quoting rdevlin, one of the developers of chrome extensions API:


有几个原因为了这个改变。一个是执行政策,
另一个是一致性。

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

我们有一个公共政策一段时间后,现在指出修改
NTP是通过(尽管
在很多情况下直到7月1日才开始执行此政策)。这是
仅仅是使Chrome代码更符合相同的政策,以帮助防止
惊喜,如果一个扩展正在修改NTP并被取消为政策
侵犯。

We've had a public policy for awhile now that states that modification of the NTP through anything other than Chrome URL overrides isn't allowed (though we didn't begin enforcing this policy in many cases until July 1st). This is merely bringing chrome code more inline with that same policy to help prevent surprise if an extension is modifying the NTP and is taken down for policy violations.

这也是为了保持一致性,因为我们实际上已经对NTP
上的脚本进行了不同的处理,这是因为某些NTP魔术。例如,浏览器在NTP上看到
的URL是chrome:// newtab,但渲染器中的url是
https://www.google.com/_/chrome/newtab 。由于chrome.tabs.executeScript在浏览器中检查
的URL,即使内容脚本
(在渲染器中选中)也将被允许,该脚本将被拒绝。从理论上讲,这些权限应该是
不是是不同的。同样奇怪的是,如果用户正在使用本地ntp
(chrome-search://local-ntp/local-ntp.html),那么在渲染器和浏览器中都将禁止注入
。而且,如果我们返回waaaaay,那么
NTP曾经是纯粹的WebUI,其URL为chrome:// newtab,而注入
又被禁止。我们希望在整个系统中具有一致性
,而不是根据
类型的脚本注入类型的不一致行为。

This is also for consistency, since we've actually treated scripts on the NTP differently for years now, due to certain NTP magic. For example, the URL seen by the browser on the NTP is chrome://newtab, but the url in the renderer is https://www.google.com/_/chrome/newtab. Since chrome.tabs.executeScript checks the URL in the browser, the script would be denied, even though content scripts (checked in the renderer) would be allowed. In theory, these permissions should not be different. Similarly odd, if the user is using the local ntp (chrome-search://local-ntp/local-ntp.html), injection would already be disallowed 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 injections were again disallowed. Rather than have inconsistent behavior depending on the type of script injection the extension uses, we want to have consistency throughout the system.

我会看看我是否不能用这个
公告发布铬扩展@中的公告(尽管该政策现在已经发布了一段时间,但额外的小额暴露不会损害)。

I'll see if I can't post an announcement in chromium-extensions@ with this announcement (even though the policy's been published for awhile now, a little extra exposure couldn't hurt).

这篇关于Chrome内容脚本和newtab的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆