puppeteer-core
Version:
A high-level API to control headless Chrome over the DevTools Protocol
43 lines • 1.25 kB
JavaScript
Object.defineProperty(exports, "__esModule", { value: true });
exports.BrowserWebSocketTransport = void 0;
/**
* @internal
*/
class BrowserWebSocketTransport {
static create(url) {
return new Promise((resolve, reject) => {
const ws = new WebSocket(url);
ws.addEventListener('open', () => {
return resolve(new BrowserWebSocketTransport(ws));
});
ws.addEventListener('error', reject);
});
}
#ws;
onmessage;
onclose;
constructor(ws) {
this.#ws = ws;
this.#ws.addEventListener('message', event => {
if (this.onmessage) {
this.onmessage.call(null, event.data);
}
});
this.#ws.addEventListener('close', () => {
if (this.onclose) {
this.onclose.call(null);
}
});
// Silently ignore all errors - we don't know what to do with them.
this.#ws.addEventListener('error', () => { });
}
send(message) {
this.#ws.send(message);
}
close() {
this.#ws.close();
}
}
exports.BrowserWebSocketTransport = BrowserWebSocketTransport;
//# sourceMappingURL=BrowserWebSocketTransport.js.map
;