Does content script have access to newtab page?

后端 未结 2 1937
一整个雨季
一整个雨季 2020-12-15 22:18

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 foll

相关标签:
2条回答
  • 2020-12-15 22:39

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

    0 讨论(0)
  • 2020-12-15 22:48

    Q: Is there any official statements about whether content scripts can run in chrome://newtab pages?

    A: Not really, but Google's documentation states that:

    Host permissions and content script matching are based on a set of URLs defined by match patterns. A match pattern is essentially a URL that begins with a permitted scheme (http, https, file, or ftp, and that can contain '*' characters. The special pattern matches any URL that starts with a permitted scheme.

    chrome://newtab only redirects the user to whatever url is set as the new tab page. Usually it will redirect the user to https://<your local google domain>/_/chrome/newtab(a permitted match pattern). But if another extension sets the new tab page to customNewTab.html, then chrome://newtab will redirect the user to chrome-extension://chrome-id/customNewTab.html, and any other extension's content scripts will not be able to run on the new tab.

    This SA question also confirms this. If you try adding "exclude_matches": ["*://*/_/chrome/newtab*"], to your manifest, the content script will stop working on the new tab page.

    Q: Is there a setting that could change this behavior?

    None beside an override page set by another extension. (Note that themes only change the appearance of the new tab, and won't override the new tab url)

    Q: Will above extension work well in chrome://newtab page?

    A: yes, unless that tab was overriden by another extension.

    I have a 30,000 user extension called Screen Shader on the extension store with a huge variety of different chrome versions and a few different browsers, and so far no one has complained about it not working on the new tab page, when they complain a lot about other things.

    I'm not too sure why other people think it shouldn't work on the new tab page, but hopefully this answered all the questions you were having.

    On a sidenote: Keypress problems with the new tab page

    On his blogpost at http://www.toptip.ca/2010/01/google-chrome-content-script.html the developer of "Boss Key and Button" complains about issues with running a content script in the new tab page. His extension minimizes all chrome windows and opens the one you are currently on in a new tab whenever you press F9. He thought the content script didn't work on the new tab page because whenever he used his shortcut in the new tab page, nothing happened. He failed to realize that the reason it wasn't working on the new tab page was because chrome redirects any keypresses to the browser bar so his content script could not capture the keypress.

    Try using his extension and pressing F9 on a random page. All chrome windows will be minimized. go back to that random page, and click in the address bar and try pressing F9. This time nothing will happen.

    0 讨论(0)
提交回复
热议问题