WorkerGlobalScope: online event

Limited availability

This feature is not Baseline because it does not work in some of the most widely-used browsers.

>

Note: This feature is only available in Web Workers.

The online event of the WorkerGlobalScope fires when the device reconnects to the internet.

Syntax

Use the event name in addEventListener():

js
addEventListener("online", (event) => { })

Alternatively, assign to the event handler property of the interface:

js
ononline = (event) => { }

Event type

A generic Event.

Example

The following code snippet shows an ononline handler set inside a worker (but note that this replaces other event listeners added using ononline, if any):

js
self.ononline = () => {
  console.log("Your worker is now online");
};

The same snippet, but using addEventListener():

js
self.addEventListener("online", () => {
  console.log("Your worker is now online");
});

Specifications

Specification
HTML>
# handler-workerglobalscope-ononline>

Browser compatibility

See also

The WorkerGlobalScope interface it belongs to.