Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.2k views
in Technique[技术] by (71.8m points)

google chrome - Does content script have access to newtab page?

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:

  1. I know by default chrome extension can't access to chrome:// pages, and we could change this behavior through chrome://flags/#extensions-on-chrome-urls

  2. chrome://newtab in fact is a url like https://www.google.co.jp/_/chrome/newtab?espv=2&ie=UTF-8, so it shouldn't be blocked by above restriction.

  3. There are many mouse gestures extension available, like crxMouse, they work well on chrome://newtab page

  4. There are also some voices saying it's not allowed to inject content scripts in chrome://newtab, for example, @Xan's comments below this answer enter image description here and this author's case enter image description here

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?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Chrome as of 61 explicitly forbids content scripts on its default new tab page


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...