Thanks @kofifus for the info, Chrome as of 61 explicitly forbids content scripts on its default new tab page
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 through chrome://flags/#extensions-on-chrome-urls
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.
There are many mouse gestures extension available, like crxMouse, they work well on chrome://newtab
page
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
and 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?
A content script is a part of your extension that runs in the context of a particular web page (as opposed to background scripts which are part of the extension, or scripts which are part of the website itself, such as those loaded using the <script> element).
Background Script - Provides persistence and handles background events. Content Script - Scripts that run in isolation in the context of the web page. Injected Script - Scripts that are programmatically injected into the web page.
New Tab: The page that appears when the user creates a new tab or window. You can also get to this page by entering the URL chrome://newtab. Note: A single extension can override only one page. For example, an extension can't override both the Bookmark Manager and History pages.
You can use the Allow web content on New Tab page group policy to enable or disable web content on the New Tab page in Microsoft Edge. Disabling this policy loads a blank page instead of the New tab page and prevents users from changing it.
Content scripts are unable to access other APIs directly. Content scripts live in an isolated world, allowing a content script to make changes to its JavaScript environment without conflicting with the page or other extensions' content scripts.
Although the execution environments of content scripts and the pages that host them are isolated from each other, they share access to the page's DOM. If the page wishes to communicate with the content script, or with the extension via the content script, it must do so through the shared DOM.
Content scripts are files that run in the context of web pages. By using the standard Document Object Model (DOM), they are able to read details of the web pages the browser visits, make changes to them and pass information to their parent extension. Understand content script capabilities #
Chrome as of 61 explicitly forbids content scripts on its default new tab page
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With