summaryrefslogtreecommitdiffstats
path: root/browser/extensions/report-site-issue/background.js
diff options
context:
space:
mode:
Diffstat (limited to 'browser/extensions/report-site-issue/background.js')
-rw-r--r--browser/extensions/report-site-issue/background.js43
1 files changed, 27 insertions, 16 deletions
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,