Safari Extensions

RSS for tag

Enhance and customize the web browsing experience on Mac, iPhone, and iPad with Safari Extensions

Posts under Safari Extensions tag

106 Posts
Sort by:

Post

Replies

Boosts

Views

Activity

Crash in Content Blocker Extension Due to Memory Limit on iOS 17
When using a content rules file prepared for Safari with a size of, for instance, 20MB, we encountered a crash on iOS 17. This is surprising given that just a few versions back Safari has increased the content rules limit to 150k. Now with this issue introduced, even when a content blocker is under the old 50k limit, we may not be able to register it. Technical Details: We use a class that implements the beginRequest(with context: NSExtensionContext) method from the NSExtensionRequestHandling protocol. For this implementation, we utilize NSItemProvider initialized with init(contentOf: URL), where the URL points to path/to/file.json. The crash arises when invoking context.completeRequest(returningItems: [], completionHandler: nil), with context being an instance of NSExtensionContext. Notably, using the same 20MB file and identical code, no such crash was observed on iOS 16.6.1 or iOS 12.5.7. Steps to Reproduce: In the host app, invoke SFContentBlockerManager.reloadContentBlocker(...). Within the beginRequest(with context: NSExtensionContext) method of the class implementing the NSExtensionRequestHandling protocol:Instantiate NSItemProvider(contentOf: <PATH/TO/FILE.json>) using a large-sized rule set (e.g., 20MB or more). Execute context.completeRequest(returningItems: [], completionHandler: nil). Note: The issue is specific to iOS 17. On other versions, no crash is observed. Expected behavior: The content blocker extension should operate without crashing. Actual behavior: The content blocker extension crashes. Also, we have opened another ticket in Feedback Assistant, its ID: FB13282146. UPD: We recently tested on iOS 17.1.1, and the issue still persists.
0
1
430
Nov ’23
Safari runtime.onConnect() not being triggered after DNR redirect
Hi there, I've run into an issue when using runtime ports to communicate between the popup and the background of an extension. Specifically, onConnect (in the background page) is not being triggered when my extension page is displayed subsequently to a Declarative Net Request Redirection. Basically, I have DNR that redirect from 'app.mydomain.com' to my extension with a rule such as : { priority: 1, action: { type: 'redirect', redirect: { regexSubstitution: `safari-web-extension://mknlkpphjfngbollbeipeekihpdomdmd/index.html\\1#/\\2`, }, }, condition: { regexFilter: `^https?://w*\\.?app\\.mydomain\\.com(\\??[^/#]*)[^#]*#?/?(.*)$`, resourceTypes: ['main_frame'], }, }, The redirect works fine, but the onConnect is never triggered in the background page. If I load the page extension directly (without a redirect being done), it works absolutly fine. I see no error or warning. Any idea on why this issue occurs and how I could solve it ? Thanks a lot
0
0
292
Oct ’23
Safari extension for macOS: window.focus()
Hello, I have a macOS app that helps navigation through running apps published on the App Store. I would like to create a Safari extension for macOS that would allow the user to open directly one of the last used tabs. Activate a tab is not a problem following the documentation, but my question is: can I allow the opening of a tab that is not in the frontmost window of the current instance of Safari? Security policies about window.focus() function are restrictive also for code executed directly in the "background" script of the extension? P.S. For example, in a Sandbox application you cannot activate directly a window but just a running application as it was left, so I cannot select the interested Safari's window from the macOS app. Thank you!
2
0
550
Oct ’23
SFSafariContextMenu is not working
Hello, I try to develop extension for safari. I edited info.plist but I can't see my menu items. My Info.plist page <?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"> <plist version="1.0"> <dict> <key>NSExtension</key> <dict> <key>NSExtensionPointIdentifier</key> <string>com.apple.Safari.web-extension</string> <key>NSExtensionPrincipalClass</key> <string>$(PRODUCT_MODULE_NAME).SafariWebExtensionHandler</string> </dict> <key>SFSafariContextMenu</key> <array> <dict> <key>Text</key> <string>Search for selected text in MyApplication.</string> <key>Command</key> <string>Search</string> </dict> <dict> <key>Text</key> <string>Add an entry for selected text in MyApplication.</string> <key>Command</key> <string>Add</string> </dict> </array> <key>SFSafariWebsiteAccess</key> <dict> <key>Level</key> <string>All</string> </dict> </dict> </plist>
1
0
582
Oct ’23
Safari 17 App Extensions (macOS Sonoma) API changes
Hello, In the latest macOS Sonoma and Safari 17 update, Safari App Extensions that were previously running without any issues (for years) suddenly stopped working. Digging a little into the source code and debugger, I found out that basic API calls do not work anymore, for example: SFSafariApplication.getActiveWindow { (window) in ... } or the async version: let window = await SFSafariApplication.activeWindow() getActiveWindow callback is never called and let window = await ... waits forever. Is there anything updated in the security model of Safari 17 that I should be aware of? Or any API updates. I repeat, the extensions worked for 5 years without any issue and also work perfectly in Safari 16 and macOS Ventura. Thank you.
1
0
708
Oct ’23
Extension downloads files as "Unknown.txt"
Hello, I am trying to download a file from the extension's settings page with the following code, but I cannot set the filename no matter what I try. It keeps downloading as Unknown.txt. The same code works well if I do it through a hosted page with an actual URL. let downloadFile = function(contents, filename) { var element = document.createElement('a'); element.setAttribute('href', 'data:application/octet-stream,' + encodeURIComponent(contents)); element.setAttribute('download', filename); element.style.display = 'none'; document.body.appendChild(element); element.click(); document.body.removeChild(element); } downloadFile('test', 'file.txt'); Is this intended or a bug?
0
0
309
Sep ’23
Allow existing customers with license key - Safari WebExtension
Hello, I have a browser extension that is already released for other browsers, and I want to start releasing for Safari as well, and I have a few questions about the payments system. My extension allows users to unlock features by making a payment through Stripe or PayPal and receiving a license key. For Safari I want to use Apple’s IAP system as I already know that this is a requirement but I also want to allow people that already purchased the license through other browsers to use it with Safari. So my question, Am I allowed to allow people bring their license keys purchased from other browsers? Throughout the Safari extension I will only use Apple’s IAP system and offer the same price as on other browsers. So I will not ”reward” people with discounts if they use other payment processors outside of Safari. Thank you!
0
0
346
Sep ’23
Seeking Assistance with Retrieving Request Body in Safari Extension
Hello, I have developed a Safari extension that intercepts browser requests. I'm utilizing the chromeWebRequest API for this purpose. You can find more information about it here: https://developer.chrome.com/docs/extensions/reference/webRequest/ I have successfully retrieved all the headers for the request. However, I am facing an issue when trying to retrieve the request body, particularly when the content-type of the request is multipart/form-data. I would greatly appreciate any assistance with this matter. Thank you.
0
0
298
Sep ’23
unlimitedStorage permission does not work for indexedDB for safari extension
I have a Safari extension needs to store more than 10GB data in indexedDB. I added unlimitedStorage permission to my extension, but there's still a limitation about 1.5GB, after write 1.5GB data in indexedDB, all put operation will failed with 'Failed to PutOrAdd in database because not enough space for domai' At this time, storage.local can still write. I'm not sure why, but Firefox and Chrome both can give unlimited storage for the indexedDB, so, please apply the permission also for indexedDB! It's hard to manage a big data by the raw storage.local API.
3
0
527
Sep ’23
"Allow Permissions" badge for mobile safari extension
I recently saw Carrot Shopping has a Allow Permissions badge next to its mobile safari extension icon in the toolbar for prompting user to allow permissions. I searched everywhere including the official safari extension documentation for turning this feature on for our extension, but I haven't been able to find anything related to this badge. Has anyone have any experience enabling this badge for their mobile safari extension? Would be super helpful if someone can guide me to the right documentation.
3
0
444
Sep ’23
The Info.plist must contain a LSApplicationCategoryType key
I've created a Safari Extension app using the MultiPlanform option. I can successfully distribute the iOS app for beta testing with TestFlight, but when I try to do this with the macOS version, I get the following error: The product archive is invalid. The Info.plist must contain a LSApplicationCategoryType key, whose value is the UTI for a valid category. For more details, see "Submitting your Mac apps to the App Store". For the record, I searched for the mentioned document and couldn't find it. A link would be nice. Regardless, when I look at the macOS (App) in the Navigator Panel, there is no Info.plist file. There is one, however, in iOS (App). When I open Test Flight on my Mac, I see the app, but that's most likely because I have an M1 chip. I can't find any documentation on this, so I'm asking: Do I need to create an Info.plist file for the macOS (App), and if so, what do I need to put in there? If I don't need this, how do I deal with this error? Thanks in advance for any helpful advice.
3
0
3.1k
Sep ’23
Get status of Safari App Extension enabled or disabled in Safari 17 for a particular profile
I can check if my Safari app extension is enabled using the SFSafariExtensionManager getStateOfSafariExtensionWithIdentifier API for default. But in case the user disables the extension for his own profile, I want to know if my safari app extension is enabled in that particular safari profile programatically using API. I'm trying this with Safari 17 on macOS 14 Beta. It's possible? If so, what API can do this for me?
1
0
612
Aug ’23
Do iOS Safari ServiceWorkers get shut down due to thermal state?
Hi! I'm working on an iOS Safari extension that has a ServiceWorker. Lately we've noticed that this ServiceWorker seems to get killed seemingly at random, and there are no logs or crash reports to tell us what happened. I'm hypothesizing that iOS might be shutting down Safari ServiceWorkers when the ProcessInfo.thermalState approaches .serious. I have circumstantial evidence that our ServiceWorker tends to get killed more often at higher levels of thermalState but can't yet say conclusively that this is the case. I can't find any direct evidence of this on internet searches either. Is anyone able to shed light onto this topic? The specific symptoms are: ServiceWorker stops, and the menu entry for its console window no longer appears on macOS Safari. No crash logs via Xcode or Sentry, and no Console messages as far as we could tell (caveat: MobileSafari generates a LOT of messages! We might have missed it.) If attached via debugger, the native part of our extension just disappears and the debugger loses connection with no error message. ServiceWorker no longer works for the lifetime of the Safari process. Sometimes, when we kill Safari and restart, we can get the ServiceWorker back. This usually requires toggling our extension's "enabled" state in system settings. In some cases, even killing/relaunching Safari and toggling the system setting doesn't bring our ServiceWorker back. I'm hypothesizing right now that this happens when the thermal state is high. I've tried simulating a serious/critical thermal state in the Xcode Devices window, but couldn't repro the ServiceWorker problem. I don't know if that setting affects the whole system, though, or just our own apps. Help appreciated! Yuna
7
0
2.5k
Mar ’24
Passwordless single sign on using SFSafariViewController in swift
0 I integrate with safriService (SFSafariViewController) to log in through a single sign-on password, the problem was the first time I log in using SFSafariViewController but the authentication follow not complete the first time so the safari browser still appear & can not direct into my app after authentication follow to become a success, another behavior is when I login again the authentication follow work fine & get the token then directed into my app fine so the main problem is the first time I login SFSafariViewController does not catch the user auth if let url = URL(string: "url") { let safariVC = SFSafariViewController(url: url) safariVC.delegate = self safariVC.dismissButtonStyle = .done present(safariVC, animated: true, completion: nil) } extension DouWebViewVC: SFSafariViewControllerDelegate { func safariViewController(_ controller: SFSafariViewController, didCompleteInitialLoad didLoadSuccessfully: Bool) { if didLoadSuccessfully { print("didLoadSuccessfully") // Do something with the URL here } } //initialLoadDidRedirectTo func safariViewController(_ controller: SFSafariViewController, initialLoadDidRedirectTo requestUrl: URL) { let absoluteUrl = requestUrl.absoluteString print("requestUrl(requestUrl)") } func safariViewControllerDidFinish(_ controller: SFSafariViewController) { print("safariViewControllerDidFinish") } }
0
0
601
Aug ’23
Using file:// scheme to access local files on SafariForWebKitDevelopment
I am currently utilizing local servers to facilitate interactions with local resources. However, I am exploring if there are solutions that would enable direct file access through the file:// protocol. I cannot access the developer tools and feature flags. Specifically, the option "Show features for web developers" seems to be deactivated. This is happening within the ASan WebKit build. I am running this using Tools/Scripts/run-safari. Any insights or potential solutions to these issues would be greatly appreciated.
2
1
597
Jul ’23