Post

Replies

Boosts

Views

Activity

Reply to Safari Web Extension tab ids are 0 during webNavigation callbacks until onCompleted event
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> { &#9;return browser.tabs.get(tabId) // tabId=0 here &#9;&#9;.then((tab: Tab) => { &#9;&#9;&#9;if (!tab) { &#9;&#9;&#9;&#9;console.debug(`Could not find tabId=${tabId}. Looking for active tab.`); &#9;&#9;&#9;&#9;return browser.tabs.query({active: true, currentWindow: true}) &#9;&#9;&#9;&#9;&#9;.then((tabs: Tab[]) => { &#9;&#9;&#9;&#9;&#9;&#9;if (tabs.length) { &#9;&#9;&#9;&#9;&#9;&#9;&#9;const tab = tabs[0]; &#9;&#9;&#9;&#9;&#9;&#9;&#9;console.debug(`Found active tab for tabId=${tabId} with tabId=${tab.id}`); &#9;&#9;&#9;&#9;&#9;&#9;&#9;return tab.id; // this tab id is non-zero! yay! &#9;&#9;&#9;&#9;&#9;&#9;} &#9;&#9;&#9;&#9;&#9;&#9;throw new Error("Tab not found"); &#9;&#9;&#9;&#9;&#9;}) &#9;&#9;&#9;} &#9;&#9;&#9;return tabId; &#9;&#9;}); } 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.
Nov ’20
Reply to Safari Web Extension: How do we programmatically close the toolbar icon popup window?
@bweinsten Could you provide the code to your test extension? I will make a barebones extension to test myself, but it could expedite things if I could see yours working. To be clear though, this is the popover that appears when the user clicks the icon in the toolbar, not a window that is opened using window.open(). @vkyrychenko87 No luck. Seems Safari is the only browser conforming to the MDN docs, OR the other browsers use a script behind the scenes to open the window and Safari does not. Either way, Safari is the outlier. In addition to my X button, though, I also have the need the programatically close the popover when the user clicks a link in it to navigate on the current tab. In instances where a new tab is opened, the popover goes away automatically, but if a link opens in the current tab, the popover just hangs around, obscuring the view. So my close method has two use cases: 1) Manually click the X button to close, and 2) Automatically close when a link is clicked in the popover. There has to be a way to do this, even if it's delegating to the native swift handler. Real head scratcher that it's non-obvious.
Jun ’21
Reply to Safari extension vs. Safari web extension permissions
I would like to understand the reasoning here as well. It seems like a Safari App Extension gets default access to whatever pages the user visits, whereas a Safari Web Extension has to ask for specific web page permissions. I can understand the latter from a privacy/security perspective, but it doesn't make much sense for the former because an App Extension has free rein. Why is an App Extension treated differently from a Web Extension in this case? For example, 1password's App Extension has access to all sites without an explicit opt-in: ...but Okta's Web Extension does not: Both have very similar functionality, that of suggesting form-fills for logins on any web site, but because Okta is a Web Extension, it gets treated differently. Why is that? It seems like both App Extensions and Web Extensions should require the same opt-ins or not. Otherwise, it's on the developer to opt for a native App Extension over a Web Extension for the better UX.
May ’22
Reply to runtime.oninstalled not working on reinstalling safari web extension
Reviving this thread because I am still seeing this issue with Web Extensions. It would appear that until you "Always allow on every website" the extension simply doesn't run (even in the background) in order to receive the onInstalled event. Furthermore, even after setting the proper web site permissions and toggling the extension off and then on, it does not 100% of the time fire the onInstalled event. In my case, we want to show a tab with a welcome page for quickly onboarding after installing the extension. Specifically, we want to describe Safari's opt-in site permissions and how to make our extension work with those settings, but we are in a catch 22 because we can't even show that page until the user opts in to site permissions.
May ’22