service-worker

Can an iframe render offline with a service worker?

放肆的年华 提交于 2020-06-25 17:31:11
问题 I have my domain, abc.com , and an iframe inside my page 123.com . I own the code for each domain. With a service worker I can load abc.com while offline but my iframe for 123.com does not load, even if I add its files to my cache.addAll call. How can I get my iframe to render while offline? Examples welcome. <!DOCTYPE html> <html> <head></head> <body> will render offline <!-- will not render offline --> <iframe src="123.com"></iframe> </body> </html> 回答1: Loading an <iframe> is very similar

Can an iframe render offline with a service worker?

我怕爱的太早我们不能终老 提交于 2020-06-25 17:27:13
问题 I have my domain, abc.com , and an iframe inside my page 123.com . I own the code for each domain. With a service worker I can load abc.com while offline but my iframe for 123.com does not load, even if I add its files to my cache.addAll call. How can I get my iframe to render while offline? Examples welcome. <!DOCTYPE html> <html> <head></head> <body> will render offline <!-- will not render offline --> <iframe src="123.com"></iframe> </body> </html> 回答1: Loading an <iframe> is very similar

How to reload the original url after recovering from network disconnection

☆樱花仙子☆ 提交于 2020-06-23 13:59:15
问题 I have webapp which uses a service worker that detects, when the network is offline, and serves a cached offline page. I have a case where: the program is started, while the network is connected, and loads the url https://localhost/my_site the user pushes a button which triggers a fetch call during that time, the network is disconnected, the service worker detects this state and returns a cached offline page the javascript code checks the response content type, finds that it is text/html

how to play sound in service worker or even vibrate in chrome?

大城市里の小女人 提交于 2020-06-16 08:11:21
问题 The bounty expires in 3 days . Answers to this question are eligible for a +100 reputation bounty. Giorgi Lagidze is looking for a canonical answer . I am using service workers . I need it for push notifications. What I want to achieve is that when I recieve notification, it should play a sound or vibrate at least. self.registration.showNotification(title, { body: body, icon: './assets/images/icons/icon_144x144.png', vibrate: [200, 100, 200, 100, 200, 100, 200], }); I am having this piece of

How to load Javascript file in a Service Worker dynamically?

不想你离开。 提交于 2020-06-15 18:29:12
问题 I can't use any solutions that involve creating a <script> tag dynamically because document does not exist in a ServiceWorker context. In this case I want to load analytics toolkit so I can track when SW-triggered Notifications are interacted with by the user. Any ideas? 回答1: That sounds like the intended use case of the importScripts() method. The imported script shares the global scope with your service worker, so modifying self via, e.g., self.addEventListener() or self.someIdentifier =

How to load Javascript file in a Service Worker dynamically?

旧时模样 提交于 2020-06-15 18:28:56
问题 I can't use any solutions that involve creating a <script> tag dynamically because document does not exist in a ServiceWorker context. In this case I want to load analytics toolkit so I can track when SW-triggered Notifications are interacted with by the user. Any ideas? 回答1: That sounds like the intended use case of the importScripts() method. The imported script shares the global scope with your service worker, so modifying self via, e.g., self.addEventListener() or self.someIdentifier =

What is the purpose of SwUpdate.activateUpdate() in Angular?

孤街醉人 提交于 2020-06-15 05:09:25
问题 Angular documentation provides following example to activate an SW update: constructor(updates: SwUpdate) { updates.available.subscribe(event => { if (promptUser(event)) { updates.activateUpdate().then(() => document.location.reload()); } }); } From what I observe, the call itself is not sufficient to activate new version, reload is necessary. However document.location.reload() is sufficient even without activateUpdate() call. What is the purpose of activateUpdate() call? Why call it at all

How to run service worker locally with Angular

…衆ロ難τιáo~ 提交于 2020-06-12 09:02:46
问题 I am following angular's best practice in order to make PWA. After making production build ( ng build --prod --aot ), I am also running the service worker from dist, on localhost : http-server -p 8080 -c-1 dist When I am trying to sync the worker with my Angular, using: navigator.serviceWorker.ready.then(function(swRegistration) { console.log('swReady'); }); Nothing happens, and seems that SW is not communicating with Angular. Working with a remote server (uploading dist) does work. So seems

How to implement skipWaiting with Create React App?

偶尔善良 提交于 2020-06-09 11:18:49
问题 I would like users to be able to update on the spot when a new service worker is available and waiting? I'm already able to show a pop up when new update is available but I would like to add a button to force update on the spot. I understand this can be achieved with calling skipWaiting but not sure how to implement it with a Create React App. Have anyone able to achieve this? Would appreciate the help. Thank you! 回答1: The CRA build\service-worker.js file now (v3 plus) includes code to handle

When and how does a PWA update itself?

孤街浪徒 提交于 2020-06-09 08:20:46
问题 As far as I know, once you click "add to homescreen" on a PWA's website, the browser generates an .apk using the provided manifest file and sources and installs it like a normal app. I noticed that when I update the website, the app also displays the updated content which suggests that the app is just a wrapper for accessing the website. I also noticed that the update to a website is not displayed instantly, I assume this is due to internal caching. My question is, are my assumptions correct?