davestewart
Explore posts from serversPD🧩 Plasmo Developers
•Created by davestewart on 5/27/2023 in #👟framework
How does the service worker hot reload mechanism work?
Interesting!
42 replies
PD🧩 Plasmo Developers
•Created by davestewart on 5/27/2023 in #👟framework
How does the service worker hot reload mechanism work?
Look around here maybe?
https://github.com/vitejs/vite-plugin-vue
42 replies
PD🧩 Plasmo Developers
•Created by davestewart on 5/27/2023 in #👟framework
How does the service worker hot reload mechanism work?
Vue 3 HMR is basically Vite HMR AFAIK.
But I suspect you're asking in terms of how to target content injected into the shadow DOM?
42 replies
PD🧩 Plasmo Developers
•Created by davestewart on 5/27/2023 in #👟framework
How does the service worker hot reload mechanism work?
Whether it's HMR or just reloading the tab, it should still result in new compiled code being loaded in and running, which is what you need in development.
Regards the sandbox, actually I don't know if this would be strictly necessary, but thanks for the tip! I'l read up more about that.
This actually gives me hope that I'll be able to build a DX friendly workflow in MV3!
42 replies
PD🧩 Plasmo Developers
•Created by davestewart on 5/27/2023 in #👟framework
How does the service worker hot reload mechanism work?
Ah, sorry - my fault for being ambiguous.
Content tab vs content script:
This tab will have all (most of?) the functionality of background, plus a
tab.id
.
Thus, should be able to complete the proxying as I mentioned before, calling any of the permitted chrome.*
APIs that you would normally expect to use background
for, via messaging.42 replies
PD🧩 Plasmo Developers
•Created by davestewart on 5/27/2023 in #👟framework
How does the service worker hot reload mechanism work?
OK, have been researching this a bit more, and it seems that it is going to be impossible to get some kind of reload working in a service worker. I was hoping that eval might be a possibility, but I can't get unsafe-eval to be accepted in the CSP.
So here's my next idea; thought I would just sanity check it...
Rather than putting all the logic in the background process, an extension in development would open a physical browser tab which did contain the logic, and the existing background service would proxy commands to that tab:
This tab could then hook into HMR or the same setup as I described before, and reload itself when the source files changed:
Granted, it seems like a lot of work, but it would allow content scripts to remain loaded when the "background" logic updated.
Another option (in my case) would be in development, to load the background logic directly in the content scripts as some kind of service, and redirect calls to the background to the local service, directly in the script. This would mean HMR would "just work" and the background service worker could effectively be ignored.
Again, I haven't thought properly about extension architecture for around 18 months, so I might be way off.
Thoughts @louis
42 replies
PD🧩 Plasmo Developers
•Created by davestewart on 5/27/2023 in #👟framework
How does the service worker hot reload mechanism work?
Ah, can't see that
42 replies
PD🧩 Plasmo Developers
•Created by davestewart on 5/27/2023 in #👟framework
How does the service worker hot reload mechanism work?
kk
42 replies
PD🧩 Plasmo Developers
•Created by davestewart on 5/27/2023 in #👟framework
How does the service worker hot reload mechanism work?
Yeah, why not! Appreciated. I can do any time at all 🙂
42 replies
PD🧩 Plasmo Developers
•Created by davestewart on 5/27/2023 in #👟framework
How does the service worker hot reload mechanism work?
Ah, you misunderstand me! I meant only the background is reloaded; so any content scripts hosts or other extension windows do not need to be reloaded.
chrome.runtime.reload()
is a bit of a sledgehammer to crack a nut42 replies
PD🧩 Plasmo Developers
•Created by davestewart on 5/27/2023 in #👟framework
How does the service worker hot reload mechanism work?
Ah, that makes sense now why the context invalidated error keeps popping up.
I'm doing it differently. I set up a webpack plugin which triggers only the background script to reload using
location.reload()
when background.js
is rewritten by the build. This means any content processes don't get reloaded if you only need to modify the background script, and can just continue passing messages without losing state.
I was hoping that there would be a way to either reload the background service worker (I see there is an update()
method on registered workers) or somehow have the files it references update, but I don't have any experience with workers or how manifest v3 references workers, so I'm starting from scratch in my investigations.
Also, yes, happy to exchange notes!42 replies