I use TreeStyleTab and I want to use the keyboard to scroll the TST sidebar. The message to do that requires the number of the window which is usually 1. When you open more windows how do you determine the window number of the current window?
Currently when I am in a different window and press the shortcut it is the sidebar of the first window that scrolls
All of these returns a Promise that you need to await or chain with .then callback.
Also, Tab object contains also windowId, so no need to use browser.windows.getCurrent.
Can you show me how to use the browser.tabs.query({active: true, lastFocusedWindow: true}).then(([tab]) => tab) code within the context of the mapkey invocation?
When I try it I get a syntax error message along the lines of needing to use an await within an async funtion.
Yes, you need to use either await keyword or .then callback function.
If you are using await, then mark whole function as async - so instead of function write async function.
So for example:
async function() {
const {windowId, id: tabId} = await browser.tabs.query({active: true, lastFocusedWindow: true}).then(([tab]) => tab);
// now you can use windowId and tabId
}
If you want to use .then, then use this:
browser.tabs.query({active: true, lastFocusedWindow: true})
.then(([tab]) => tab)
.then(({windowId, id: tabId}) => {
// now you can use windowId and tabId
});
Also as you can see, I’m using here destructuring assignment:
(but feel free to use tab.id and tab.windowId instead )
EDIT:
So your code should look something like this: