[英]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.
扩展只是删除旧页面并将其替换为从“你没有互联网”页面复制的HTML和CSS,实质上是让用户认为他们没有互联网。 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.
我不希望发生更改的唯一页面是Google Chrome新标签页。 The way to go about normally excluding pages is to specify it in the Extensions manifest.json file under the content scripts.
通常排除页面的方法是在内容脚本下的Extensions manifest.json文件中指定它。 Here was my original manifest.json setup:
这是我原来的manifest.json设置:
{
"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: 我目前在manifest.json文件content_scripts部分尝试了以下设置,以便排除Chrome新标签页无效:
"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. 我认为这会排除它,因为谷歌产品表格上的这个页面告诉我新标签页面的URL是“chrome:// newtab”,它不是HTTP:或HTTPS:协议。
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 .
我在这里完成了排除页面的研究: 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?
真正的问题是:是否有人知道谷歌新标签页的正确网址或如何将其排除在清单文件中?
As of Chrome v61, content scripts are no longer allowed on the New Tab Page . 自Chrome v61起, 新标签页上不再允许使用内容脚本 。
The URL of the new tab page has changed to chrome-search://local-ntp/local-ntp.html
. 新标签页的网址已更改为
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.
可以在编辑历史记录中查看原始答案。
According to Match Patterns , chrome
is not a valid scheme. 根据Match Patterns ,
chrome
不是一个有效的方案。
scheme := '*' |
scheme:='*'| 'http' |
'http'| 'https' |
'https'| 'file' |
'文件'| 'ftp'
'FTP'
You could use the following exclude_matches
您可以使用以下
exclude_matches
"exclude_matches": ["*://*/_/chrome/newtab*"]
You could also check if window.location.href
contains chrome/newtab
in you content scripts. 您还可以检查
window.location.href
包含内容脚本中的chrome/newtab
。
Opened a new tab, opened the Dev Tools - Network tab. 打开一个新选项卡,打开Dev Tools - Network选项卡。 Looks like it requests https://www.google.com/_/chrome/newtab .
看起来它要求https://www.google.com/_/chrome/newtab 。 Try with this one, maybe.
也许尝试使用这个。
It's probably safer to use "exclude_globs"
instead of "exclude_matches"
. 使用
"exclude_globs"
代替"exclude_matches"
可能更安全。 With "exclude_matches": ["*://*/_/chrome/newtab*"]
you could unintentionally skip something like http://example.com/_/chrome/newtab : 使用
"exclude_matches": ["*://*/_/chrome/newtab*"]
您可能会无意中跳过http://example.com/_/chrome/newtab之类的内容 :
"content_scripts": [{
"matches": ["<all_urls>"],
"exclude_globs": ["https://www.google.*/_/chrome/newtab*"],
"run_at": "document_end",
"js": ["script.js"]
}],
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.