Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

$pwa is always false #70

Open
danieldanielecki opened this issue Sep 27, 2023 · 4 comments
Open

$pwa is always false #70

danieldanielecki opened this issue Sep 27, 2023 · 4 comments

Comments

@danieldanielecki
Copy link

I followed https://vite-pwa-org.netlify.app/frameworks/nuxt.html along with issues in the repo, created assets using https://vite-pwa-org.netlify.app/assets-generator/ and read https://vite-pwa-org.netlify.app/guide/pwa-minimal-requirements.html. Also, check the example at https://vite-pwa-org.netlify.app/examples/nuxt.html -> https://github.com/vite-pwa/nuxt/tree/main/playground.

In my view-source:http://localhost:3000/ I can't see <link rel="manifest" href="/manifest.webmanifest"> or any other file related to PWA, such as favicon.

Additionally, I've deployed the app to https://ibstructure.com and the PWA works, but the $pwa is still false. It's really confusing when trying to validate during development (esp. on localhost with bad documentation/localhost-PWA problems) whether the app is PWA working.

Screenshot 2023-09-27 at 08 56 15
@danieldanielecki
Copy link
Author

Most of my PWA-related changes/fixes/debugging were in: Doyban/Doyban-Website@6c13721 whereas the entire repo can be found on https://github.com/Doyban/Doyban-Website

@userquin
Copy link
Member

userquin commented Sep 28, 2023

why are you using injectManifest strategy without a custom sw? Use generateSW strategy (default), it should work.

EDIT: are you using generate or build to deploy the app? if using build, you should prerender the root route (/)

@danieldanielecki
Copy link
Author

No changes without injectManifest / with generateSW.
I have ServiceWorker in public/sw.js:

import { clientsClaim } from 'workbox-core'
import {
  precacheAndRoute,
  cleanupOutdatedCaches,
  createHandlerBoundToURL,
} from 'workbox-precaching'
import { registerRoute, NavigationRoute } from 'workbox-routing'

self.skipWaiting()
clientsClaim()
precacheAndRoute(self.__WB_MANIFEST)
cleanupOutdatedCaches()

//You can remove this code if you aren't precaching anything, or leave it in and live with the warning message
try {
  const handler = createHandlerBoundToURL('/')
  const route = new NavigationRoute(handler)
  registerRoute(route)
} catch (error) {
  console.warn('Error while registering cache route', { error })
}

I'm using generate.

@userquin
Copy link
Member

userquin commented Nov 24, 2023

Move the sw.js to some src folder and update the pwa options, you need to "build" it since cannot use you're using import statements inside a service worker (sw cannot use static/dynamic imports if you don't register it using type module, and will work only on chromium based browsers; IIRC you cannot use dynamic imports with type module yet).

You can also change static imports with importScripts but you will need to add them also to the public folder or use CDN (you can keep your service worker in the public folder).

Check elk.zone github repo, you've an example and the configuration needed to build your service worker, check servce-worker folder and typescrupt option in nuxt.config.ts file (the service worker using TypeScript):

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants