This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
- # announcements (4)
- # aws (3)
- # babashka (5)
- # beginners (16)
- # cider (8)
- # clj-kondo (3)
- # clojars (8)
- # clojure (115)
- # clojure-uk (15)
- # clojurescript (18)
- # data-science (5)
- # datomic (14)
- # fulcro (49)
- # funcool (6)
- # graalvm (3)
- # graphql (4)
- # lumo (17)
- # malli (5)
- # off-topic (15)
- # reitit (18)
- # ring-swagger (8)
- # rum (2)
- # shadow-cljs (35)
- # tools-deps (20)
- # uncomplicate (2)
- # vrac (1)
@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
deps in deps.edn, in shadow-cljs. In
paths var is set to src.
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?
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 https://developer.chrome.com/extensions/contentSecurityPolicy#interactions
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
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: https://github.com/thheller/shadow-cljs/issues/279#issuecomment-392007641
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
Hmm, interesting, so the stuff in the function that I marked with
^:dev/after-load is indeed reloaded, but not in the
So when I do this:
After changing the string in the
(defn ^:dev/after-load reloaded  (println "The content script was reloaded!")) (defn init  (reloaded))
reloadedfunction, the new string is printed in the console of the page. But when I reload the page after that, the old string gets printed.
Looks like the previous version of the content script is loaded on page refresh.
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
you might also try to open devtools and check disabling caching in DevTools Settings (F1)
not sure if this would apply to content scripts as well, probaly not, but worth trying
ok, that is only related to page network requests, not extensions see this: https://bugs.chromium.org/p/chromium/issues/detail?id=112471
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
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
Yes, an example would be great! I struggled the first day or so to set everything up.
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)