【发布时间】:2012-07-21 17:43:20
【问题描述】:
Chrome 是否阻止访问网络商店网址?
我想制作一个在 +1 按钮旁边显示点赞按钮的扩展程序,但内容脚本似乎不适用于 https://chrome.google.com/webstore/*
这是真的吗?
【问题讨论】:
标签: google-chrome google-chrome-extension
Chrome 是否阻止访问网络商店网址?
我想制作一个在 +1 按钮旁边显示点赞按钮的扩展程序,但内容脚本似乎不适用于 https://chrome.google.com/webstore/*
这是真的吗?
【问题讨论】:
标签: google-chrome google-chrome-extension
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)'});
});
【讨论】:
--allow-scripting-gallery(至少在 Canary 版本中)。