Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 795
Haibara Ai Avatar asked Aug 15 '16 03:08

Haibara Ai


People also ask

What is a content script?

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).

What is background script and content script?

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.

What is the URL for a new tab?

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.

How to enable or disable web content on the new tab page?

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.

Can content scripts access other APIs?

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.

What is the relationship between the page and content script?

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.

What are content scripts?

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 #


1 Answers

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

like image 95
kofifus Avatar answered Sep 22 '22 19:09

kofifus