1) Build and run the attached sample Xcode project SonomaBug
2) Open Safari
3) Allow unsigned extensions
4) Enable SonomaBug in Safari Extensions Settings
5) Click the SonomaBug toolbar button in a Safari window
6) Click the Open Page button
The problem is that the completion handler for -[SFSafariApplication getActiveWindowWithCompletionHandler:] never gets called. In the Console log I see this:
SonomaBug Extension FOOBAR url: https://apple.com/
SonomaBug Extension No current extension context; trying most recent context
SonomaBug Extension No most recent extension context
SonomaBug Extension No extension context for best match
SonomaBug Extension No extension context for remote object
This bug only occurs on Sonoma. The bug doesn't occur on Ventura and earlier. It appears to be a memory management issue. The workaround is to keep a strong reference to the SFSafariWindow object. In the sample project SafariExtensionHandler.m file, uncomment the lines after "Uncomment to fix memory management bug on Sonoma." Then the button works, and I see this in the Console log:
SonomaBug Extension FOOBAR url: https://apple.com/
SonomaBug Extension No current extension context; trying most recent context
SonomaBug Extension FOOBAR activeWindow: <SFSafariWindow: 0x117a06370>
macOS 14.0 (23A344) on Mac mini M1, 2020
1) Build and run the attached sample Xcode project SonomaBug 2) Open Safari 3) Allow unsigned extensions 4) Enable SonomaBug in Safari Extensions Settings 5) Click the SonomaBug toolbar button in a Safari window 6) Click the Open Page button
Expected results: https://apple.com/ opens in a Safari tab
Actual results: Nothing happens
The problem is that the completion handler for -[SFSafariApplication getActiveWindowWithCompletionHandler:] never gets called. In the Console log I see this:
This bug only occurs on Sonoma. The bug doesn't occur on Ventura and earlier. It appears to be a memory management issue. The workaround is to keep a strong reference to the SFSafariWindow object. In the sample project SafariExtensionHandler.m file, uncomment the lines after "Uncomment to fix memory management bug on Sonoma." Then the button works, and I see this in the Console log:
SonomaBug.zip