WorkerGlobalScope: offline 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 offline event of the WorkerGlobalScope fires when the device loses connection to the internet.
Syntax
Use the event name in addEventListener():
js
addEventListener("offline", (event) => { })
Alternatively, assign to the event handler property of the interface:
js
onoffline = (event) => { }
Event type
A generic Event.
Example
The following code snippet shows an onoffline handler set inside a worker (but note that this replaces other event listeners added using onoffline, if any):
js
self.onoffline = () => {
console.log("Your worker is now offline");
};
The same snippet, but using addEventListener():
js
self.addEventListener("offline", () => {
console.log("Your worker is now offline");
});
Specifications
| Specification |
|---|
| HTML> # handler-workerglobalscope-onoffline> |
Browser compatibility
See also
The WorkerGlobalScope interface it belongs to.