mirror of
https://github.com/microsoft/playwright.git
synced 2024-12-14 21:53:35 +03: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) {
|
||||
const ws = this._webSockets.get(requestId);
|
||||
if (ws)
|
||||
if (ws && ws.markAsNotified())
|
||||
this._page.emit(Page.Events.WebSocket, ws);
|
||||
}
|
||||
|
||||
|
@ -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;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user