Extreload: A command line program to reload extensions

447 views
Skip to first unread message

Teddy

unread,
Mar 4, 2021, 9:45:24 AM3/4/21
to Chromium Extensions
Hello all,

I'd like to share a program I just finished to reload Chrome extensions
from the command line:

https://github.com/teddywing/extreload

There are existing tools that facilitate reloading extensions, but these
often require modifying your extension codebase, and aren't as
interoperable as a command line program.

Extreload is completely external, with no code modifications necessary
or Webpack plugins to include. Currently, it only works for Manifest V2
extensions. It's helped me immensely to speed up my development feedback
loop.

For example, this call will reload the
`kldfpiebhefepgbjknnlgpeichadmdib` extension in all open profiles, then
reload the current tab:

$ extreload \
--socket-url ws://127.0.0.1:55755/devtools/browser/208ae571-d691-4c98-ad41-3a15d507b656
\
--reload-current-tab \
kldfpiebhefepgbjknnlgpeichadmdib

The DevTools Protocol socket URL can be retrieved automatically by
wrapping the command in a script:

#!/bin/sh
socket_url=$(head -n 300 path/to/chrome_debug.log |
fgrep 'DevTools listening on ws://' |
sed 's,DevTools listening on ws://,ws://,')
extreload --socket-url "$socket_url" --reload-current-tab "$@"

We can do things like reload an extension when JS files are saved:

$ find . -name '*.js' -not -path './node_modules/*' |
entr -s 'extreload ...'

Or run the reload program when a keyboard shortcut is pressed:
https://github.com/teddywing/dothammerspoon/blob/487ff34d75b034814a9b8bdd352e2ede38395c25/ufo.lua#L57-L62

I hope you find it useful.


-Teddy

--










*"This email and any files transmitted with it are confidential
and intended solely for the use of the individual or entity to whom they
are addressed. If you have received this email in error please notify the
sender immediately"*

Teddy

unread,
Mar 4, 2021, 1:07:39 PM3/4/21
to Alexei Miagkov, Chromium Extensions
On Mar 4, 2021, at 12:16 PM -0500, Alexei Miagkov <amia...@gmail.com>
wrote:
>Have you seen web-ext, "a command line tool to help build, run, and test
>WebExtensions"?
>
>This will launch your extension in a fresh Chrome instance with automatic code
>reloading:
>
>$ web-ext run --target chromium -s /path/to/extension/src/

I was superficially aware of web-ext, but didn't realise that it has
automatic reloading, cool.

The disadvantage, though, is that it opens a new Chrome instance rather
than allowing you to work in an existing one (or multiple profiles).

Also, when I tried the `chrome.management.setEnabled()` strategy that
web-ext uses to reload
(https://github.com/mozilla/web-ext/blob/528f8a0594e16171936503d61fe972487b93a9b7/src/extension-runners/chromium.js#L324-L332),
my extension would just deactivate and reactivate rather than reload
fully. I opted to use `chrome.runtime.reload()` instead.

Alex

unread,
Mar 4, 2021, 1:21:51 PM3/4/21
to Chromium Extensions, Teddy, Chromium Extensions
A new browser instance is generally desirable for testing purposes, but if you can specify a profile directory if you want with --chromium-profile. See the full suite of options here: https://extensionworkshop.com/documentation/develop/web-ext-command-reference/

Teddy

unread,
Mar 4, 2021, 2:42:05 PM3/4/21
to Alex, Chromium Extensions
On Mar 4, 2021, at 10:21 AM -0800, Alex <amia...@gmail.com> wrote:
>A new browser instance is generally desirable for testing purposes,

Interesting, what kinds of benefits does working in a new browser
instance provide?

>but if you can specify a profile directory if you want with
>--chromium-profile. See the full suite of options here:
>https://extensionworkshop.com/documentation/develop/web-ext-command-reference/

Nice, thanks for the tip.
Reply all
Reply to author
Forward
0 new messages