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 inWeb Workers.
Theonline event of theWorkerGlobalScope fires when the device reconnects to the internet.
In this article
Syntax
Use the event name in methods likeaddEventListener(), or set an event handler property.
js
addEventListener("online", (event) => { })ononline = (event) => { }Event type
A genericEvent.
Example
The following code snippet shows anonoffline handler set inside a worker:
js
self.ononline = () => { console.log("Your worker is now online");};The same snippet, but usingaddEventListener():
js
self.addEventListener("online", () => { console.log("Your worker is now online");});Specifications
| Specification |
|---|
| HTML> # handler-workerglobalscope-ononline> |
Browser compatibility
See also
TheWorkerGlobalScope interface it belongs to.