@@ -146,8 +146,9 @@ class TargetRegistry {
146
146
let tab ;
147
147
let gBrowser ;
148
148
const windowsIt = Services . wm . getEnumerator ( 'navigator:browser' ) ;
149
+ let window ;
149
150
while ( windowsIt . hasMoreElements ( ) ) {
150
- const window = windowsIt . getNext ( ) ;
151
+ window = windowsIt . getNext ( ) ;
151
152
// gBrowser is always created before tabs. If gBrowser is not
152
153
// initialized yet the browser belongs to another window.
153
154
if ( ! window . gBrowser )
@@ -172,7 +173,7 @@ class TargetRegistry {
172
173
openerTarget = this . _browserToTarget . get ( tab . openerTab . linkedBrowser ) ;
173
174
}
174
175
const browserContext = this . _userContextIdToBrowserContext . get ( userContextId ) ;
175
- const target = new PageTarget ( this , gBrowser , tab , linkedBrowser , browserContext , openerTarget ) ;
176
+ const target = new PageTarget ( this , window , gBrowser , tab , linkedBrowser , browserContext , openerTarget ) ;
176
177
177
178
const sessions = [ ] ;
178
179
const readyData = { sessions, target } ;
@@ -187,12 +188,12 @@ class TargetRegistry {
187
188
} ,
188
189
} ) ;
189
190
190
- const onTabOpenListener = event => {
191
+ const onTabOpenListener = ( window , event ) => {
191
192
const tab = event . target ;
192
193
const userContextId = tab . userContextId ;
193
194
const browserContext = this . _userContextIdToBrowserContext . get ( userContextId ) ;
194
195
if ( browserContext && browserContext . defaultViewportSize )
195
- setViewportSizeForBrowser ( browserContext . defaultViewportSize , tab . linkedBrowser ) ;
196
+ setViewportSizeForBrowser ( browserContext . defaultViewportSize , tab . linkedBrowser , window ) ;
196
197
} ;
197
198
198
199
const onTabCloseListener = event => {
@@ -220,7 +221,7 @@ class TargetRegistry {
220
221
} ) ;
221
222
if ( ! domWindow . gBrowser )
222
223
return ;
223
- domWindow . gBrowser . tabContainer . addEventListener ( 'TabOpen' , onTabOpenListener ) ;
224
+ domWindow . gBrowser . tabContainer . addEventListener ( 'TabOpen' , event => onTabOpenListener ( domWindow , event ) ) ;
224
225
domWindow . gBrowser . tabContainer . addEventListener ( 'TabClose' , onTabCloseListener ) ;
225
226
} ,
226
227
onCloseWindow : window => {
@@ -304,7 +305,7 @@ class TargetRegistry {
304
305
} ) ;
305
306
} ) ;
306
307
if ( browserContext && browserContext . defaultViewportSize )
307
- setViewportSizeForBrowser ( browserContext . defaultViewportSize , browser ) ;
308
+ setViewportSizeForBrowser ( browserContext . defaultViewportSize , browser , window ) ;
308
309
browser . focus ( ) ;
309
310
if ( browserContext . settings . timezoneId ) {
310
311
if ( await target . hasFailedToOverrideTimezone ( ) )
@@ -332,11 +333,12 @@ class TargetRegistry {
332
333
}
333
334
334
335
class PageTarget {
335
- constructor ( registry , gBrowser , tab , linkedBrowser , browserContext , opener ) {
336
+ constructor ( registry , win , gBrowser , tab , linkedBrowser , browserContext , opener ) {
336
337
EventEmitter . decorate ( this ) ;
337
338
338
339
this . _targetId = helper . generateId ( ) ;
339
340
this . _registry = registry ;
341
+ this . _window = win ;
340
342
this . _gBrowser = gBrowser ;
341
343
this . _tab = tab ;
342
344
this . _linkedBrowser = linkedBrowser ;
@@ -374,7 +376,7 @@ class PageTarget {
374
376
375
377
async setViewportSize ( viewportSize ) {
376
378
this . _viewportSize = viewportSize ;
377
- const actualSize = setViewportSizeForBrowser ( viewportSize , this . _linkedBrowser ) ;
379
+ const actualSize = setViewportSizeForBrowser ( viewportSize , this . _linkedBrowser , this . _window ) ;
378
380
await this . _channel . connect ( '' ) . send ( 'awaitViewportDimensions' , {
379
381
width : actualSize . width ,
380
382
height : actualSize . height
@@ -690,9 +692,11 @@ async function waitForWindowReady(window) {
690
692
}
691
693
}
692
694
693
- function setViewportSizeForBrowser ( viewportSize , browser ) {
695
+ function setViewportSizeForBrowser ( viewportSize , browser , window ) {
694
696
if ( viewportSize ) {
695
697
const { width, height} = viewportSize ;
698
+ const rect = browser . getBoundingClientRect ( ) ;
699
+ window . resizeBy ( width - rect . width , height - rect . height ) ;
696
700
browser . style . setProperty ( 'min-width' , width + 'px' ) ;
697
701
browser . style . setProperty ( 'min-height' , height + 'px' ) ;
698
702
browser . style . setProperty ( 'max-width' , width + 'px' ) ;
0 commit comments