I'm trying to use the Service Worker but a the moment of registration I get this error:
I got that the service worker can't subscribe because the evaluation of the script failed, but I don't get why "Username" is not defined, cause if I debug it I can see the value inside it, and inside the service worker the value is passed correctly, but I can't figure out why "Username" is not defined. Help please!
This is the start and the end of the Sevice Worker:
This is the Service Worker:
You can inject parameter in url during registration
navigator.serviceWorker.register("my-service-worker.js?someParam=someValue")
and inside my-service-worker.js
you can read it as follows
var param = null;
self.addEventListener('install', function (event) {
param = new URL(location).searchParams.get('someParam');
});
you can add more params using &
separator
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.