26

Is Chrome blocking access to the webstore url?

I would like to make an extension that displays a like button beside the +1 button, but it looks like that content scripts are not working on https://chrome.google.com/webstore/*

Is that true?

chingo
  • 281
  • 1
  • 3
  • 4

1 Answers1

35

TL;DR The webstore cannot be scripted by extensions, and the flag that previously allowed you to do that (--allow-scripting-gallery) has been removed in Chrome 35.

Chrome extensions cannot execute Content scripts / insert CSS the Chrome Web Store. This is explicitly defined in the source code, at function IsScriptableURL (click on the previous link to see the full logic).

  // 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 is defined here:

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

The error can be viewed in the background page's console when you use chrome.tabs.executeScript to inject a script in a Web Store tab. For instance, open https://chrome.google.com/webstore/, then execute the following script in the background page of an extension (via the console, for live debugging):

chrome.tabs.query({url:'https://chrome.google.com/webstore/*'}, function(result) {
    if (result.length) chrome.tabs.executeScript(result[0].id, {code:'alert(0)'});
});
Rob W
  • 341,306
  • 83
  • 791
  • 678
  • Ok Content Scripts not working, is there maybe a way via Background Pages? Or is there no possible way to get this working (except via command line parameter) – chingo Jul 25 '12 at 14:14
  • This doesn't seem to be working any more (in Chrome 31). I submitted a bug - https://code.google.com/p/chromium/issues/detail?id=342090 – kzahel Feb 08 '14 at 01:07
  • 2
    @kzahel I have just fixed that bug. You should be able to use the `--allow-scripting-gallery` again (at least with Canary builds). – Rob W Feb 10 '14 at 23:19
  • FYI CSS can not be inserted via the insertCSS function, however any CSS you have declared in your manifest will load - while your content_script does not. Booooo on Google – sboy031 Mar 26 '14 at 06:37
  • @sboy031 FYI, what you described was [a bug](https://code.google.com/p/chromium/issues/detail?id=356652), and it has already been fixed since Chrome 36. – Rob W Aug 07 '14 at 13:41
  • This needs to be updated; the code path to allow this through a switch was removed – Xan Apr 05 '15 at 22:58
  • @Xan Updated. Thanks for the heads-up – Rob W Apr 06 '15 at 09:07