I think I found a workaround myself...still testing though. It appears if you get the currently active tab when then tab id is 0, you can get the REAL tab id. Example:
private getRealTabId(tabId: number): Promise<number> {
	return browser.tabs.get(tabId) // tabId=0 here
		.then((tab: Tab) => {
			if (!tab) {
				console.debug(`Could not find tabId=${tabId}. Looking for active tab.`);
				return browser.tabs.query({active: true, currentWindow: true})
					.then((tabs: Tab[]) => {
						if (tabs.length) {
							const tab = tabs[0];
							console.debug(`Found active tab for tabId=${tabId} with tabId=${tab.id}`);
							return tab.id; // this tab id is non-zero! yay!
						}
						throw new Error("Tab not found");
					})
			}
			return tabId;
		});
}
This would not be a perfect solution, though, since a user could be quickly switching tabs and thus resulting in a new active tab, but it may be "good enough" for now.
Topic:
Safari & Web
SubTopic:
General
Tags: