| Summary: | REGRESSION (Safari 17.0): browser.tabs.onActivated API doesn't work | ||||||||
|---|---|---|---|---|---|---|---|---|---|
| Product: | WebKit | Reporter: | Frederik Riedel <frederik.riedel> | ||||||
| Component: | WebKit Extensions | Assignee: | Jon Davis <jond> | ||||||
| Status: | RESOLVED CONFIGURATION CHANGED | ||||||||
| Severity: | Normal | CC: | annevk, ap, jond, timothy, webkit-bug-importer | ||||||
| Priority: | P2 | Keywords: | InRadar | ||||||
| Version: | Safari 17 | ||||||||
| Hardware: | Unspecified | ||||||||
| OS: | Unspecified | ||||||||
| Attachments: |
|
||||||||
|
Description
Frederik Riedel
2023-10-15 01:40:07 PDT
Not sure why this was filed as evangelism, moving to a regular component. That said, I don't think that we ever supported the focuschanged event. Could you please add some more details, ideally a test case? Created attachment 468233 [details]
demo project
Hey Alexey!
Thanks for your quick reply and thanks for taking care to assign this to the correct component.
I have just talked to the developer who is working on the browser extension, and we are using the browser.tabs.onActivated API, not onFocusChanged. Sorry for the confusion.
Please find a minimal example attached, it is basically the Xcode boilerplate code for a Safari extension including these lines in the background.js:
browser.tabs.onActivated.addListener(async (info) => {
console.log("this is never called :(");
});
I am not able to reproduce this. I am seeing that event get called whenever I switch tabs. (See attached screenshot.) Created attachment 468265 [details]
Working
The one sec extension does appear to be hitting an exception / promise error responding to the event: [Error] Unhandled Promise Rejection: TypeError: "" cannot be parsed as a URL. r (background.js:1:15494) Since the code is obfuscated, it is not clear where the empty string in coming from here. The extension was granted all access to all websites, so it should have access to the tab's URL. And it does show the URL in the popup of the extension, so I know that is working. I would debug where this is happening to see if you are accessing the right info here. I suspect the fix to URL parsing for compatibility affected this. Looks like URL("") has always thrown an error, it just has a better error message in Safari 17.
So the likely issue now is some tab object is returning an empty string for the URL, when a full URL was expected. We do return an empty string when permission hasn't been granted to the tab, but in this case I granted it to all websites.
The empty URL was from the start page, which will be an empty string. This should be handled by the extension, so the exception does not break the extension. Avoiding empty tabs, I was able to use this extension just fine in Safari 17. Also, if the user has not granted access to the extension for a specific site, it will be an empty string in the tab result too. So you need to account for that in the extension code, so it does not throw an exception and halt further execution. Timothy! Wow! Thanks a lot for your great help + debugging our obfuscated code! What you found was the exact reason why this stopped working. We fixed it now, and the expected result has been restored. Have a nice day :) – Frederik (PS: not sure what the correct status for this "bug" is now, please feel free to update it accordingly) Awesome, happy to help! |