Chrome扩展程序内容脚本

Chrome扩展程序内容脚本

本文介绍了Chrome扩展程序内容脚本,位于https://chrome.google.com/webstore/上的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Chrome是否阻止访问webstore url?

Is Chrome blocking access to the webstore url?

我想要在+1按钮旁边添加一个类似按钮的扩展程序,但看起来像内容脚本在 *上无效

I would like to make an extension that displays a like button beside the +1 button, but it looks like that content scripts are not working on https://chrome.google.com/webstore/*

这是真的吗?

Is that true?

推荐答案

TL ; DR webstore不能被扩展脚本所使用,并且以前允许你这样做的标志( - allow-scripting-gallery )。

TL;DR The webstore cannot be scripted by extensions, and the flag that previously allowed you to do that (--allow-scripting-gallery) has been removed in Chrome 35.

Chrome扩展程序无法执行内容脚本/插入CSS Chrome网上应用店。这在,在函数 IsScriptableURL (点击上一个链接查看完整逻辑)。

Chrome extensions cannot execute Content scripts / insert CSS the Chrome Web Store. This is explicitly defined in the source code, at function IsScriptableURL (click on the previous link to see the full logic).

  // The gallery is special-cased as a restricted URL for scripting to prevent
  // access to special JS bindings we expose to the gallery (and avoid things
  // like extensions removing the "report abuse" link).
  // TODO(erikkay): This seems like the wrong test.  Shouldn't we we testing
  // against the store app extent?
  GURL store_url(extension_urls::GetWebstoreLaunchURL());
  if (url.host() == store_url.host()) {
    if (error)
      *error = manifest_errors::kCannotScriptGallery;
    return false;
  }

manifest_errors :: kCannotScriptGallery 的定义:

const char kCannotScriptGallery[] =
    "The extensions gallery cannot be scripted.";

使用 chrome时,可以在后台页面的控制台中查看错误。 tabs.executeScript 在Web Store选项卡中注入脚本。例如,打开,然后执行以下脚本在扩展的后台页面(通过控制台进行实时调试):

The error can be viewed in the background page's console when you use chrome.tabs.executeScript to inject a script in a Web Store tab. For instance, open https://chrome.google.com/webstore/, then execute the following script in the background page of an extension (via the console, for live debugging):

chrome.tabs.query({url:'https://chrome.google.com/webstore/*'}, function(result) {
    if (result.length) chrome.tabs.executeScript(result[0].id, {code:'alert(0)'});
});

这篇关于Chrome扩展程序内容脚本,位于https://chrome.google.com/webstore/上的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-14 03:26