Reloading your Chrome extensions on-save in VS Code!

solomon

Solomon

Posted on February 24, 2019

Reloading your Chrome extensions on-save in VS Code!

Update: there's a better way to do this

There's a really cool Chrome extension I commented on DEV about called "Reload Extensions", and it's saved me from an extension loading bug (in addition to the general inconvenience of reloading unpacked extensions):

Yep! Especially when the extension icons don't update after I enable/load an extension (which I think is unintended behavior), I just go to reload.extensions and everything works as intended!

But it can get even more convenient for us aspiring extension developers.

are you using the extensions reloader url to automate the reloading?

(kudos to @kinghat for inspiring this post!)

Configuration

Prerequisites

You need to have the following software installed:

  • Visual Studio Code
  • Extensions Reloader
  • Google Chrome, Brave, Vivaldi, or any browser that supports the installation of Chrome extensions. The example command configurations are for Chrome, but start http://reload.extensions (Windows), open http://reload.extensions (Mac), and xdg-open http://reload.extensions (GNU/Linux) can work with any of the aforementioned browsers, assuming they are your computer's default.

You can get this Visual Studio Code extension called RunOnSave, which lets you add this to your settings.json:

Windows



    "emeraldwalk.runonsave": {
        "commands": [
            {
                "match": "\\\\extension-project-folder\\\\.*",
                "cmd": "start chrome http://reload.extensions"
            }
        ]
    }


Enter fullscreen mode Exit fullscreen mode

Just make sure to replace "extension-project-folder" with the name of your project's folder.

The double escaping of the backslashes isn't required on Unix-like operating systems like Mac and GNU/Linux.

macOS


</span><span class="nl">"emeraldwalk.runonsave"</span><span class="p">:</span><span class="w"> </span><span class="p">{</span><span class="w">
    </span><span class="nl">"commands"</span><span class="p">:</span><span class="w"> </span><span class="p">[</span><span class="w">
        </span><span class="p">{</span><span class="w">
            </span><span class="nl">"match"</span><span class="p">:</span><span class="w"> </span><span class="s2">"/extension-project-folder/.*"</span><span class="p">,</span><span class="w">
            </span><span class="nl">"cmd"</span><span class="p">:</span><span class="w"> </span><span class="s2">"open -a 'Google Chrome' http://reload.extensions"</span><span class="w">
        </span><span class="p">}</span><span class="w">
    </span><span class="p">]</span><span class="w">
</span><span class="p">}</span><span class="w">
Enter fullscreen mode Exit fullscreen mode
Enter fullscreen mode Exit fullscreen mode




GNU/Linux



</span><span class="nl">"emeraldwalk.runonsave"</span><span class="p">:</span><span class="w"> </span><span class="p">{</span><span class="w">
    </span><span class="nl">"commands"</span><span class="p">:</span><span class="w"> </span><span class="p">[</span><span class="w">
        </span><span class="p">{</span><span class="w">
            </span><span class="nl">"match"</span><span class="p">:</span><span class="w"> </span><span class="s2">"/extension-project-folder/.*"</span><span class="p">,</span><span class="w">
            </span><span class="nl">"cmd"</span><span class="p">:</span><span class="w"> </span><span class="s2">"google-chrome http://reload.extensions"</span><span class="w">
        </span><span class="p">}</span><span class="w">
    </span><span class="p">]</span><span class="w">
</span><span class="p">}</span><span class="w">
Enter fullscreen mode Exit fullscreen mode
Enter fullscreen mode Exit fullscreen mode




Autosave configuration

(this step is optional but recommended)

For minimal interruptions, I recommend setting the save mode to auto save when the VS Code window loses focus in settings.json:



"files.autoSave": "onWindowChange"

Enter fullscreen mode Exit fullscreen mode




That's it!

It's kind of annoying (because it focuses your browser every time you switch away from VS Code) unless you're only switching between Code and Chrome, in which case it works really well!

I haven't tested this on every OS and browser, so let me know if this functions for you in the comments below.


Thanks for reading!

If you gained some knowledge from this post, please smash that ❤️ button an odd number of times.

Sources

https://stackoverflow.com/a/32775952
https://stackoverflow.com/a/23039509
https://superuser.com/a/790678
https://askubuntu.com/a/19920
https://github.com/emeraldwalk/vscode-runonsave/blob/master/README.md

💖 💪 🙅 🚩
solomon
Solomon

Posted on February 24, 2019

Join Our Newsletter. No Spam, Only the good stuff.

Sign up to receive the latest update from our blog.

Related