logo
down
shadow

Service worker error: event already responded to


Service worker error: event already responded to

By : Moaz M. Abboud
Date : November 20 2020, 03:01 PM
seems to work fine The problem is that your call to event.respondWith() is inside your top-level promise's .then() clause, meaning that it will be asynchronously executed after the top-level promise resolves. In order to get the behavior you're expecting, event.respondWith() needs to execute synchronously as part of the fetch event handler's execution.
The logic inside of your promise is a bit hard to follow, so I'm not exactly sure what you're trying to accomplish, but in general you can follow this pattern:
code :
self.addEventListerner('fetch', event => {
  // Perform any synchronous checks to see whether you want to respond.
  // E.g., check the value of event.request.url.
  if (event.request.url.includes('something')) {
    const promiseChain = doSomethingAsync()
      .then(() => doSomethingAsyncThatReturnsAURL())
      .then(someUrl => fetch(someUrl));
      // Instead of fetch(), you could have called caches.match(),
      // or anything else that returns a promise for a Response.

    // Synchronously call event.respondWith(), passing in the
    // async promise chain.
    event.respondWith(promiseChain);
  }
});


Share : facebook icon twitter icon
service worker install event is called before register event is completed

service worker install event is called before register event is completed


By : James Bultitude
Date : March 29 2020, 07:55 AM
I wish this helpful for you navigator.serviceWorker.register() is not an event. It's a function that returns a promise, and then promise will resolve with a ServiceWorkerRegistration object that corresponds to the registration.
The actual service worker logic is executed in a different thread/process, and the lifecycle events that the service worker handles, like the install event, happen independently of the web page that registered the service worker. What you're seeing in your console.log() output is expected.
How to wait for 'message' event inside the 'install' event in service worker?

How to wait for 'message' event inside the 'install' event in service worker?


By : Herbert
Date : March 29 2020, 07:55 AM
around this issue I have a scenario where i need to send postMessage of latest version files array from client to service worker on the update event of service worker. , I believe you can do something like this:
code :
// sw.js

self.addEventListener('install', function(e) {
    const installPromise = new Promise(function(resolve, reject) {
        // do install stuff, like caching resources, etc.

        self.addEventListener('message', function(e) {
            // 1. do something with the received data
            // 2. remove this event listener
            resolve();
        });
    });

    e.waitUntil(installPromise);
});
Error:OAuth2 request failed: Service responded with error: 'bad client id: APP_ID_OR_ORIGIN_NOT_MATCH'

Error:OAuth2 request failed: Service responded with error: 'bad client id: APP_ID_OR_ORIGIN_NOT_MATCH'


By : Zin
Date : March 29 2020, 07:55 AM
this one helps. Two possibilities that I've faced:
The client ID type you created wasn't for "Chrome App" In the Credentials section of the developers console, click on the name of your client ID, and make sure that the "Applicaiton ID" section is correctly filled out. This should contain the ID shown under chrome://extensions/ as a a 32 character ID just below the description of your extension.
Distributed Tensorflow: The worker does not responded

Distributed Tensorflow: The worker does not responded


By : user2023746
Date : March 29 2020, 07:55 AM
I wish this help you Now, after I solved my error, I will share my solution. It was not a bug in the TF code but one of two things that I tried solved my problem stated above. Because I am working on EC2 instances, the firewall prevents the connection between nodes. So, I made the rule to accept all the traffics to the instances. Second, I was using only IP-address:port-No in the command line. Instead, I wrote it like this, ec2-IP.compute-1.amazonaws.com:2222.
Service worker / Safari / fetch event fires before the message event

Service worker / Safari / fetch event fires before the message event


