How to install a private user script in Chrome 21+?

60

28

In Chrome 20 and older versions, you could simply open any .user.js file in Chrome and it would prompt you to install the user script.

However, in Chrome 21 and up, it downloads the file instead, and displays a warning at the top saying “Extensions, apps, and user scripts can only be added from the Chrome Web Store”.

Screenshot

The “Learn More” link points to http://support.google.com/chrome_webstore/bin/answer.py?hl=en&answer=2664769, but that page doesn’t say anything about user scripts, only about extensions in .crx format, apps, and themes.

This part sounded interesting:

Enterprise Administrators: You can specify URLs that are allowed to install extensions, apps, and themes directly through the ExtensionInstallSources policy.

So, I ran the following commands, then restarted Chrome and Chrome Canary:

defaults write com.google.Chrome ExtensionInstallSources -array "https://gist.github.com/*"
defaults write com.google.Chrome.canary ExtensionInstallSources -array "https://gist.github.com/*"

Sadly, these settings only seem to affect extensions, apps, and themes (as it says in the text), not user scripts. (I’ve filed a bug asking to make this setting affect user scripts as well.)

Any ideas on how to install a private user script (that I don’t want to add to the Chrome Web Store) in Chrome 21+?

Mathias Bynens

Posted 2012-07-19T11:36:28.807

Reputation: 2 171

Have you tried enabling developer mode in Settings -> Extensions? Not sure if its gonna work but you can give it a try. – Rhyuk – 2012-07-19T12:04:01.970

@Rhyuk Thanks for the suggestion. I had developer mode enabled, though — doesn’t seem to make a difference. – Mathias Bynens – 2012-07-19T12:05:17.817

1How do I install a userscript? – Sathyajith Bhat – 2012-07-19T13:00:36.500

Answers

37

The problem was that gist.github.com’s raw URLs redirect to a different domain. So, we have to use these commands instead:

# Allow installing user scripts via GitHub or Userscripts.org
defaults write com.google.Chrome ExtensionInstallSources -array "https://*.github.com/*" "http://userscripts.org/*"
defaults write com.google.Chrome.canary ExtensionInstallSources -array "https://*.github.com/*" "http://userscripts.org/*"

This works!


Anyway, this seems to be a workaround (thanks to Paul Horn for the hint):

  1. Download the user script.
  2. Open chrome://chrome/extensions/.
  3. Drag and drop the user script file on the page you opened in step 2.

Mathias Bynens

Posted 2012-07-19T11:36:28.807

Reputation: 2 171

This seems better than having to edit the command used to open Chromium. Thanks! – btleffler – 2012-09-03T21:39:17.623

@btleffler Except that you'll have to jump through that hoop every time, rather than making the change once. – Eugene Beresovsky – 2012-09-24T23:48:35.707

NB. When drag and dropping, you need to drop the file exactly onto the message. Anywhere else on the page won't work. – Colonel Panic – 2012-10-26T10:53:29.733

is the drag and drop way of adding extensions still working? It does not seem like that on Chrome 24 on OSX. – Viktor – 2013-02-20T20:31:14.620

It bears mentioning that github allows the hosting of user-generated content on <username>.github.com (via "Github Pages" - http://pages.github.com).

Just a heads up for anyone for whom this would be a security concern.

– mh. – 2013-03-16T13:27:38.003

Where do you enter the commands? – Sam – 2013-04-10T01:14:15.803

@Sam In your terminal. – Mathias Bynens – 2013-04-10T09:37:05.123

Drag&Drop opens the script in chrome, it doesn't install anything. Is there a normal way to install script? – Danubian Sailor – 2013-07-18T20:03:47.917

@ŁukaszLech You need to drag it to chrome://chrome/extensions/, not just to the Chrome window. – Mathias Bynens – 2013-07-23T05:08:15.933

36

Start Chrome with the --enable-easy-off-store-extension-install switch.

To use a command line switch (from Chromium.org):

On Windows:

  • Right click on your "Chrome" icon.
  • Choose properties
  • At the end of your target line, place these parameters: --enable-easy-off-store-extension-install
  • It should look like: chrome.exe --enable-easy-off-store-extension-install

On OS X:

  • /Applications/Chromium.app/Contents/MacOS/Chromium --enable-easy-off-store-extension-install

  • For Google Chrome you'll need to escape spaces like so: /Applications/Google\ Chrome.app/Contents/MacOS/Google\ Chrome --enable-easy-off-store-extension-install

On Linux:

  • chromium-browser --enable-easy-off-store-extension-install

Jacob Groß

Posted 2012-07-19T11:36:28.807

Reputation: 361

I have a problem on windows http://dl2.joxi.net/drive/0005/3037/338909/141218/3935c61eb8.jpg

– gstackoverflow – 2014-12-18T12:12:36.130

1Pretty sure this stopped working sometime after August, 2014. Doesn't seem to work now at all. – Brock Adams – 2016-11-28T05:33:22.587

1You have to quit chrome completely, not just open a new window from the icon. (this is rubbish of Google btw) – Jonathan. – 2012-08-16T20:32:01.683

1Yep, this is encroaching on "evil" territory IMO. – We Are All Monica – 2012-11-26T03:33:45.247

This worked... :) The answer of @MathiasBynens didn't work on MacOS/Chrome25 – Lipis – 2012-12-19T01:18:18.523

10

Well, this took a couple hours of my life to figure out. I guess Google engineers think that we only deserve to install untrusted extensions if we can figure out how to do tricks and jump through their hoops.

The instructions in Mathias's answer look to be spot-on for Mac OS X, but I use Linux. Here's what I did on Linux to enable easier (pre-Chrome-21-style) install of all third-party extensions, apps, and user scripts from any website:

  1. Create the policies directory (if it doesn't already exist):

    sudo mkdir -p /etc/opt/chrome/policies/recommended/
    
  2. Create the policy file:

    cd /etc/opt/chrome/policies/recommended/
    
    sudo tee easy_install_extensions.json <<EOF
    {
        "ExtensionInstallSources": ["<all_urls>"]
    }
    EOF
    
  3. Restart Chrome. Completely exit the program via menu -> Exit; don't just close your current window.


Sources:

Notes:

  • <all_urls> (used above) is a special pattern according to the URL match docs. Good to know about.
  • According to the Linux policy docs, the directories /etc/opt/chrome/policies/{managed,recommended}/ contain JSON policy files. If entries conflict, managed overrides recommended.

We Are All Monica

Posted 2012-07-19T11:36:28.807

Reputation: 303

2I didn’t know about <all_urls> — very useful. Thanks! – Mathias Bynens – 2012-11-26T06:59:11.540

Confirmed to work in Fedora 18. Awesome post, extremely helpful! – ehime – 2013-02-21T20:13:05.360

Awesome! Drag and drop didn't work before, and now it works! – billyswong – 2013-05-29T03:47:14.897