@@ -39,6 +39,7 @@ import { ConsoleMessage } from '../console';
3939import { NotConnectedError } from '../errors' ;
4040import { logError } from '../logger' ;
4141
42+
4243const UTILITY_WORLD_NAME = '__playwright_utility_world__' ;
4344
4445export class CRPage implements PageDelegate {
@@ -55,7 +56,7 @@ export class CRPage implements PageDelegate {
5556 private readonly _pagePromise : Promise < Page | Error > ;
5657 _initializedPage : Page | null = null ;
5758
58- constructor ( client : CRSession , targetId : string , browserContext : CRBrowserContext , opener : CRPage | null ) {
59+ constructor ( client : CRSession , targetId : string , browserContext : CRBrowserContext , opener : CRPage | null , hasUIWindow : boolean ) {
5960 this . _targetId = targetId ;
6061 this . _opener = opener ;
6162 this . rawKeyboard = new RawKeyboardImpl ( client ) ;
@@ -67,7 +68,7 @@ export class CRPage implements PageDelegate {
6768 this . _mainFrameSession = new FrameSession ( this , client , targetId ) ;
6869 this . _sessions . set ( targetId , this . _mainFrameSession ) ;
6970 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 ) ;
7172 }
7273
7374 private async _forAllFrameSessions ( cb : ( frame : FrameSession ) => Promise < any > ) {
@@ -97,7 +98,7 @@ export class CRPage implements PageDelegate {
9798 this . _page . _frameManager . removeChildFramesRecursively ( frame ) ;
9899 const frameSession = new FrameSession ( this , session , targetId ) ;
99100 this . _sessions . set ( targetId , frameSession ) ;
100- frameSession . _initialize ( ) . catch ( e => e ) ;
101+ frameSession . _initialize ( false ) . catch ( e => e ) ;
101102 }
102103
103104 removeFrameSession ( targetId : Protocol . Target . TargetID ) {
@@ -319,6 +320,7 @@ class FrameSession {
319320 private _firstNonInitialNavigationCommittedPromise : Promise < void > ;
320321 private _firstNonInitialNavigationCommittedFulfill = ( ) => { } ;
321322 private _firstNonInitialNavigationCommittedReject = ( e : Error ) => { } ;
323+ private _windowId : number | undefined ;
322324
323325 constructor ( crPage : CRPage , client : CRSession , targetId : string ) {
324326 this . _client = client ;
@@ -364,7 +366,11 @@ class FrameSession {
364366 ] ;
365367 }
366368
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+ }
368374 let lifecycleEventsEnabled : Promise < any > ;
369375 if ( ! this . _isMainFrame ( ) )
370376 this . _addSessionListeners ( ) ;
@@ -696,6 +702,20 @@ class FrameSession {
696702 screenOrientation : isLandscape ? { angle : 90 , type : 'landscapePrimary' } : { angle : 0 , type : 'portraitPrimary' } ,
697703 } ) ,
698704 ] ;
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+ }
699719 await Promise . all ( promises ) ;
700720 }
701721
0 commit comments