File tree Expand file tree Collapse file tree 2 files changed +15
-3
lines changed
packages/playwright-core/src/server/bidi Expand file tree Collapse file tree 2 files changed +15
-3
lines changed Original file line number Diff line number Diff line change @@ -28,7 +28,8 @@ import type * as bidi from './third_party/bidiProtocol';
28
28
29
29
// BidiPlaywright uses this special id to issue Browser.close command which we
30
30
// should ignore.
31
- export const kBrowserCloseMessageId = 0 ;
31
+ export const kBrowserCloseMessageId = Number . MAX_SAFE_INTEGER - 1 ;
32
+ export const kShutdownSessionNewMessageId = kBrowserCloseMessageId - 1 ;
32
33
33
34
export class BidiConnection {
34
35
private readonly _transport : ConnectionTransport ;
@@ -209,7 +210,7 @@ export class BidiSession extends EventEmitter {
209
210
210
211
dispatchMessage ( message : any ) {
211
212
const object = message as bidi . Message ;
212
- if ( object . id === kBrowserCloseMessageId )
213
+ if ( object . id === kBrowserCloseMessageId || object . id === kShutdownSessionNewMessageId )
213
214
return ;
214
215
if ( object . id && this . _callbacks . has ( object . id ) ) {
215
216
const callback = this . _callbacks . get ( object . id ) ! ;
Original file line number Diff line number Diff line change @@ -20,7 +20,7 @@ import path from 'path';
20
20
import { wrapInASCIIBox } from '../utils/ascii' ;
21
21
import { BrowserType , kNoXServerRunningError } from '../browserType' ;
22
22
import { BidiBrowser } from './bidiBrowser' ;
23
- import { kBrowserCloseMessageId } from './bidiConnection' ;
23
+ import { kBrowserCloseMessageId , kShutdownSessionNewMessageId } from './bidiConnection' ;
24
24
import { createProfile } from './third_party/firefoxPrefs' ;
25
25
import { ManualPromise } from '../../utils/isomorphic/manualPromise' ;
26
26
@@ -78,6 +78,17 @@ export class BidiFirefox extends BrowserType {
78
78
}
79
79
80
80
override attemptToGracefullyCloseBrowser ( transport : ConnectionTransport ) : void {
81
+ // browser.close does not work without an active session, make sure
82
+ // to create a new session first. The command will fail if a session
83
+ // already exists, we'll just ignore the error.
84
+ transport . send ( { method : 'session.new' , params : {
85
+ capabilities : {
86
+ alwaysMatch : {
87
+ unhandledPromptBehavior : { default : 'ignore' } ,
88
+ webSocketUrl : true
89
+ }
90
+ }
91
+ } , id : kShutdownSessionNewMessageId } ) ;
81
92
transport . send ( { method : 'browser.close' , params : { } , id : kBrowserCloseMessageId } ) ;
82
93
}
83
94
You can’t perform that action at this time.
0 commit comments