By : user3680949
Date : March 29 2020, 07:55 AM
I think the issue was by ths following , I've tested this example both in Chrome and Safari but I am not relying on the postMessage method to send the form_data parameters. Instead, I am relying on the ServiceWorker's ability to listen for fetch events and grab request parameters inside of the handler.
code :
self.addEventListener(`fetch`, event => {
  const requestClone = event.request.clone()

  event.respondWith(
    (async function() {
      const params = await request.text().catch(err => err)

      if (params instanceof Error) {
        // this is a simple check, but handle error appropriately
      }

      if (event.request.method === `POST`) {
        console.log(`POST request with params: ${params}`)
        // do work here
      }
      return fetch(event.request)
    })()
  )
})
fetch("https://jsonplaceholder.typicode.com/posts", {
  method: "POST",
  body: JSON.stringify({ title: "foo", body: "bar", userId: 1 }),
  headers: { "Content-Type": `application/json` }
})
  .then(response => response.json())
  .then(json => console.log(`fetch response`, json))
  .catch(error => console.error(`fetch error`, error));

// console logs
//  >> POST request with {"title":"foo","body":"bar","userId":1} (worker.js)
//  >> fetch response {title: "foo", body: "bar", userId: 1, id: 101} (index.js)
Related Posts Related Posts :
  • Chrome-Extension/JavaScript How to make all links on page have no effect?
  • Websocket issue Internet Explorer
  • sessionStorage value becomes null in other tab in AngularJS
  • Split URL from position x to the end in Javascript
  • How to set value of input field with NgIf in Angular 4
  • invalidStateError for second time screenshare on Chrome
  • How do you pass a value to the variable in a xhr.setRequestHeader?
  • I cant start nodemon on my windows 10
  • Nested if else jumps out from the main if else in javascript
  • Iterate through all collections and remove them
  • ES6 - Value of a variable in template string does not increment
  • how to get content of html table cell using javascript javascript depending on checkbox
  • Node.js Working with Multiple Tier SQL
  • Can't allow Cross-Origin Request in local Nodejs server
  • Datatables orderable=false directly on table
  • Dynamically load js content with iron router in meteor using array in return statement
  • Limit checkbox to 2, but moving the select instead of blocking it
  • Why itsn't displaying marker on map?
  • jQuery target next of the same class in the whole DOM
  • encoding must be a valid encoding error in process encoding
  • How to do a date range to view data from selected date highcharts
  • How do I refactor this composed function with Ramda.js?
  • jQuery to serialize selected option's value, not label
  • Convert object to Chartis.js structure
  • Dynamic import with not bundled file
  • Click handler not firing for elements rendered in Ajax Callback - only in Safari
  • Math.max.apply gives an error CreateListFromArrayLike called on non-object
  • get the parent nodes to a given node in d3 dendogram
  • is-dropdown-submenu-parent makes links unclickable on Opera and Chrome
  • JS: Sum column values and updating result on change
  • Query against nested object keys
  • Fullcalendar getting its parent colspan
  • How to retrieve a dynamic number of elements by id
  • How to access redux variables and functions from deep components
  • Efficiently access Array.prorotype.filter single-item returns
  • PHP var into Javascript
  • How to parse json with javascript/jquery if content matches string
  • How can I make a pyramid based on alphabet?
  • Javascript sorting a csv rows and displaying in table
  • How to get specific data from json from api using ajax. The json looks strange to me
  • react js html5 video not working
  • Javascript Angular 4 Change ngClass from another Component
  • Hide multiple table columns with javascript
  • Convert datetime to ISO Format using moment js
  • Dynamically adjust canvas size depending on content
  • setTimeout function with document on click
  • Need advice on nested Promises.all
  • Google Captcha expiration time
  • Syntax of Javascript TAPE unit test
  • Parse php json to javascript
  • Write to Internet Explorer javascript console with vba in excel
  • 2 Forms with Jquery
  • Why the loop stops right in the middle?
  • filter system for restaurant booking
  • how to add active class in framework nav menu when (add/edit) pages are opened
  • Port a js map in dart
  • How to get value from select using javascript
  • Audio won't be muted with JavaScript - removing audio tags with mutationobserver needed
  • How to include an HTML/Javascript game into reactJS website
  • Convert Nodejs server into node module
  • shadow
    Privacy Policy - Terms - Contact Us © voile276.org