Skip to content

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

@wanderview

Description

@wanderview

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?

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions