From c8762945d9cfcc18aeb8cbdfe6e88d765f74be53 Mon Sep 17 00:00:00 2001 From: Raymond Hill Date: Wed, 13 Mar 2024 10:01:33 -0400 Subject: [PATCH] Fix failure to create popup logger window sometimes Related issue: https://github.com/uBlockOrigin/uBlock-issues/issues/2249 --- platform/common/vapi-background.js | 26 +++++++++++++++----------- 1 file changed, 15 insertions(+), 11 deletions(-) diff --git a/platform/common/vapi-background.js b/platform/common/vapi-background.js index 85acc9a05..2ff99ac12 100644 --- a/platform/common/vapi-background.js +++ b/platform/common/vapi-background.js @@ -433,22 +433,26 @@ vAPI.Tabs = class { // For some reasons, some platforms do not honor the left,top // position when specified. I found that further calling // windows.update again with the same position _may_ help. + // + // https://github.com/uBlockOrigin/uBlock-issues/issues/2249 + // Mind that the creation of the popup window might fail. if ( details.popup !== undefined && vAPI.windows instanceof Object ) { - const createDetails = { + const basicDetails = { url: details.url, type: details.popup, }; - if ( details.box instanceof Object ) { - Object.assign(createDetails, details.box); + const shouldRestorePosition = details.box instanceof Object; + const extraDetails = shouldRestorePosition + ? Object.assign({}, basicDetails, details.box) + : basicDetails; + const win = await vAPI.windows.create(extraDetails); + if ( win === null ) { + if ( shouldRestorePosition === false ) { return; } + return vAPI.windows.create(basicDetails); } - const win = await vAPI.windows.create(createDetails); - if ( win === null ) { return; } - if ( details.box instanceof Object === false ) { return; } - if ( - win.left === details.box.left && - win.top === details.box.top - ) { - return; + if ( shouldRestorePosition === false ) { return; } + if ( win.left === details.box.left ) { + if ( win.top === details.box.top ) { return; } } vAPI.windows.update(win.id, { left: details.box.left,