Bug 1881803 - convert Report Site Issue extension to event pages; r=robwu,webcompat-reviewers,ksenia

Differential Revision: https://phabricator.services.mozilla.com/D202602
This commit is contained in:
Thomas Wisniewski 2024-03-04 15:15:01 +00:00
Родитель c722636351
Коммит dd33e85ad8
2 изменённых файлов: 30 добавлений и 17 удалений

Просмотреть файл

@ -18,24 +18,34 @@ const androidReporterConfig = {
utm_source: "android-components-reporter", 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 () => { // For now, setting the productName is the only use for this port, and that's only happening
const permissions = ["nativeMessaging"]; // once after startup, so let's disconnect the port when we're done.
if (await browser.permissions.contains({ permissions })) { port.disconnect();
reporterConfig = androidReporterConfig; }
});
const port = browser.runtime.connectNative("mozacWebcompatReporter"); } else {
port.onMessage.addListener(message => { resolve(desktopReporterConfig);
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();
}
}); });
} return promise;
};
})(); })();
async function loadTab(url) { async function loadTab(url) {
@ -60,6 +70,7 @@ async function captureAndSendReport(tab) {
try { try {
const { endpointUrl, webcompatInfo } = const { endpointUrl, webcompatInfo } =
await browser.tabExtras.getWebcompatInfo(id); await browser.tabExtras.getWebcompatInfo(id);
const reporterConfig = await getReporterConfig();
const dataToSend = { const dataToSend = {
endpointUrl, endpointUrl,
reportUrl: url, reportUrl: url,

Просмотреть файл

@ -3,7 +3,7 @@
"name": "WebCompat Reporter", "name": "WebCompat Reporter",
"description": "Report site compatibility issues on webcompat.com", "description": "Report site compatibility issues on webcompat.com",
"author": "Thomas Wisniewski <twisniewski@mozilla.com>", "author": "Thomas Wisniewski <twisniewski@mozilla.com>",
"version": "2.0.0", "version": "2.1.0",
"homepage_url": "https://github.com/mozilla/webcompat-reporter", "homepage_url": "https://github.com/mozilla/webcompat-reporter",
"browser_specific_settings": { "browser_specific_settings": {
"gecko": { "gecko": {
@ -37,6 +37,8 @@
}, },
"permissions": ["tabs", "<all_urls>"], "permissions": ["tabs", "<all_urls>"],
"background": { "background": {
"persistent": false,
"type": "module",
"scripts": ["background.js"] "scripts": ["background.js"]
} }
} }