Reloading your Chrome extensions on-save in Visual Studio Code!

1 minute read

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 save me from a (now fixed) extension loading bug (in addition to the general inconvenience of reloading unpacked extensions).

But it can get even more convenient for us aspiring extension developers. (kudos to @kinghat on DEV 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"
            }
        ]
    }

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

    "emeraldwalk.runonsave": {
        "commands": [
            {
                "match": "/extension-project-folder/.*",
                "cmd": "open -a 'Google Chrome' http://reload.extensions"
            }
        ]
    }

GNU/Linux

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

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"

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 by commenting on this article on dev.to.


Thanks for reading!

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