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
229 views
in Technique[技术] by (71.8m points)

javascript - 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?

See Question&Answers more detail:os

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

1 Reply

0 votes
by (71.8m points)

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

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


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

...