The error message isn’t that helpful. You have to putthe code in an async
function:
browser.commands.onCommand.addListener(async command => { switch (command) {
case '1 Host Connect': {
const { id: windowId, } = (await browser.windows.getLastFocused());
const { id: tabId, } = (await (browser.tabs.query({ active: true, windowId, })))[0];
const pageSelection = (await Promise.all(
(await browser.webNavigation.getAllFrames({ tabId, }))
.map(({ frameId, }) =>
browser.tabs.executeScript(tabId, { frameId, code: `window.getSelection().toString()`, })
.catch(_ => '') // 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, '') || '';
// use `pageSelection`
} break;
// other commands
} });
Again, net tested, but it is syntactically correct and should work.