Assuming you have the shadow-cljs npm package installed:
- From the
shadow/
directory, runshadow-cljs release extension
and wait for the build to complete. - Go to
"chrome://extensions"
. - Toggle on 'Developer mode' in the top right of the page.
- Click the 'Load unpacked' button and find
~/[...]/hacky-chromex-shadow-manifest-v2-to-v3-migration/shadow/resources/unpacked
.
- Versions in
deps.edn
bumped to latest, andbinaryage/chromex
made a non-local dependency. (commit) :manifest-version
inshadow/resources/unpacked/manifest.edn
bumped from2
to3
. (commit)- Introduced a shadow-cljs build hook, to run at the very end of the build. This is responsible for all of the hacky patching required to get this thing working. (commit)
- Patched
"background"
key in manifest. (commit)- Under Manifest V3, the
"background"
key can only take a single"service_worker"
where before it took an array of"scripts"
. - This is why we ignore all
"scripts"
but"out/background.js"
, here.
- Under Manifest V3, the
- Prepended copy of
out/shared.js
toout/background.js
. (commit)- Even developing against release builds, shadow generates multiple
"background"
scripts:out/background.js
,out/bg-shared.js
, andout/shared.js
. So whilst it's possible under Manifest V3 to declare the background"service_worker"
an ES Module and statically import such additional code intoout/background.js
,out/shared.js
currently doesn't export stuff in the necessary way.
- Even developing against release builds, shadow generates multiple
- Patched
"content_security_policy"
key in manifest. (commit) - Removed
'unsafe-eval'
from Content Security Policy. (commit)- Again, Manifest V3 doesn't allow it.
- Patched
"actions"
. (commit) - Fixed permissions. (commit)
- Patched
- Regarding (3)(ii) above, perhaps hot reloading of code during development could be recovered if there were a way to deal with the many background-relevant scripts that
shadow-cljs watch extension
generates in addition toout/background.js
— as opposed to justout/shared.js
forshadow-cljs release extension
. So... aside from prepending every single one toout/background.js
, what options are there?- They could potentially be statically imported if shadow threw a few exports in during building, right?
- Something else?
- With
'unsafe-eval
gone in Manifest V3, even during dev, it's unclear how to get a REPL hooked up to the various runtimes comprising a running extension. (Related shadow-cljs issue/comment: thheller/shadow-cljs#902 (comment).) And even if it were possible, the short-lived nature of background service workers (replacing Manifest V2's background pages) would make REPL-driven dev against background-relatedcljs
files annoying... probably. Are there any good solutions here, aside from maybe:- Developing against Manifest V2 in a V3-compatible way, then building the extension as V3?
- Developing against a modified Chromium, enabling unsafe-eval?
- It seems so far that all the required changes are shadow-related, because they're related to how the extension is built/packaged — in particular, by this namespace here. Is this right? And if so, should a patch be submitted?