答案 0 :(得分:29)
TL; DR无法通过扩展程序编写Webstore脚本,以及之前允许您执行此操作的标记(--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
在Web Store选项卡中注入脚本时,可以在后台页面的控制台中查看错误。例如,打开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)'});
});