mafintosh / mafintosh/browser-server

Properly wait for the serviceworker to be ready

Open
#6 2 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
JavaScript
Stars
186
Forks
12
PR merge metrics
No merged PRs in 30d

Description

It seems that there is a small wait between when the .ready method is called and the serviceworker actually claims the client.

We should wait for the controller before firing ready:

  navigator.serviceWorker.register('/worker.js').then(function () {
    return navigator.serviceWorker.ready
  }).then(function (reg) {
    if (navigator.serviceWorker.controller) {
      self.emit('ready')
    } else {
      var listener = navigator.serviceWorker.addEventListener('controllerchange', () => {
        navigator.serviceWorker.removeEventListener('controllerchange', listener)
        self.emit('ready')
      })
    }
  })

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by locating the service-worker registration and the handling of navigator.serviceWorker.ready described in the issue. Ensure the ready event is emitted only after navigator.serviceWorker.controller is available, including the controllerchange path, and verify the registration behavior in the browser.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript
Domain
web-dev
Issue type
Bug
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
55/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.