What I want to accomplish is:
- The user selects some text in a Web page.
- The user types a key combination.
- The browser action popup is opened at a specific URL, based on the previous key combination.
The manifest is like:
...
"commands": {
"toggle-feature": {
"suggested_key": {
"default": "Ctrl+Shift+U"
},
"description": "Send a 'toggle-feature' event"
}
}
Trying to do:
browser.commands.onCommand.addListener(async (command) => {
if (command == "toggle-feature") {
const { id: tabId } = (await browser.tabs.query({ active: true, currentWindow: true }))[0];
const text = (await browser.tabs.executeScript(tabId, { code: 'getSelection()+""' }))[0];
browser.browserAction.setPopup({ popup: "My URL" + text });
browser.browserAction.openPopup();
}
});
results in:
while:
browser.commands.onCommand.addListener(async (command) => {
if (command == "toggle-feature") {
browser.browserAction.setPopup({ popup: "My URL" });
browser.browserAction.openPopup();
}
});
works and opens the popup at the speficied URL. However, I need to set that page at runtime, since I need the selected text to decide the destination URL. How can I accomplish this?