From 086c044dc34dfc0f74fbe41f4ecb402b2cd34884 Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Fri, 19 Apr 2024 03:13:33 +0200 Subject: Merging upstream version 125.0.1. Signed-off-by: Daniel Baumann --- browser/extensions/report-site-issue/background.js | 43 ++++++++++++++-------- 1 file changed, 27 insertions(+), 16 deletions(-) (limited to 'browser/extensions/report-site-issue/background.js') diff --git a/browser/extensions/report-site-issue/background.js b/browser/extensions/report-site-issue/background.js index d495f33c25..8c8234e52f 100644 --- a/browser/extensions/report-site-issue/background.js +++ b/browser/extensions/report-site-issue/background.js @@ -18,24 +18,34 @@ const androidReporterConfig = { utm_source: "android-components-reporter", }; -let reporterConfig = desktopReporterConfig; +const getReporterConfig = (() => { + let promise; + return async () => { + promise ??= new Promise(resolve => { + browser.permissions + .contains({ permissions: ["nativeMessaging"] }) + .then(needProductName => { + if (needProductName) { + const port = browser.runtime.connectNative( + "mozacWebcompatReporter" + ); + port.onMessage.addListener(message => { + if ("productName" in message) { + androidReporterConfig.productName = message.productName; + resolve(androidReporterConfig); -(async () => { - const permissions = ["nativeMessaging"]; - if (await browser.permissions.contains({ permissions })) { - reporterConfig = androidReporterConfig; - - const port = browser.runtime.connectNative("mozacWebcompatReporter"); - port.onMessage.addListener(message => { - if ("productName" in message) { - reporterConfig.productName = message.productName; - - // For now, setting the productName is the only use for this port, and that's only happening - // once after startup, so let's disconnect the port when we're done. - port.disconnect(); - } + // For now, setting the productName is the only use for this port, and that's only happening + // once after startup, so let's disconnect the port when we're done. + port.disconnect(); + } + }); + } else { + resolve(desktopReporterConfig); + } + }); }); - } + return promise; + }; })(); async function loadTab(url) { @@ -60,6 +70,7 @@ async function captureAndSendReport(tab) { try { const { endpointUrl, webcompatInfo } = await browser.tabExtras.getWebcompatInfo(id); + const reporterConfig = await getReporterConfig(); const dataToSend = { endpointUrl, reportUrl: url, -- cgit v1.2.3