https://chrome.google.com/webstore/上的 Chrome 扩展内容脚本 [英] Chrome Extension Content Script on https://chrome.google.com/webstore/

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

问题描述

Chrome 是否阻止访问网店网址?

Is Chrome blocking access to the webstore url?

我想制作一个在 +1 按钮旁边显示一个赞按钮的扩展程序,但看起来内容脚本在 https://chrome.google.com/webstore/*

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/*

这是真的吗?

推荐答案

TL;DR Webstore 不能由扩展编写脚本,并且以前允许您这样做的标志 (--allow-scripting-gallery) 已在 Chrome 35 中删除.

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 扩展程序无法在 Chrome 网上应用店中执行内容脚本/插入 CSS.这在源代码中明确定义/a>,在函数 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 选项卡中注入脚本时,可以在后台页面的控制台中查看错误.例如,打开https://chrome.google.com/webstore/,然后执行以下脚本在扩展的后台页面中(通过控制台,用于实时调试):

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)'});
});

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

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