Meet Safari Web Extensions on iOS

RSS for tag

Discuss the WWDC21 session Meet Safari Web Extensions on iOS.

Posts under wwdc21-10104 tag

38 Posts

Post

Replies

Boosts

Views

Activity

Opening native app from a web extension
Is it possible to open the native app from a web extension? I have tried creating a new tab that uses the app's URL scheme but the UI asking the user to open the app is not shown until the new page UI is dismissed. Creating a tab with an HTTPS URL that the app is setup to handle does not work and always the link in a new tab. I tried sending a message to the app extension and using NSExtensionContext.open(_:completionHandler:) but the URL is not opened and the closure received false, indicating it was not handled. Having the option to link back to the native app would be very useful.
3
0
1.9k
Mar ’25
Programmatically open popup in Safari Web Extension
I have a Safari web extension that needs the ability to open the popup when the user interacts with a modal coming from the content script. There is a native message handler that comes with the safari web extension when you first create it: import SafariServices import os.log class SafariWebExtensionHandler: NSObject, NSExtensionRequestHandling { func beginRequest(with context: NSExtensionContext) { let item = context.inputItems[0] as! NSExtensionItem let message = item.userInfo?[SFExtensionMessageKey] os_log(.default, "Received message from browser.runtime.sendNativeMessage: %@", message as! CVarArg) let response = NSExtensionItem() response.userInfo = [ SFExtensionMessageKey: [ "Response to": message ] ] print("hit") context.completeRequest(returningItems: [response], completionHandler: nil) } } I have the permissions to send a native message, I've seen some examples online where you can access the SFSafariApplication module from SafariServices and open the popover. But I can't seem to access SFSafariApplication in this module.
1
0
1.7k
May ’24
Open Maps app from Safari extension
With a Safari extension I add a link to certain websites to open the Maps app with coordinates found on the website. In the content script I detect clicks on my added link and forward the message to the background script with browser.runtime.sendMessage({ coordinates: "some coordinates I found on the website" }). The background script receives this message in its listener function and forwards the message to the extension handler like so browser.runtime.onMessage.addListener((request, sender, sendResponse) => { browser.runtime.sendNativeMessage( { message: request.coordinates }, function(response) { }); } The extension handler receives the message in its func beginRequest(with context: NSExtensionContext) function as expected. In this function I convert the coordinates I receive to a valid CLLocationCoordinate2D object. However, if I want to use the following code inside the beginRequest function to open the Maps app, it does not work on iOS. The same code works fine with a macOS Safari extension. MKMapItem(placemark: MKPlacemark(coordinate: CLLocationCoordinate2D(latitude: 50.1234, longitude: 8.1234))).openInMaps()
1
0
1.2k
Apr ’22
safari-web-extension-converter not setting icons
I just converted a chrome extension with XCode command line xcrun /Applications/Xcode-beta.app/Contents/Developer/usr/bin/safari-web-extension-converter /Users/macminitwo/Downloads/new-tab-background which had no icon in manifest, after conversion there was build error error: Build input file cannot be found: '/Users/macminitwo/camo theme/Shared (App)/Resources/Icon.png' (in target 'camo theme (iOS)' from project 'camo theme') Then I updated manifest.json of main project and added icon to the project "icons": { "16": "icon16.png", "48": "icon48.png", "128": "icon128.png" } tried converting again, and it still gave same error. Now, I have to manually put the icon in "resources" folder. Note: every time on conversion, it said abort trap 6 What should I do to not get this error? And have icon there already. System Info: macOS: 11.4 Big Sur XCode: 13.0 beta 3
1
0
1.5k
Mar ’22
Infinite loop in "browser.i18n.getMessage" API
I was tracking down an infinite loop and it's caused by calling: browser.i18n.getMessage('faq_4a', ['$13.99']) Where the "faq_4a" is defined as: "faq_4a": { "message": "Highlight all prices like $1" }, The problem is the parameter ['$13.99'], if I use this parameter for any message that accepts a placeholder, it will just froze the console or whatever executed it. Can someone please try to run this code to verify? I need to know if this is a Safari issue or if just my Safari broken. I use Safari 15.3 (17612.4.9.1.8). Thank you!
2
0
1.3k
Mar ’22
Safari Web extension allow access all websites permissions - need clarification
I learned there are two types of safari extensions . Web extensions and app extensions . We are currently developing a safari web extension . The extension requires access on all web sites by default (without user granting permissions) . But there is no provision for same in web extension . However the same can be achieved in app extension by including safari website access  in info.plist . Please clarify why there is no provision to achieve the same in web extension . However same is provided in app extension .
1
0
1.7k
Mar ’22
What is the configurations of macOS for manifest v3 on safari?
Safari version : 15.3 Os version : 12.2.1 This is after latest updates and manifest v3 is not supported. So i need to downgrade manifest version to 2. What can be the solution to run manifest v3 with current mac and safari version? Also, My safari is not getting updated after updating os, Im using intel processor. What can be done to update safari version to 15.4?
1
0
1.3k
Mar ’22
Safari Web Extension does not load content script on iOS 15
The content scripts specified in the manifest of an extension should be loaded each time a user visits a web page. However, in the iOS 15 simulator, the content script is only loaded the first time that the extension is enabled -- either when you grant permission for the site, or if you turn the extension off and back on while on a site. Otherwise, the content script is not injected. This is clearly a bug, right? Is there a known workaround or a fix in the works?
4
0
3.6k
Mar ’22
Spawning a service worker in a safari web extension in the background
new Worker(browser.runtime.getURL('source/worker.js')) throws an error: Error: This script should only be loaded in a browser extension. I have a hefty background processing operation that I need to pass off to a web worker, but the script I try to execute causes this error. Is there a standard way of spawning a web worker in a background script for a safari web extension?
0
0
1k
Feb ’22
How to get URL of active tab from popup.js with Safari iOS App Extension in iOS 15?
I'm developing Safari App Extension for iOS 15.0+ and I need to get URL of active tab in popup.js and display. Here is how I do that in popup.js: document.getElementById("activetaburl").innerHTML = document.URL As result it returns path of current popup.js Here is my permissions from manifest.json: "permissions": ["nativeMessaging", "activeTab"] And info.plist: <dict> <key>NSExtension</key> <dict> <key>NSExtensionAttributes</key> <dict> <key>NSExtensionActivationRule</key> <dict> <key>NSExtensionActivationSupportsWebURLWithMaxCount</key> <integer>1</integer> <key>NSExtensionActivationSupportsImageWithMaxCount</key> <integer>10</integer> </dict> </dict> <key>NSExtensionPointIdentifier</key> <string>com.apple.Safari.web-extension</string> <key>NSExtensionPrincipalClass</key> <string>$(PRODUCT_MODULE_NAME).SafariWebExtensionHandler</string> </dict> </dict> So how to fix the issue above and get url of active tab? Thanks, Serge
2
0
2.8k
Jan ’22
How to use store data in content.js file.
I have implement reset text function in content.js file with static array. I need to manage this array with dynamic. I have pass data app to extension with FileManager. I have get store data in extension safariwebextension.swift. file. How can use this array in content.js file. Need to replace store data in content.js file. Your provided demo only supported mac version feature.
1
0
973
Jan ’22
How to resolve warnings if using safari-web-extension-converter?
Command Used: xcrun safari-web-extension-converter package-content.safariextension  --project-location SafariExtension  While running the above command, I am getting below warnings. How to resolve these for Safari for iOS 15? Warnings: The following keys in your manifest.json are not supported by your current version of Safari. If these are critical to your extension, you should review your code to see if you need to make changes to support Safari:         manifest_version         icons         persistent         version         js         content_security_policy         matches         description         <all_urls>         tabs         cookies         activeTab         scripts         storage         applications         browser_action         web_accessible_resources         name         run_at
3
0
2.4k
Jan ’22
Safari Extensions and FaceID/Keychain access
My Safari Extension on iOS needs access to a Keychain item (password) that is secured by the userPresence and devicePasscode flag. In other words, FaceID/TouchID or the device PIN is necessary to access the password. Is there a way for the extension to access the password? SafariWebExtensionHandler.swift has access to the Keychain, but can't present FaceID/TouchID/device PIN interface to the user. Popup.js has UI access, but can't access the iOS Keychain. One hack is to set touchIDAuthenticationAllowableReuseDuration of the Keychain item to an arbitrary time and have the user authenticate in the containing app. However, in case of a time-out, the containing app has be opened by the extension with a custom URL scheme. openURL is not accessible in SafariWebExtensionHandler.swift either (I assume it can be handled by popup.js). This is a user-unfriendly solution. What is the best way to give the Safari extension access to a Keychain item?
0
0
1.3k
Dec ’21
iOS Safari web extension works only in simulator
Hi there, my iOS web extension for Safari, written in Xcode works fine in simulator but on a physical device the extension doesn't show in the extension area on phone. When launched, the app spashscreen comes up, but the extension is not show in the extension are of the browser. Same on IPhone 13 simulator works without any prob. What can I do?
2
0
898
Dec ’21
Safari not working good
I have a problem with safari, the problem started on my iPhone 7 that some of experimental webkit features was changed so that many things stopped of working on safari and I bought new iPhone pro 13 and moved the data from the old device to the new and discovered the the problem became on my two devices now.
0
0
529
Nov ’21
Screenshot of non-active tab
Hello, Is it possible to take a screenshot of a non-active tab? Firefox supports this via captureTab (https://developer.mozilla.org/en-US/docs/Mozilla/Add-ons/WebExtensions/API/tabs/captureTab) With Safari App extensions that was possible via getScreenshotOfVisibleArea which doesn't seem to work with Safari extensions.
0
0
725
Oct ’21
Haptic Feedback in Safari Web Extension
Hi! We're currently building a web extension with iOS as a primary target. Since haptics on iOS are really nice, we wanted to make use of it to give the experience a special feel on iPhone. However, haptics don't seem to work when called from SafariWebExtensionHandler... maybe because the messaging layer between the web extension and the native code is in the background (is it?), and haptics don't work in apps that are in the background. Anyway, is there any way we can make haptics work regardless?
2
0
2.4k
Oct ’21
Opening native app from a web extension
Is it possible to open the native app from a web extension? I have tried creating a new tab that uses the app's URL scheme but the UI asking the user to open the app is not shown until the new page UI is dismissed. Creating a tab with an HTTPS URL that the app is setup to handle does not work and always the link in a new tab. I tried sending a message to the app extension and using NSExtensionContext.open(_:completionHandler:) but the URL is not opened and the closure received false, indicating it was not handled. Having the option to link back to the native app would be very useful.
Replies
3
Boosts
0
Views
1.9k
Activity
Mar ’25
Programmatically open popup in Safari Web Extension
I have a Safari web extension that needs the ability to open the popup when the user interacts with a modal coming from the content script. There is a native message handler that comes with the safari web extension when you first create it: import SafariServices import os.log class SafariWebExtensionHandler: NSObject, NSExtensionRequestHandling { func beginRequest(with context: NSExtensionContext) { let item = context.inputItems[0] as! NSExtensionItem let message = item.userInfo?[SFExtensionMessageKey] os_log(.default, "Received message from browser.runtime.sendNativeMessage: %@", message as! CVarArg) let response = NSExtensionItem() response.userInfo = [ SFExtensionMessageKey: [ "Response to": message ] ] print("hit") context.completeRequest(returningItems: [response], completionHandler: nil) } } I have the permissions to send a native message, I've seen some examples online where you can access the SFSafariApplication module from SafariServices and open the popover. But I can't seem to access SFSafariApplication in this module.
Replies
1
Boosts
0
Views
1.7k
Activity
May ’24
Open Maps app from Safari extension
With a Safari extension I add a link to certain websites to open the Maps app with coordinates found on the website. In the content script I detect clicks on my added link and forward the message to the background script with browser.runtime.sendMessage({ coordinates: "some coordinates I found on the website" }). The background script receives this message in its listener function and forwards the message to the extension handler like so browser.runtime.onMessage.addListener((request, sender, sendResponse) => { browser.runtime.sendNativeMessage( { message: request.coordinates }, function(response) { }); } The extension handler receives the message in its func beginRequest(with context: NSExtensionContext) function as expected. In this function I convert the coordinates I receive to a valid CLLocationCoordinate2D object. However, if I want to use the following code inside the beginRequest function to open the Maps app, it does not work on iOS. The same code works fine with a macOS Safari extension. MKMapItem(placemark: MKPlacemark(coordinate: CLLocationCoordinate2D(latitude: 50.1234, longitude: 8.1234))).openInMaps()
Replies
1
Boosts
0
Views
1.2k
Activity
Apr ’22
safari-web-extension-converter not setting icons
I just converted a chrome extension with XCode command line xcrun /Applications/Xcode-beta.app/Contents/Developer/usr/bin/safari-web-extension-converter /Users/macminitwo/Downloads/new-tab-background which had no icon in manifest, after conversion there was build error error: Build input file cannot be found: '/Users/macminitwo/camo theme/Shared (App)/Resources/Icon.png' (in target 'camo theme (iOS)' from project 'camo theme') Then I updated manifest.json of main project and added icon to the project "icons": { "16": "icon16.png", "48": "icon48.png", "128": "icon128.png" } tried converting again, and it still gave same error. Now, I have to manually put the icon in "resources" folder. Note: every time on conversion, it said abort trap 6 What should I do to not get this error? And have icon there already. System Info: macOS: 11.4 Big Sur XCode: 13.0 beta 3
Replies
1
Boosts
0
Views
1.5k
Activity
Mar ’22
Infinite loop in "browser.i18n.getMessage" API
I was tracking down an infinite loop and it's caused by calling: browser.i18n.getMessage('faq_4a', ['$13.99']) Where the "faq_4a" is defined as: "faq_4a": { "message": "Highlight all prices like $1" }, The problem is the parameter ['$13.99'], if I use this parameter for any message that accepts a placeholder, it will just froze the console or whatever executed it. Can someone please try to run this code to verify? I need to know if this is a Safari issue or if just my Safari broken. I use Safari 15.3 (17612.4.9.1.8). Thank you!
Replies
2
Boosts
0
Views
1.3k
Activity
Mar ’22
Safari Web extension allow access all websites permissions - need clarification
I learned there are two types of safari extensions . Web extensions and app extensions . We are currently developing a safari web extension . The extension requires access on all web sites by default (without user granting permissions) . But there is no provision for same in web extension . However the same can be achieved in app extension by including safari website access  in info.plist . Please clarify why there is no provision to achieve the same in web extension . However same is provided in app extension .
Replies
1
Boosts
0
Views
1.7k
Activity
Mar ’22
What is the configurations of macOS for manifest v3 on safari?
Safari version : 15.3 Os version : 12.2.1 This is after latest updates and manifest v3 is not supported. So i need to downgrade manifest version to 2. What can be the solution to run manifest v3 with current mac and safari version? Also, My safari is not getting updated after updating os, Im using intel processor. What can be done to update safari version to 15.4?
Replies
1
Boosts
0
Views
1.3k
Activity
Mar ’22
Safari Web Extension does not load content script on iOS 15
The content scripts specified in the manifest of an extension should be loaded each time a user visits a web page. However, in the iOS 15 simulator, the content script is only loaded the first time that the extension is enabled -- either when you grant permission for the site, or if you turn the extension off and back on while on a site. Otherwise, the content script is not injected. This is clearly a bug, right? Is there a known workaround or a fix in the works?
Replies
4
Boosts
0
Views
3.6k
Activity
Mar ’22
Spawning a service worker in a safari web extension in the background
new Worker(browser.runtime.getURL('source/worker.js')) throws an error: Error: This script should only be loaded in a browser extension. I have a hefty background processing operation that I need to pass off to a web worker, but the script I try to execute causes this error. Is there a standard way of spawning a web worker in a background script for a safari web extension?
Replies
0
Boosts
0
Views
1k
Activity
Feb ’22
How to get URL of active tab from popup.js with Safari iOS App Extension in iOS 15?
I'm developing Safari App Extension for iOS 15.0+ and I need to get URL of active tab in popup.js and display. Here is how I do that in popup.js: document.getElementById("activetaburl").innerHTML = document.URL As result it returns path of current popup.js Here is my permissions from manifest.json: "permissions": ["nativeMessaging", "activeTab"] And info.plist: <dict> <key>NSExtension</key> <dict> <key>NSExtensionAttributes</key> <dict> <key>NSExtensionActivationRule</key> <dict> <key>NSExtensionActivationSupportsWebURLWithMaxCount</key> <integer>1</integer> <key>NSExtensionActivationSupportsImageWithMaxCount</key> <integer>10</integer> </dict> </dict> <key>NSExtensionPointIdentifier</key> <string>com.apple.Safari.web-extension</string> <key>NSExtensionPrincipalClass</key> <string>$(PRODUCT_MODULE_NAME).SafariWebExtensionHandler</string> </dict> </dict> So how to fix the issue above and get url of active tab? Thanks, Serge
Replies
2
Boosts
0
Views
2.8k
Activity
Jan ’22
How to use store data in content.js file.
I have implement reset text function in content.js file with static array. I need to manage this array with dynamic. I have pass data app to extension with FileManager. I have get store data in extension safariwebextension.swift. file. How can use this array in content.js file. Need to replace store data in content.js file. Your provided demo only supported mac version feature.
Replies
1
Boosts
0
Views
973
Activity
Jan ’22
How to resolve warnings if using safari-web-extension-converter?
Command Used: xcrun safari-web-extension-converter package-content.safariextension  --project-location SafariExtension  While running the above command, I am getting below warnings. How to resolve these for Safari for iOS 15? Warnings: The following keys in your manifest.json are not supported by your current version of Safari. If these are critical to your extension, you should review your code to see if you need to make changes to support Safari:         manifest_version         icons         persistent         version         js         content_security_policy         matches         description         <all_urls>         tabs         cookies         activeTab         scripts         storage         applications         browser_action         web_accessible_resources         name         run_at
Replies
3
Boosts
0
Views
2.4k
Activity
Jan ’22
Can I use _locale/en/messages.json string in script file?
Can I use string entered in _locale / en / messages.json in the popup.js script file?
Replies
1
Boosts
0
Views
847
Activity
Jan ’22
Safari Extensions and FaceID/Keychain access
My Safari Extension on iOS needs access to a Keychain item (password) that is secured by the userPresence and devicePasscode flag. In other words, FaceID/TouchID or the device PIN is necessary to access the password. Is there a way for the extension to access the password? SafariWebExtensionHandler.swift has access to the Keychain, but can't present FaceID/TouchID/device PIN interface to the user. Popup.js has UI access, but can't access the iOS Keychain. One hack is to set touchIDAuthenticationAllowableReuseDuration of the Keychain item to an arbitrary time and have the user authenticate in the containing app. However, in case of a time-out, the containing app has be opened by the extension with a custom URL scheme. openURL is not accessible in SafariWebExtensionHandler.swift either (I assume it can be handled by popup.js). This is a user-unfriendly solution. What is the best way to give the Safari extension access to a Keychain item?
Replies
0
Boosts
0
Views
1.3k
Activity
Dec ’21
iOS Safari web extension works only in simulator
Hi there, my iOS web extension for Safari, written in Xcode works fine in simulator but on a physical device the extension doesn't show in the extension area on phone. When launched, the app spashscreen comes up, but the extension is not show in the extension are of the browser. Same on IPhone 13 simulator works without any prob. What can I do?
Replies
2
Boosts
0
Views
898
Activity
Dec ’21
Safari not working good
I have a problem with safari, the problem started on my iPhone 7 that some of experimental webkit features was changed so that many things stopped of working on safari and I bought new iPhone pro 13 and moved the data from the old device to the new and discovered the the problem became on my two devices now.
Replies
0
Boosts
0
Views
529
Activity
Nov ’21
Did Safari Web Extension support `navigator.mediaDevices.getUserMedia`?
I would like to call navigator.mediaDevices.getUserMedia({ audio: true, video: true }).then(() => {...}); in my background.js. But It will neither resolve nor reject. I try to run it in console of background.js, but only get Promise {status: "pending"} = $1
Replies
1
Boosts
0
Views
1k
Activity
Oct ’21
Screenshot of non-active tab
Hello, Is it possible to take a screenshot of a non-active tab? Firefox supports this via captureTab (https://developer.mozilla.org/en-US/docs/Mozilla/Add-ons/WebExtensions/API/tabs/captureTab) With Safari App extensions that was possible via getScreenshotOfVisibleArea which doesn't seem to work with Safari extensions.
Replies
0
Boosts
0
Views
725
Activity
Oct ’21
Add iOS Support for Existing Safari WebExtension
How do you add iOS support for an existing Safari WebExtension? I tried running xcrun safari-web-extension-converter --rebuild-project /path/to/project.xcodeproj but that just shows the help text for the safari-web-extension-converter. Is there any documentation that demonstrates a manual way to do this? Specs: Safari 14.1.1 macOS 11.4 Xcode 12.5.1
Replies
1
Boosts
0
Views
1.3k
Activity
Oct ’21
Haptic Feedback in Safari Web Extension
Hi! We're currently building a web extension with iOS as a primary target. Since haptics on iOS are really nice, we wanted to make use of it to give the experience a special feel on iPhone. However, haptics don't seem to work when called from SafariWebExtensionHandler... maybe because the messaging layer between the web extension and the native code is in the background (is it?), and haptics don't work in apps that are in the background. Anyway, is there any way we can make haptics work regardless?
Replies
2
Boosts
0
Views
2.4k
Activity
Oct ’21