This feature is well established and works across many devices and browser versions. It’s been available across browsers since August 2016.
Note: This feature is available in Web Workers.
The CloseEvent() constructor creates a new CloseEvent object.
new CloseEvent(type) new CloseEvent(type, options)
typeA string with the name of the event. It is case-sensitive and browsers always set it to close.
options OptionalAn object that, in addition of the properties defined in Event(), has the following properties:
wasClean OptionalA boolean value indicating if the connection has been closed cleanly or not. It defaults to false.
code OptionalAn integer representing the connection close code sent by the server. It defaults to 0.
reason OptionalA string containing a human-readable reason describing why the server closed the connection. It defaults to ''
A new CloseEvent object.
| Specification |
|---|
| WebSockets> # dom-closeevent-closeevent> |
| Desktop | Mobile | |||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|
| Chrome | Edge | Firefox | Opera | Safari | Chrome Android | Firefox for Android | Opera Android | Safari on IOS | Samsung Internet | WebView Android | WebView on iOS | |
CloseEvent |
16 | 14 | 11 | 12.1 | 6 | 18 | 14 | 12.1 | 6 | 1.0 | 4.4 | 6 |
CloseEvent, the interface of the objects it constructs.
© 2005–2025 MDN contributors.
Licensed under the Creative Commons Attribution-ShareAlike License v2.5 or later.
https://developer.mozilla.org/en-US/docs/Web/API/CloseEvent/CloseEvent