w3c / w3c/ServiceWorker

is the browser required to start the ServiceWorker for postMessage() if there is no message event handler?

Open
#1,200 11 comments 0 reactions 1 assignee View on GitHub

@mfalken is already working on this.

Since Jun 3, 2019.

decided
Dominant language
Bikeshed
Stars
3.6k
Forks
324
Avg merge
14d 22h
Merged PRs (30d)
1

Description

Consider this code:

// main window script
let bc = new BroadcastChannel('sw_side_channel');
sw.onmessage = evt => console.log('service worker started up');
navigator.serviceWorker.controller.postMessage('ping');

// service worker script
let bc = new BroadcastChannel('sw_side_channel');
bc.postMessage('pong');
self.onmessage = null;  // no direct message event handler

Is the browser required to start the service worker if its not running and a postMessage() is fired at while there is no message event handler? Worker startup is observable thanks to things like BroadcastChannel or Clients API.

Or can the browser do similar optimizations like we do for FetchEvent where we don't start the worker if there is no message handler?

Contributor guide

Open the contributing guide

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.

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.