简体   繁体   English

Google Chrome新标签页的网址是什么,以及如何将其从manifest.json中排除

[英]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? 真正的问题是:是否有人知道谷歌新标签页的正确网址或如何将其排除在清单文件中?

Please note that most of the content in my original answer from 2016 no longer holds true. 请注意,2016年原始答案中的大部分内容不再适用。

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 Patternschrome不是一个有效的方案。

scheme := '*' | scheme:='*'| 'http' | 'http'| 'https' | 'https'| 'file' | '文件'| 'ftp' 'FTP'

  1. You could use the following exclude_matches 您可以使用以下exclude_matches

     "exclude_matches": ["*://*/_/chrome/newtab*"] 
  2. 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.

相关问题 Chrome 扩展程序,如何在 manifest.json 中排除 chrome:// URI - Chrome extension, how to exclude chrome:// URIs in manifest.json 如何从Chrome扩展程序的选项页面启用/禁用manifest.json CSS内容脚本? - How to enable/disable manifest.json CSS content script from Chrome Extension's options page? Chrome扩展程序帮助-将打开页面的网址添加到manifest.json中default_popup的html中的过程是什么? - Chrome extension help - what's the process for adding the url of an open page to the html of the default_popup in manifest.json 在Google Chrome扩展程序manifest.json中启用跨域权限 - Enable cross domain permission in google chrome extension manifest.json 如何在我的manifest.json文件中包括jQuery扩展的jQuery - How to include jQuery in my manifest.json file for a chrome Extension 如何在 manifest.json 在 PWA 中传递动态 URL - how to pass dynamic URL in manifest.json in PWA PWA:如何在 manifest.json 中使用动态“start_url” - PWA: How to have dynamic "start_url" in manifest.json Manifest.json中的Chrome扩展程序的自定义值? - Custom Values in Manifest.json for Chrome Extensions? 在Chrome扩展manifest.json中检测锚点 - Detect anchor in Chrome Extension manifest.json 在 React 应用中 manifest.json 有什么用? - What is the use of manifest.json in React app?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM