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) {
const ws = this._webSockets.get(requestId);
if (ws)
if (ws && ws.markAsNotified())
this._page.emit(Page.Events.WebSocket, ws);
}

View File

@ -476,6 +476,7 @@ export class Response extends SdkObject {
export class WebSocket extends SdkObject {
private _url: string;
private _notified = false;
static Events = {
Close: 'close',
@ -489,6 +490,16 @@ export class WebSocket extends SdkObject {
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 {
return this._url;
}