mirror of
https://github.com/microsoft/playwright.git
synced 2025-06-26 21:40:17 +00:00
fix(protocol): rename websocket error event to socketerror (#4495)
This is to avoid special handling of error events in node.
This commit is contained in:
parent
1278c25442
commit
09f9a35198
@ -336,7 +336,7 @@ export class WebSocket extends ChannelOwner<channels.WebSocketChannel, channels.
|
||||
const payload = event.opcode === 2 ? Buffer.from(event.data, 'base64') : event.data;
|
||||
this.emit(Events.WebSocket.FrameReceived, { payload });
|
||||
});
|
||||
this._channel.on('error', ({ error }) => this.emit(Events.WebSocket.Error, error));
|
||||
this._channel.on('socketError', ({ error }) => this.emit(Events.WebSocket.Error, error));
|
||||
this._channel.on('close', () => {
|
||||
this._isClosed = true;
|
||||
this.emit(Events.WebSocket.Close);
|
||||
|
@ -107,7 +107,7 @@ export class WebSocketDispatcher extends Dispatcher<WebSocket, channels.WebSocke
|
||||
});
|
||||
webSocket.on(WebSocket.Events.FrameSent, (event: { opcode: number, data: string }) => this._dispatchEvent('frameSent', event));
|
||||
webSocket.on(WebSocket.Events.FrameReceived, (event: { opcode: number, data: string }) => this._dispatchEvent('frameReceived', event));
|
||||
webSocket.on(WebSocket.Events.Error, (error: string) => this._dispatchEvent('error', { error }));
|
||||
webSocket.on(WebSocket.Events.SocketError, (error: string) => this._dispatchEvent('socketError', { error }));
|
||||
webSocket.on(WebSocket.Events.Close, () => this._dispatchEvent('close', {}));
|
||||
}
|
||||
}
|
||||
|
@ -2215,7 +2215,7 @@ export interface WebSocketChannel extends Channel {
|
||||
on(event: 'open', callback: (params: WebSocketOpenEvent) => void): this;
|
||||
on(event: 'frameSent', callback: (params: WebSocketFrameSentEvent) => void): this;
|
||||
on(event: 'frameReceived', callback: (params: WebSocketFrameReceivedEvent) => void): this;
|
||||
on(event: 'error', callback: (params: WebSocketErrorEvent) => void): this;
|
||||
on(event: 'socketError', callback: (params: WebSocketSocketErrorEvent) => void): this;
|
||||
on(event: 'close', callback: (params: WebSocketCloseEvent) => void): this;
|
||||
}
|
||||
export type WebSocketOpenEvent = {};
|
||||
@ -2227,7 +2227,7 @@ export type WebSocketFrameReceivedEvent = {
|
||||
opcode: number,
|
||||
data: string,
|
||||
};
|
||||
export type WebSocketErrorEvent = {
|
||||
export type WebSocketSocketErrorEvent = {
|
||||
error: string,
|
||||
};
|
||||
export type WebSocketCloseEvent = {};
|
||||
|
@ -1895,7 +1895,7 @@ WebSocket:
|
||||
opcode: number
|
||||
data: string
|
||||
|
||||
error:
|
||||
socketError:
|
||||
parameters:
|
||||
error: string
|
||||
|
||||
|
@ -336,7 +336,7 @@ export class WebSocket extends EventEmitter {
|
||||
|
||||
static Events = {
|
||||
Close: 'close',
|
||||
Error: 'socketerror',
|
||||
SocketError: 'socketerror',
|
||||
FrameReceived: 'framereceived',
|
||||
FrameSent: 'framesent',
|
||||
};
|
||||
@ -359,7 +359,7 @@ export class WebSocket extends EventEmitter {
|
||||
}
|
||||
|
||||
error(errorMessage: string) {
|
||||
this.emit(WebSocket.Events.Error, errorMessage);
|
||||
this.emit(WebSocket.Events.SocketError, errorMessage);
|
||||
}
|
||||
|
||||
closed() {
|
||||
|
@ -168,11 +168,26 @@ it('should scope browser handles', async ({browserType, browserOptions}) => {
|
||||
await expectScopeState(browserType, GOLDEN_PRECONDITION);
|
||||
});
|
||||
|
||||
it('should work with the domain module', async ({ domain, browserType, browserOptions }) => {
|
||||
it('should work with the domain module', async ({ domain, browserType, browserOptions, server, isFirefox }) => {
|
||||
const browser = await browserType.launch(browserOptions);
|
||||
const page = await browser.newPage();
|
||||
const result = await page.evaluate(() => 1 + 1);
|
||||
expect(result).toBe(2);
|
||||
|
||||
expect(await page.evaluate(() => 1 + 1)).toBe(2);
|
||||
|
||||
// At the time of writing, we used to emit 'error' event for WebSockets,
|
||||
// which failed with 'domain' module.
|
||||
let callback;
|
||||
const result = new Promise(f => callback = f);
|
||||
page.on('websocket', ws => ws.on('socketerror', callback));
|
||||
page.evaluate(port => {
|
||||
new WebSocket('ws://localhost:' + port + '/bogus-ws');
|
||||
}, server.PORT);
|
||||
const message = await result;
|
||||
if (isFirefox)
|
||||
expect(message).toBe('CLOSE_ABNORMAL');
|
||||
else
|
||||
expect(message).toContain(': 400');
|
||||
|
||||
await browser.close();
|
||||
});
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user