Saturday 16 June 2018

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


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+?



Answer



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.


No comments:

Post a Comment

Where does Skype save my contact's avatars in Linux?

I'm using Skype on Linux. Where can I find images cached by skype of my contact's avatars? Answer I wanted to get those Skype avat...