From fd59d6a4ddbb019bae9ba1850dd541f77a34e172 Mon Sep 17 00:00:00 2001 From: Edgar Chen Date: Fri, 14 Mar 2025 19:55:01 +0000 Subject: [PATCH] Bug 1952343 - [about:memory] Wait for document to regain focus before reopening the file picker; r=mccr8 Differential Revision: https://phabricator.services.mozilla.com/D241441 --- .../aboutmemory/content/aboutMemory.js | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/toolkit/components/aboutmemory/content/aboutMemory.js b/toolkit/components/aboutmemory/content/aboutMemory.js index 46a4990a5224..883a85e30361 100644 --- a/toolkit/components/aboutmemory/content/aboutMemory.js +++ b/toolkit/components/aboutmemory/content/aboutMemory.js @@ -327,13 +327,24 @@ window.onload = function () { // onchange handler to be re-called without having to go via the file // picker. if (!aElem.skipClick) { + // Attempts to reopen the picker immediately might fail because the + // focus may not have switched back on some platform, so explicitly + // wait for focus here. + if (!this.ownerDocument.hasFocus()) { + let input = this; + this.ownerDocument.addEventListener("focus", (e) => { + input.click(); + }, { once: true }); + return; + } this.click(); } - } else { - let filename1 = this.filename1; - delete this.filename1; - updateAboutMemoryFromTwoFiles(filename1, file.mozFullPath); + return; } + + let filename1 = this.filename1; + delete this.filename1; + updateAboutMemoryFromTwoFiles(filename1, file.mozFullPath); } );