You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Hi!
I'm using tauri v2 together with Nuxt and Typescript and I'm struggling to register a service worker in production builds with tauri build. The only way I can use a service worker is with tauri dev in combination with @vite-pwa/nuxt ... but I need a production build :)
The service worker that shall be loaded is successfully placed in .tauri-build/dist/sw.js. The devTools only show the error An unknown error occurred when fetching the script.
The devTools network tab also shows that the request is made to http://tauri.localhost/sw.js but never answered.
I don't think this is an issue with my service worker because when I omit tauri and just serve the app with nuxt the service worker also registers properly in MS Edge.
In dev mode when trying a manual installation it also fails with unsupported MIME type indicating that Nuxt just responded with a 404 error page.
It seems to me like this sw.js file is excluded from the bundle. If someone could point me to the tauri source code file where such filtering happens I'm happy to take a deeper look. I just never programmed in Rust and in the tauri source and I don't see the forest for the trees.
then pnpm tauri dev works with @vite-pwa/nuxt - the service worker is installed. However, manual registration still fails.
with pnpm tauri build the service worker can't get installed at all.
I also tried to do a hack by importing the sw.js in the App.vue and added such a guard inside the sw.js file:
if (!document) {
self.addEventListener("install", function (e) {
console.log("service worker installation");
});
} else {
navigator.serviceWorker.register("/test.js");
}
But still: Failed to register a ServiceWorker for scope ('http://tauri.localhost/') with script ('http://tauri.localhost/test.js'): An unknown error occurred when fetching the script.
However as fetch('/sw.js') succeeds I don't understand this dark magic :)
Describe the bug
Hi!
I'm using tauri v2 together with Nuxt and Typescript and I'm struggling to register a service worker in production builds with
tauri build
. The only way I can use a service worker is withtauri dev
in combination with@vite-pwa/nuxt
... but I need a production build :)The service worker that shall be loaded is successfully placed in
.tauri-build/dist/sw.js
. The devTools only show the errorAn unknown error occurred when fetching the script.
The devTools network tab also shows that the request is made to
http://tauri.localhost/sw.js
but never answered.I don't think this is an issue with my service worker because when I omit tauri and just serve the app with nuxt the service worker also registers properly in MS Edge.
In dev mode when trying a manual installation it also fails with
unsupported MIME type
indicating that Nuxt just responded with a 404 error page.It seems to me like this
sw.js
file is excluded from the bundle. If someone could point me to the tauri source code file where such filtering happens I'm happy to take a deeper look. I just never programmed in Rust and in the tauri source and I don't see the forest for the trees.I appreciate any hint! :)
Thank you!
Martin
Reproduction
https://github.com/Martin-Schlodinski/tauri-sw
pnpm install
then
pnpm tauri dev
works with@vite-pwa/nuxt
- the service worker is installed. However, manual registration still fails.with
pnpm tauri build
the service worker can't get installed at all.Expected behavior
Service workers can be loaded.
Full
tauri info
outputStack trace
No response
Additional context
No response
The text was updated successfully, but these errors were encountered: