内容脚本是否可以访问newtab页面

内容脚本是否可以访问newtab页面

本文介绍了内容脚本是否可以访问newtab页面?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

更新



感谢@kofifus的信息,Chrome自61开始


所以它看起来很奇怪,因为它在不同设备(或设置?)上的行为不同。是否有关于内容脚本是否可以在 chrome:// newtab 页面中运行的官方声明?或者是否有一个设置可以改变这种行为?

.chromium.org / 2978953002 /rel =nofollow noreferrer>在其默认新标签页上明确禁止内容脚本


Updated

Thanks @kofifus for the info, Chrome as of 61 explicitly forbids content scripts on its default new tab page

Previous

Say I have the following sample extension, it will output test in console.

manifest.json

{
  "name": "Test",
  "version": "1.0",
  "manifest_version": 2,
  "content_scripts": [
    {
      "matches": [
        "<all_urls>"
      ],
      "js": [
        "content.js"
      ]
    }
  ]
}

content.js

console.log('test');

Will above extension work well in chrome://newtab page?

Some helpful info:

  1. I know by default chrome extension can't access to chrome:// pages, and we could change this behavior through chrome://flags/#extensions-on-chrome-urls

  2. chrome://newtab in fact is a url like https://www.google.co.jp/_/chrome/newtab?espv=2&ie=UTF-8, so it shouldn't be blocked by above restriction.

  3. There are many mouse gestures extension available, like crxMouse, they work well on chrome://newtab page

  4. There are also some voices saying it's not allowed to inject content scripts in chrome://newtab, for example, @Xan's comments below this answerand this author's case

So it looks weird as its different behavior across different devices( or settings?). Is there any official statements about whether content scripts can run in chrome://newtab pages? Or is there a setting we could change this behavior?

解决方案

Chrome as of 61 explicitly forbids content scripts on its default new tab page

这篇关于内容脚本是否可以访问newtab页面?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-21 01:23