@@ -39,6 +39,7 @@ import { ConsoleMessage } from '../console';
39
39
import { NotConnectedError } from '../errors' ;
40
40
import { logError } from '../logger' ;
41
41
42
+
42
43
const UTILITY_WORLD_NAME = '__playwright_utility_world__' ;
43
44
44
45
export class CRPage implements PageDelegate {
@@ -55,7 +56,7 @@ export class CRPage implements PageDelegate {
55
56
private readonly _pagePromise : Promise < Page | Error > ;
56
57
_initializedPage : Page | null = null ;
57
58
58
- constructor ( client : CRSession , targetId : string , browserContext : CRBrowserContext , opener : CRPage | null ) {
59
+ constructor ( client : CRSession , targetId : string , browserContext : CRBrowserContext , opener : CRPage | null , hasUIWindow : boolean ) {
59
60
this . _targetId = targetId ;
60
61
this . _opener = opener ;
61
62
this . rawKeyboard = new RawKeyboardImpl ( client ) ;
@@ -67,7 +68,7 @@ export class CRPage implements PageDelegate {
67
68
this . _mainFrameSession = new FrameSession ( this , client , targetId ) ;
68
69
this . _sessions . set ( targetId , this . _mainFrameSession ) ;
69
70
client . once ( CRSessionEvents . Disconnected , ( ) => this . _page . _didDisconnect ( ) ) ;
70
- this . _pagePromise = this . _mainFrameSession . _initialize ( ) . then ( ( ) => this . _initializedPage = this . _page ) . catch ( e => e ) ;
71
+ this . _pagePromise = this . _mainFrameSession . _initialize ( hasUIWindow ) . then ( ( ) => this . _initializedPage = this . _page ) . catch ( e => e ) ;
71
72
}
72
73
73
74
private async _forAllFrameSessions ( cb : ( frame : FrameSession ) => Promise < any > ) {
@@ -97,7 +98,7 @@ export class CRPage implements PageDelegate {
97
98
this . _page . _frameManager . removeChildFramesRecursively ( frame ) ;
98
99
const frameSession = new FrameSession ( this , session , targetId ) ;
99
100
this . _sessions . set ( targetId , frameSession ) ;
100
- frameSession . _initialize ( ) . catch ( e => e ) ;
101
+ frameSession . _initialize ( false ) . catch ( e => e ) ;
101
102
}
102
103
103
104
removeFrameSession ( targetId : Protocol . Target . TargetID ) {
@@ -319,6 +320,7 @@ class FrameSession {
319
320
private _firstNonInitialNavigationCommittedPromise : Promise < void > ;
320
321
private _firstNonInitialNavigationCommittedFulfill = ( ) => { } ;
321
322
private _firstNonInitialNavigationCommittedReject = ( e : Error ) => { } ;
323
+ private _windowId : number | undefined ;
322
324
323
325
constructor ( crPage : CRPage , client : CRSession , targetId : string ) {
324
326
this . _client = client ;
@@ -364,7 +366,11 @@ class FrameSession {
364
366
] ;
365
367
}
366
368
367
- async _initialize ( ) {
369
+ async _initialize ( hasUIWindow : boolean ) {
370
+ if ( hasUIWindow ) {
371
+ const { windowId } = await this . _client . send ( 'Browser.getWindowForTarget' ) ;
372
+ this . _windowId = windowId ;
373
+ }
368
374
let lifecycleEventsEnabled : Promise < any > ;
369
375
if ( ! this . _isMainFrame ( ) )
370
376
this . _addSessionListeners ( ) ;
@@ -696,6 +702,20 @@ class FrameSession {
696
702
screenOrientation : isLandscape ? { angle : 90 , type : 'landscapePrimary' } : { angle : 0 , type : 'portraitPrimary' } ,
697
703
} ) ,
698
704
] ;
705
+ if ( this . _windowId ) {
706
+ let insets = { width : 24 , height : 88 } ;
707
+ if ( process . platform === 'win32' )
708
+ insets = { width : 16 , height : 88 } ;
709
+ else if ( process . platform === 'linux' )
710
+ insets = { width : 8 , height : 85 } ;
711
+ else if ( process . platform === 'darwin' )
712
+ insets = { width : 2 , height : 80 } ;
713
+
714
+ promises . push ( this . _client . send ( 'Browser.setWindowBounds' , {
715
+ windowId : this . _windowId ,
716
+ bounds : { width : viewport . width + insets . width , height : viewport . height + insets . height }
717
+ } ) ) ;
718
+ }
699
719
await Promise . all ( promises ) ;
700
720
}
701
721
0 commit comments