WebSocket: open event

The open handler is executed when a connection with a websocket is opened.

Bubbles No
Cancelable No
Interface Event
Event handler property onopen


// Create WebSocket connection.
const socket = new WebSocket('ws://localhost:8080');

// Connection opened
socket.addEventListener('open', (event) => {
    socket.send('Hello Server!');


Specification Status Comment
HTML Living Standard
The definition of 'WebSocket' in that specification.
Living Standard Initial definition

Browser compatibility

No compatibility data found. Please contribute data for "api.WebSocket.open" (depth: 1) to the MDN compatibility data repository.

See also

Document Tags and Contributors

Contributors to this page: irenesmith, mdnwebdocs-bot, fscholz, teoli, Sheppy, ethertank, louisremi
Last updated by: irenesmith,