2012-07-23 62 views

回答

28

TL; DR的网络商店无法通过扩展来照本宣科,而以前允许你这样做(--allow-scripting-galleryhas been removed in Chrome 35的标志。

Chrome扩展程序无法执行内容脚本/插入CSS Chrome网上应用店。这在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商店选项卡中注入一个脚本来查看。例如,开放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)'}); 
}); 
+0

好内容脚本不工作,有没有可能通过后台网页的方法吗? 还是有没有可能的方式来得到这个工作(除了通过命令行参数) – chingo 2012-07-25 14:14:21

+0

这似乎不再工作(在Chrome 31中)。我提交了一个bug - https://code.google.com/p/chromium/issues/detail?id=342090 – kzahel 2014-02-08 01:07:37

+2

@kzahel我刚刚修复了这个错误。你应该可以再次使用'--allow-scripting-gallery'(至少在Canary构建中)。 – 2014-02-10 23:19:12

相关问题