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:
Dmitry Gozman 2021-11-24 10:46:32 -08:00 committed by GitHub
parent fc9747b1df
commit b8b6c7a220
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 12 additions and 1 deletions

View File

@ -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);
} }

View File

@ -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;
} }