Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the URL of the google chrome new tab page and how to exclude it from manifest.json

I am currently building a simple google chrome extension to prank my brother. The Extension simply deletes the old page and replaces it with HTML and CSS copied off of the "You have no internet" page, In essence making the user think they don't have internet when they do. The following is the content script injected into all new pages:

var hed = document.head;
var bod = document.body;
document.head.parentElement.removeChild(document.head);
document.body.parentElement.removeChild(document.body);
document.write(/*Copy of "no internet" page source here*/);

This script works perfectly. The only page i don't want the change to occur on is the google chrome New Tab page. The way to go about normally excluding pages is to specify it in the Extensions manifest.json file under the content scripts. Here was my original manifest.json setup:

{
    "manifest_version": 2,

    "name": "No Internet Extention",
    "description": "Make people with this extention think they have no internet",
    "version": "1.0",

    "content_scripts": 
    [
        {
          "matches": ["*://*/*"],
          "js": ["bup.js"]
        }
    ],

    "permissions": 
    [
        "activeTab",
        "https://ajax.googleapis.com/"
    ]
}

I have currently tried the following set ups in my manifest.json file content_scripts section in order to exclude the Chrome New Tab page to no avail:

"matches": ["http://*/*", "https://*/*"]

I assumed this would exclude it because This page on the google product forms Told me that the URL of the New Tab page is "chrome://newtab", which is not a HTTP: or HTTPS: Protocol.

I also Tried:

"matches": ["*//*/*"]
"exclude_matches": ["chrome://newtab"]

"matches": ["*//*/*"]
"exclude_matches": ["chrome://newtab/*"]

"matches": ["*//*/*"]
"exclude_matches": ["*://newtab/*"]

"matches": ["*//*/*"]
"exclude_globs": ["chrome://newtab"]

None of these have worked and the content script still executes on the new tab page. I believe the root of the problem here is that my New Tab URL is incorrect. My research for excluding pages was done here: Google Content Scripts Page. The real question is: Does anyone know the proper URL for the google new tab page or how to go about excluding it in a manifest file?

like image 368
James Oswald Avatar asked May 17 '16 22:05

James Oswald


People also ask

What is the URL for Chrome new tab 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.

How do I isolate a tab in Chrome?

On your computer, open Chrome. In the address bar at the top, enter chrome://flags/#enable-site-per-process and press Enter. Next to "Strict site isolation," click Enable. If you don't see "Strict site isolation," update Chrome.

Can you get rid of the Google search bar on New tab page?

To remove that Google search box form new tab, first install Replace New Tab Page extension. Once you install, you will get an option to fill a web page. Here you can fill any web page that you want to see every time you open a new tab. You can also use Google Chrome flags in that address.


2 Answers

Please note that most of the content in my original answer from 2016 no longer holds true.

  • As of Chrome v61, content scripts are no longer allowed on the New Tab Page.

  • The URL of the new tab page has changed to chrome-search://local-ntp/local-ntp.html.

  • If you want to create a custom New Tab Page, use override pages.

I decided to delete the original content of this answer to avoid possibly misleading somebody. The original answer can be viewed in edit history.

like image 118
Petr Srníček Avatar answered Oct 03 '22 12:10

Petr Srníček


According to Match Patterns, chrome is not a valid scheme.

scheme := '*' | 'http' | 'https' | 'file' | 'ftp'

  1. You could use the following exclude_matches

    "exclude_matches": ["*://*/_/chrome/newtab*"]
    
  2. You could also check if window.location.href contains chrome/newtab in you content scripts.

like image 42
Haibara Ai Avatar answered Oct 03 '22 12:10

Haibara Ai