@@ -334,7 +334,7 @@ export function createDevtoolsPopup(options: { src?: string; hotkey?: string | f
334334 popoutBtn . textContent = '⧉' ;
335335 popoutBtn . title = 'Open in its own window' ;
336336 popoutBtn . setAttribute ( 'aria-label' , 'Open Pangular Inspector in its own window' ) ;
337- popoutBtn . addEventListener ( 'click' , ( ) => void popOut ( ) ) ;
337+ popoutBtn . addEventListener ( 'click' , ( ) => void popOut ( true ) ) ;
338338
339339 const closeBtn = document . createElement ( 'button' ) ;
340340 closeBtn . type = 'button' ;
@@ -994,22 +994,42 @@ export function createDevtoolsPopup(options: { src?: string; hotkey?: string | f
994994 * closes it here. The launcher, the shortcut or the panel's **Back into the
995995 * page** command bring it back.
996996 */
997- async function popOut ( ) {
997+ async function popOut ( fromToolbar = false ) {
998998 notice . textContent = '' ;
999- // The frame's address is known once the panel loaded, which keeps the
1000- // call inside the click, as a pop-up blocker wants.
1001- const src = iframe . src && ! iframe . hidden ? iframe . src : await resolveTarget ( ) ;
999+ const known = iframe . src && ! iframe . hidden ? iframe . src : undefined ;
1000+ const width = Math . min ( 1200 , Math . max ( 480 , Math . round ( window . outerWidth * 0.6 ) || 960 ) ) ;
1001+ const height = Math . min ( 900 , Math . max ( 360 , Math . round ( window . outerHeight * 0.8 ) || 720 ) ) ;
1002+ const features = `popup,width=${ width } ,height=${ height } ` ;
1003+ const closeQuietly = ( w : Window | null ) => {
1004+ try {
1005+ if ( w && ! w . closed ) w . close ( ) ;
1006+ } catch {
1007+ // the window is already gone
1008+ }
1009+ } ;
1010+ let win : Window | null = null ;
1011+ // A pop-up blocker only allows window.open inside the click, so a toolbar
1012+ // click that still has to look up the panel's address opens a blank window
1013+ // first and points it at the panel once the address is known.
1014+ if ( fromToolbar && ! known ) {
1015+ try {
1016+ win = window . open ( 'about:blank' , popoutName ( ) , features ) ;
1017+ } catch {
1018+ win = null ;
1019+ }
1020+ }
1021+ const src = known ?? ( await resolveTarget ( ) ) ;
10021022 if ( src === null ) {
1023+ closeQuietly ( win ) ;
10031024 notice . textContent = 'No devtools server found, so there is nothing to open.' ;
10041025 return ;
10051026 }
1006- const width = Math . min ( 1200 , Math . max ( 480 , Math . round ( window . outerWidth * 0.6 ) || 960 ) ) ;
1007- const height = Math . min ( 900 , Math . max ( 360 , Math . round ( window . outerHeight * 0.8 ) || 720 ) ) ;
10081027 const url = popoutUrl ( src ) ;
1009- let win : Window | null = null ;
10101028 try {
1011- win = window . open ( url , popoutName ( ) , `popup,width=${ width } ,height=${ height } ` ) ;
1029+ if ( win ) win . location . href = url ;
1030+ else win = window . open ( url , popoutName ( ) , features ) ;
10121031 } catch {
1032+ closeQuietly ( win ) ;
10131033 win = null ;
10141034 }
10151035 if ( ! win ) {
0 commit comments