问题描述
更新
感谢@kofifus的信息,Chrome自61开始
和
所以它看起来很奇怪,因为它在不同设备(或设置?)上的行为不同。是否有关于内容脚本是否可以在 chrome:// newtab
页面中运行的官方声明?或者是否有一个设置可以改变这种行为?
Updated
Thanks @kofifus for the info, Chrome as of 61 explicitly forbids content scripts on its default new tab page
Previous
Say I have the following sample extension, it will output test
in console.
manifest.json
{
"name": "Test",
"version": "1.0",
"manifest_version": 2,
"content_scripts": [
{
"matches": [
"<all_urls>"
],
"js": [
"content.js"
]
}
]
}
content.js
console.log('test');
Will above extension work well in chrome://newtab
page?
Some helpful info:
I know by default chrome extension can't access to
chrome://
pages, and we could change this behavior throughchrome://flags/#extensions-on-chrome-urls
chrome://newtab
in fact is a url likehttps://www.google.co.jp/_/chrome/newtab?espv=2&ie=UTF-8
, so it shouldn't be blocked by above restriction.There are many mouse gestures extension available, like crxMouse, they work well on
chrome://newtab
pageThere are also some voices saying it's not allowed to inject content scripts in
chrome://newtab
, for example, @Xan's comments below this answerand this author's case
So it looks weird as its different behavior across different devices( or settings?). Is there any official statements about whether content scripts can run in chrome://newtab
pages? Or is there a setting we could change this behavior?
Chrome as of 61 explicitly forbids content scripts on its default new tab page
这篇关于内容脚本是否可以访问newtab页面?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!