WebKit Bugzilla
New
Browse
Log In
×
Sign in with GitHub
or
Remember my login
Create Account
·
Forgot Password
Forgotten password account recovery
RESOLVED CONFIGURATION CHANGED
263170
REGRESSION (Safari 17.0): browser.tabs.onActivated API doesn't work
https://bugs.webkit.org/show_bug.cgi?id=263170
Summary
REGRESSION (Safari 17.0): browser.tabs.onActivated API doesn't work
Frederik Riedel
Reported
2023-10-15 01:40:07 PDT
Hey Safari + WebKit Team! This is about the macOS Safari Extension of my app one sec (
https://one-sec.app/mac/
): The goal of my app is to interrupt any unintentional attempts to navigate to distracting websites (e.g. open mastodon.social while waiting for WebKit to compile 🙃). When a target website is opened, a breathing exercise is shown instead (after which the user can decide if they really want to open that website). With Safari 17.0, one minor feature of my extension broke: I rely on the onFocusChanged API to detect if the user switches to a different window or app on their computer (to avoid having to wait for the intervention to complete) and then come back 10s later when the breathing animation is finished and the website is unlocked. However, on Safari 17.0, I noticed that this API does not work anymore. Have there been any changes to this? Or is this a known issue? Any workarounds? Thanks a lot and have a nice day! – Frederik
Attachments
demo project
(706.01 KB, application/zip)
2023-10-16 10:10 PDT
,
Frederik Riedel
no flags
Details
Working
(81.81 KB, image/png)
2023-10-18 14:42 PDT
,
Timothy Hatcher
no flags
Details
View All
Add attachment
proposed patch, testcase, etc.
Radar WebKit Bug Importer
Comment 1
2023-10-15 01:40:16 PDT
<
rdar://problem/116975467
>
Alexey Proskuryakov
Comment 2
2023-10-16 09:04:47 PDT
Not sure why this was filed as evangelism, moving to a regular component.
Alexey Proskuryakov
Comment 3
2023-10-16 09:08:40 PDT
That said, I don't think that we ever supported the focuschanged event. Could you please add some more details, ideally a test case?
Frederik Riedel
Comment 4
2023-10-16 10:10:47 PDT
Created
attachment 468233
[details]
demo project
Frederik Riedel
Comment 5
2023-10-16 10:11:37 PDT
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 :("); });
Timothy Hatcher
Comment 6
2023-10-18 14:42:11 PDT
I am not able to reproduce this. I am seeing that event get called whenever I switch tabs. (See attached screenshot.)
Timothy Hatcher
Comment 7
2023-10-18 14:42:33 PDT
Created
attachment 468265
[details]
Working
Timothy Hatcher
Comment 8
2023-10-18 15:03:34 PDT
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.
Timothy Hatcher
Comment 9
2023-10-18 15:50:45 PDT
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.
Timothy Hatcher
Comment 10
2023-10-18 18:38:48 PDT
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.
Timothy Hatcher
Comment 11
2023-10-18 18:41:53 PDT
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.
Frederik Riedel
Comment 12
2023-10-19 03:11:00 PDT
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)
Timothy Hatcher
Comment 13
2023-10-19 09:22:09 PDT
Awesome, happy to help!
Note
You need to
log in
before you can comment on or make changes to this bug.
Top of Page
Format For Printing
XML
Clone This Bug