service-worker

Is it possible to intercept and cache WebSocket messages in a Service Worker like all the examples do for normal HTTP requests?

别说谁变了你拦得住时间么 提交于 2019-12-01 14:52:44
问题 I know you can create WebSocket connections from within a Service Worker itself; my question is more whether or not you can use a WebSocket from your app as normal and have the Service Worker intercept / cache WebSocket requests just like it can do for normal HTTP fetch requests? Here's an example of intercepting and caching a normal HTTP request from a Service Worker. self.addEventListener('fetch', function(event) { // If a match isn't found in the cache, the response // will look like a

Google Colaboratory ServiceWorker Error On Chrome

女生的网名这么多〃 提交于 2019-12-01 14:43:27
问题 Whenever I open a Colaboratory Document I always get the same error message: NotSupportedError: Failed to register a ServiceWorker: The user denied permission to use Service Worker. This is happening on chrome and my browser allows for ServiceWorkers ( chrome://serviceworker-internals/ ), what's going on? Because the thing is all the code still runs. 回答1: Colab's output frames use service workers to support some functionality such as displaying richer graphs (Altair and Plot.ly). The error

Posting data with GCM push notification

家住魔仙堡 提交于 2019-12-01 09:20:59
I'm trying out the GCM push notification API. So far it works fine, but I'm not sure how to post additional data. I followed the steps on this page: https://developers.google.com/web/fundamentals/getting-started/push-notifications/step-07 So I ended up writing a curl request like this: curl --header "Authorization: key=myKey" --header "Content-Type: application/json" https://android.googleapis.com/gcm/send -d "{\"registration_ids\":[myRegistrationId], \"additionalData\": {\"user_id\":\"1\"}}" And then my sw.js (my service worker) self.addEventListener('push', function(event) { console.log(

getSubscription returns a null subscription

夙愿已清 提交于 2019-12-01 07:18:57
I am new to service workers and GAE, I am able to register the service workers but not able to subscribe the PushManager, getting subscription null error. Find the below code for reference. serviceWorkerRegistration.pushManager.getSubscription() .then(function(subscription) { var pushButton = document.querySelector('.js-push-button'); pushButton.disabled = false; if (!subscription) { console.log('subscription error '); return; } console.log('subscriptioned '); // Keep your server in sync with the latest subscriptionId sendSubscriptionToServer(subscription); // Set your UI to show they have

Can users clear the service worker cache?

大憨熊 提交于 2019-12-01 06:36:13
I've built a Progressive Web App that uses caching, but it's unclear to me whether users can (accidentally or on purpose) clear the service worker cache, which may clear my tracking data. When a user clears their browsing data / cookies, this clears all site storage which includes the SW cache, cookies, local storage, indexeddb, and any other local caching system. Furthermore, Ctrl-F5 forces a cache refresh, and is intended to abandon all cached content including service worker cache and just retrieve all content from the servers again. "Clear site data" in Chrome 76 will delete the caches and

getSubscription returns a null subscription

核能气质少年 提交于 2019-12-01 05:10:56
问题 I am new to service workers and GAE, I am able to register the service workers but not able to subscribe the PushManager, getting subscription null error. Find the below code for reference. serviceWorkerRegistration.pushManager.getSubscription() .then(function(subscription) { var pushButton = document.querySelector('.js-push-button'); pushButton.disabled = false; if (!subscription) { console.log('subscription error '); return; } console.log('subscriptioned '); // Keep your server in sync with

Prevent Service Worker from automatically stopping

China☆狼群 提交于 2019-12-01 02:34:40
Service Worker seems to automatically stop at some point. This behaviour unintentionally closes the WebSocket connection established on activate. When and Why does it stop? How can I programmatically disable this unexpected action to keep Service Worker stay running? What you're seeing is the expected behavior, and it's not likely to change. Service workers intentionally have very short lifespans. They are "born" in response to a specific event ( install , activate , message , fetch , push , etc.), perform their task, and then "die" shortly thereafter. The lifespan is normally long enough that

serviceworkers focus tab: clients is empty on notificationclick

爱⌒轻易说出口 提交于 2019-12-01 02:25:21
I have a common serviceworker escenario, where I want catch a notification click and focus the tab where the notification has come from. However, clients variable is always empty, its lenght is 0 console.log("sw startup"); self.addEventListener('install', function (event) { console.log("SW installed"); }); self.addEventListener('activate', function (event) { console.log("SW activated"); }); self.addEventListener("notificationclick", function (e) { // Android doesn't automatically close notifications on click console.log(e); e.notification.close(); // Focus tab if open e.waitUntil(clients

Service worker add files from API call to precache

我是研究僧i 提交于 2019-12-01 01:23:40
To enable my app running offline. During installation the service worker should: fetch a list of URLs from an async API reformat the response add all URLs in the response to the precache For this task I use Googles Workbox in combination with Webpack. The problem: While the service worker successfully caches all the Webpack assets (which tells me that the workbox basically does what it should), it does not wait for the async API call to cache the additional remote assets. They are simply ignored and neither cached nor ever fetched in the network. Here is my service worker code: importScripts(

“New version available” with service worker and sw-precache

佐手、 提交于 2019-11-30 20:16:18
I'm trying to use sw-precache , but I must be doing something wrong! I'm mostly using the demo code available from the github repo and can't seem to get updates to the app to come through. Once it's cached the first time, it never checks for new versions. I was expecting that when I publish a new service worker, the browser would request the new service worker and update the cache accordingly in the background. Then using the registration code in the example , I would be able to prompt the user to refresh and get the latest version from their newly refreshed cache. Would really appreciate if