Sometimes the error reporting in Firefox really sucks. Try it with a try ... catch
:
code with logging and catch
browser.commands.onCommand.addListener(async command => { try { switch (command) {
case '1 Host Connect': {
const { id: windowId, } = (await browser.windows.getLastFocused());
console.log(`windowId`, windowId);
const { id: tabId, } = (await (browser.tabs.query({ active: true, windowId, })))[0];
console.log(`tabId`, tabId);
const pageSelection = (await Promise.all(
(await browser.webNavigation.getAllFrames({ tabId, }))
.map(async ({ frameId, }) => { try {
console.log(`Checking frame ${frameId} in tab ${tabId} ...`);
const selected = (await browser.tabs.executeScript(tabId, { frameId, code: `window.getSelection().toString()`, }));
console.log(`Selection in frame ${frameId} in tab ${tabId}:`, selection);
return selection;
} catch (_) { console.error(_); return ''; } }) // in production, avoid weird errors about uninitialized frames and stuff like that, but when debugging empty selection texts again, comment this line
)).reduce((a, b) => a || b, '') || '';
console.info(`Selection in some frame in the currently active tab ${tabId}`: pageSelection);
// use `pageSelection`
} break;
// other commands
} catch (error) { console.error(`onCommand error`, error); } });