Search code examples
javascriptgoogle-chromegoogle-chrome-extensionuserscripts

Enable a non-PlayStore UserScript with Chrome 35 and above


Since the version 35 of Google Chrome, the execution of any extension installed outside of the Google's PlayStore is blocked and cannot be enabled from the extensions menu.

The auto-installation of non-store scripts was removed two years ago but downloading the script and performing a drag & drop on the extensions menu still allowed the installation, so it was still possible to create and share scripts for Google's Chrome. But now everything is locked.

  • Is it possible to manually add permissions to your independant scripts ?
  • Is it possible to white-list a personnal website ?
  • Is there any other solution ?

I know that this restriction does not apply for dev and canary release channels but the scripts are purposed to be used by users with enough knowledge to know what they do, without forcing them to change their browser. The native support support is rather interresting on Chrome (even if completly locked now), so a solution without a third party plugin (ie : Tampermonkey) is better.

Thank you


Solution

  • EDIT : I validate this solution because it's what helped me particularly on this problem. A much richer answer is the list of workarounds submited by user2428118. Even if they did not solved my specific problem, they should be considered.

    I finally could find an answer to my question thanks to the link posted by yoz, and the fact is that you can still enable a script unrelated to the PlayStore, without any third party plug-in, but as you'll see : it might be better to use TamperMonkey (even if it might imply little adaptations, it's 200% easier).

    The solution is to import the unpacked user-script in developer mode.

    Step By Step Explanation

    1. Create your user script myscript.user.js as usually

    2. Include it in a directory and create a file named manifest.json. You'll get this structure (can be zipped for distribution) :

      myscript/

      • manifest.json
      • myscript.user.js
    3. The manifest.json is a file required to import your script as a Chrome extension in developer. It describes your user script. Here is the related documentation, but the minimal code for our purpose is :

       {
           "manifest_version":2,
           "version":"1.0",
           "name": "MyScript",
           "content_scripts": [
               {
                   "js": ["myscript.user.js"],
                   "matches": ["http://domain.com/"]
               }
           ]
       }
      
    4. Now that you have your directory with your user script and manifest.json, you can import it as an unpacked extension (a packed one will be disabled after Chrome's restart). To achieve this, simply check the "developer mode" and choose "Load Unpacked Extension...". Navigate to the directory created at step 2 and select it : that's "all".

    Load Unpacked Extension

    Pros

    • Native solution
    • Natural for you if your developing your script on Chrome (obviously this wasn't my case :P)
    • Your script is now treated like a "real" extension.

    Cons

    • Oh, god... I'm missing the one-click install : even if the user only has to achieve the step 4 it's still a pain.
    • Looks less "professional" because the user has to enable the developer mode
    • No longer "cross-browser" distribution since the Google Chrome's script has to be packed in a special way
    • The original directory cannot be (re)moved without breaking the script
    • A warning will be triggered every single time Chrome is opened to ask if you are sure that you want to use developer mode

    Conclusion

    I liked the way user-scripts had native support on Chrome : every third party plugin has some small variations (ie : datas or xhr handling). But the cons are to numerous and to important (especially the two last ones)... Even if enabling a non-PlayStore script is possible in a native way, it became such a pain that I recommend to adapt the script for a plugin such as TamperMonkey. After all, Chrome was an exception since every other browser require a plugin, now these plugins are the only way.

    I still feel a bit disappointed, so if anyone happens to find a better solution (still hoping for some white-lists) I would enjoy to offer some bounty.

    EDIT : Please note that user2428118 provided a list of other interesting workarounds. Even if they did not solved my specifif problem, they should be considered.

    EDIT : manifest fixed