Chrome はウェブストアの URL へのアクセスをブロックしていますか?
+1ボタンの横にいいねボタンを表示する拡張機能を作りたいのですが、https://chrome.google.com/webstore/でコンテンツスクリプトが動作していないようです*
本当?
Chrome はウェブストアの URL へのアクセスをブロックしていますか?
+1ボタンの横にいいねボタンを表示する拡張機能を作りたいのですが、https://chrome.google.com/webstore/でコンテンツスクリプトが動作していないようです*
本当?
TL;DR ウェブストアは拡張機能でスクリプト化できません。以前はそれを許可していたフラグ ( --allow-scripting-gallery
)が Chrome 35 で削除されました。
Chrome 拡張機能は、コンテンツ スクリプトを実行したり、Chrome Web ストアに CSS を挿入したりできません。これは、ソース コードの関数で明示的に定義されています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
ここで定義されています:
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)'});
});