mirror of
https://github.com/microsoft/playwright.git
synced 2025-06-26 21:40:17 +00:00
fix(chromium): websocket handshake comes twice (#10518)
Sometimes we get "Network.webSocketWillSendHandshakeRequest" in Chromium. Perhaps websocket is restarted because of chrome.webRequest extensions api? Or maybe the handshake response was a redirect? This reports websocket twice and triggers an assert.
This commit is contained in:
parent
fc9747b1df
commit
b8b6c7a220
@ -377,7 +377,7 @@ export class FrameManager {
|
|||||||
|
|
||||||
onWebSocketRequest(requestId: string) {
|
onWebSocketRequest(requestId: string) {
|
||||||
const ws = this._webSockets.get(requestId);
|
const ws = this._webSockets.get(requestId);
|
||||||
if (ws)
|
if (ws && ws.markAsNotified())
|
||||||
this._page.emit(Page.Events.WebSocket, ws);
|
this._page.emit(Page.Events.WebSocket, ws);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -476,6 +476,7 @@ export class Response extends SdkObject {
|
|||||||
|
|
||||||
export class WebSocket extends SdkObject {
|
export class WebSocket extends SdkObject {
|
||||||
private _url: string;
|
private _url: string;
|
||||||
|
private _notified = false;
|
||||||
|
|
||||||
static Events = {
|
static Events = {
|
||||||
Close: 'close',
|
Close: 'close',
|
||||||
@ -489,6 +490,16 @@ export class WebSocket extends SdkObject {
|
|||||||
this._url = url;
|
this._url = url;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
markAsNotified() {
|
||||||
|
// Sometimes we get "onWebSocketRequest" twice, at least in Chromium.
|
||||||
|
// Perhaps websocket is restarted because of chrome.webRequest extensions api?
|
||||||
|
// Or maybe the handshake response was a redirect?
|
||||||
|
if (this._notified)
|
||||||
|
return false;
|
||||||
|
this._notified = true;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
url(): string {
|
url(): string {
|
||||||
return this._url;
|
return this._url;
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user