google chrome新标签页的网址是什么,以及如何将其从manifest.json中排除 [英] What is the URL of the google chrome new tab page and how to exclude it from manifest.json

查看:205
本文介绍了google chrome新标签页的网址是什么,以及如何将其从manifest.json中排除的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前正在构建一个简单的Google Chrome扩展程序来恶作剧我的兄弟。该扩展只是删除旧页面,并将其替换为从您没有互联网页面复制的HTML和CSS,实质上使用户认为他们在没有互联网时就认为他们没有。以下是注入所有新页面的内容脚本:

  var hed = document.head; 
var bod = document.body;
document.head.parentElement.removeChild(document.head);
document.body.parentElement.removeChild(document.body);
document.write(/ *复制无互联网页面源代码* /);

这个脚本完美地工作。我不希望发生变化的唯一页面是谷歌浏览器新标签页。通常排除页面的方法是在内容脚本下的Extensions manifest.json文件中指定它。这是我原来的manifest.json设置:

  {
manifest_version:2,

name:没有互联网延伸,
描述:让这个延伸的人认为他们没有互联网,
版本:1.0,

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

权限:
[
activeTab,
https://ajax.googleapis .com /

}

我目前已尝试以下设置在我的manifest.json文件的content_scripts部分,以排除Chrome新标签页无效:

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

我认为这会排除它,因为此页面上谷歌产品形式告诉我,新标签页的URL是chrome:// newtab,它不是HTTP:或HTTPS:协议。



我也试过:

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

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

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

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

这些都没有奏效,内容脚本仍然在新标签页上执行。我相信问题的根源在于我的新标签网址不正确。我对排除网页的研究是在这里完成的: Google内容脚本页。真正的问题是:有没有人知道谷歌新标签页的正确URL或如何去清除它在清单文件? $ c>到地址栏中,它会重定向到 https://<您的本地Google域> / _ / chrome / newtab 。即使没有连接可用,情况也是如此。该内容显然被缓存在Chrome的某个位置,因此该页面可以正确脱机显示,但该网址仍然是 https://<您的本地Google网域> / _ / chrome / newtab

无需在清单中排除 chrome:// newtab URL,因为 chrome:// 不是内容脚本的允许方案,所以< all_urls> *:// * / * 将权限授予 chrome:// 网址。 (使用 chrome:// flags /#extensions-on-chrome-urls chrome:// URL你只需要排除 *:// * / _ / chrome / newtab * (因为Haibara Bai已经存在在他的回答中说)。



您的代码中的其他问题:


  1. 您需要在清单中包含run_at:document_start
    内容脚本在加载完页面DOM后默认加载,所以用户在实际改变内容之前会清楚地看到某些内容已经加载。请参阅文档。显然,由于在DOM加载之前您将运行内容脚本,因此您无法在代码中使用 document.head 等操作DOM。


  2. 由于您没有使用程序化注入,因此不需要在permissions部分中包含任何内容

工作示例:



manifest.json:

  {
manifest_version:2,

name:没有互联网延伸,
description:让这个延伸的人认为他们没有互联网,
version:1.0,

content_scripts:
[
{
matches:[< all_urls>],
exclude_matches:[*:// * / _ / chrome / newtab *],
js:[bup.js],
run_at:document_start
}
]

}



bup.js:

  document.wr ite(< body>< p>我想让您认为您没有互联网连接。< / p>< / body>); 

顺便说一句:
显然,在Chrome地址栏中输入文字,所以他们应该很明显地看到互联网连接实际上正在工作。您可以通过使用 chrome.webRequest API 真正阻止来自Chrome的流量来实现您的目标。 。


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?

解决方案

While the New Tab page can be opened by typing chrome://newtab into the address bar, it redirects to https://<your local google domain>/_/chrome/newtab. This is true even when no connection is available. The content is obviously cached somewhere in Chrome, so the page displays correctly offline, but the URL is still https://<your local google domain>/_/chrome/newtab.

There is no need to exclude the chrome://newtab URL in your manifest, because chrome:// is not a permitted scheme for content scripts, so neither <all_urls> nor *://*/* grants permission to chrome:// URLs. (Extensions can be allowed to access chrome:// URLs using the chrome://flags/#extensions-on-chrome-urls flag, but it is disabled by default.) You only need to exclude *://*/_/chrome/newtab* (as Haibara Bai has already said in his answer).

Other issues in your code:

  1. You need to include "run_at": "document_start" in your manifest. Content scripts are loaded after loading of the page DOM has finished by default, so users would clearly see that something has loaded before you actually alter the content. See the documentation. Obviously, since you will be running your content script before the DOM has loaded, you can't manipulate the DOM using document.head etc. in your code.

  2. Since you are not using programmatic injection, there is no need to have anything in the "permissions" part of the manifest in this case.

Working example:

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": ["<all_urls>"],
      "exclude_matches": ["*://*/_/chrome/newtab*"],
      "js": ["bup.js"],
      "run_at": "document_start"
    }
]

}

bup.js:

document.write("<body><p>I want to make you think that you have no internet connection.</p></body>");

BTW: Users will obviously still get automatic suggestions when entering text in Chrome address bar, so it should be quite obvious to them that internet connection is in fact working. You might be able to achieve your objective by actually really blocking traffic from Chrome using the chrome.webRequest API.

这篇关于google chrome新标签页的网址是什么,以及如何将其从manifest.json中排除的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