Fork me on GitHub

@pri one guess: you are using deps.edn or project.clj but configured said path in shadow-cljs.edn?


The project structure is from a "working example" off a blog. source-path is set to src and deps in deps.edn, in shadow-cljs. In deps.edn the paths var is set to src.

Gleb Posobin22:02:24

I am using shadow-cljs to generate a chrome extension. The content script does not seem to hot reload, while the background script reloads fine on file updates. I.e. init-fn in content script continues to println the same thing after page refresh it did when I loaded the extension in chrome. What could be wrong?

Gleb Posobin22:02:52

But when I unload and then load the extension again in Chrome, the content script behaves differently. So it compiles the changes, but they for some reason are not picked up by the running extension.


I’m not familiar with shadow-cljs support for chrome extensions, but in general hot reloading content script is really tricky, because eval of dynamic code prohibiter or restricted


I don’t remeber the details but I ended up not supporting hot reloading of content scripts in chromex library.


I just briefly glanced over shadow-cljs sources and it looks like @thheller added support for hot-reloading of content script - maybe the feature is just broken for you

Gleb Posobin23:02:44

I thought that the content security policy might be a problem. There is this message by @thheller with an example of a CSP that I thought would fix that, but it did not:


maybe Chrome devs tightened the rules and what worked before no longer works, at least they have been nagging my chrome extension to review requrested permissions and explain them to the review team

Gleb Posobin23:02:56

Hmm, interesting, so the stuff in the function that I marked with ^:dev/after-load is indeed reloaded, but not in the init function.

Gleb Posobin23:02:39

So when I do this:

(defn ^:dev/after-load reloaded []
  (println "The content script was reloaded!"))

(defn init []
After changing the string in the reloaded function, the new string is printed in the console of the page. But when I reload the page after that, the old string gets printed.

Gleb Posobin23:02:27

Looks like the previous version of the content script is loaded on page refresh.


make sure that the genearated source javascript file on disk is actually what you expect, this will rule out shadow-cljs not recompiling the file properly and the problem will be chrome caching the content script file itself somewhere (likely)

Gleb Posobin23:02:52

The file on disk is updated correctly.


not sure how to tell chrome to reload whole content script javascript file


manually you can go to extensions page and reload the extension via UI, I would expect that to load new version of on-disk file

Gleb Posobin23:02:26

Yes, that does reload the file correctly.


you might also try to open devtools and check disabling caching in DevTools Settings (F1)


I mean disabling network caching when DevTools is open


not sure if this would apply to content scripts as well, probaly not, but worth trying

Gleb Posobin23:02:13

That flag doesn't help =/


ok, that is only related to page network requests, not extensions see this:


but since shadow-cljs already knows how to do hot reloading in theory it could add a workaround for this issue, content script init code could contain some test for stale content and request a clean hot-reload for you

Gleb Posobin23:02:51

Adding :module-hash-names true to the shadow-cljs config helped with that.

Gleb Posobin23:02:25

@darwin Thank you for your help!


good to know! maybe open an issue with this workaround so this knowledge does not get lost here on slack btw. I started with shadow-cljs just recently. I want to look into this :chrome-extension target soon, it looks like a hidden gem 🙂 … and maybe create an example shadow-cljs app using chromex


That would be a dream come true!

Gleb Posobin23:02:23

Ah, no, it didn't help facepalm


😞 you need to kick chrome extensions subsystem somehow, to reload the files

Gleb Posobin23:02:56

Yes, an example would be great! I struggled the first day or so to set everything up.


otherwise it will assume they didn’t change


maybe you can do custom hack yourself, simple http get the js file in content script init code and eval it (the same way shadow-cljs evals the code during hot-reload)


it is dirty, but it should work