【问题标题】:Chrome Extension Content Script on https://chrome.google.com/webstore/https://chrome.google.com/webstore/ 上的 Chrome 扩展内容脚本
【发布时间】:2012-07-21 17:43:20
【问题描述】:

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

我想制作一个在 +1 按钮旁边显示点赞按钮的扩展程序,但内容脚本似乎不适用于 https://chrome.google.com/webstore/*

这是真的吗?

【问题讨论】:

    标签: google-chrome google-chrome-extension


    【解决方案1】:

    TL;DR 网络商店不能由扩展编写脚本,并且以前允许您这样做的标志 (--allow-scripting-gallery) has been removed in Chrome 35

    Chrome 扩展程序无法执行内容脚本/在 Chrome 网上应用店中插入 CSS。这在the source code 函数IsScriptableURL 中明确定义(单击上一个链接查看完整逻辑)。

      // 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 定义为here

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

    当您使用chrome.tabs.executeScript 在网上应用店选项卡中注入脚本时,可以在后台页面的控制台中查看该错误。例如,打开https://chrome.google.com/webstore/,然后在扩展的后台页面中执行以下脚本(通过控制台,用于实时调试):

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

    【讨论】:

    • 好的 内容脚本不起作用,是否有办法通过后台页面?或者有没有办法让这个工作(除了通过命令行参数)
    • 这似乎不再起作用(在 Chrome 31 中)。我提交了一个错误 - code.google.com/p/chromium/issues/detail?id=342090
    • @kzahel 我刚刚修复了这个错误。您应该可以再次使用--allow-scripting-gallery(至少在 Canary 版本中)。
    • 仅供参考,CSS 不能通过 insertCSS 函数插入,但是您在清单中声明的​​任何 CSS 都会加载 - 而您的 content_script 则不会。 Google 上的嘘声
    • @sboy031 仅供参考,您所描述的是a bug,自 Chrome 36 起已修复。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-09-28
    • 2021-06-15
    • 2013-06-11
    • 1970-01-01
    • 2019-11-05
    相关资源
    最近更新 更多