Meet Safari Web Extensions on iOS

RSS for tag

Discuss the WWDC21 session Meet Safari Web Extensions on iOS.

View Session

Posts under wwdc21-10104 tag

35 Posts
Sort by:
Post not yet marked as solved
1 Replies
297 Views
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()
Posted
by andre07.
Last updated
.
Post not yet marked as solved
0 Replies
539 Views
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
Posted
by AjeetRE.
Last updated
.
Post not yet marked as solved
2 Replies
409 Views
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!
Posted
by Juraj_M.
Last updated
.
Post not yet marked as solved
1 Replies
401 Views
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 .
Posted Last updated
.
Post not yet marked as solved
1 Replies
331 Views
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?
Posted Last updated
.
Post not yet marked as solved
3 Replies
1.4k Views
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?
Posted Last updated
.
Post not yet marked as solved
0 Replies
292 Views
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?
Posted
by uzinator.
Last updated
.
Post not yet marked as solved
2 Replies
862 Views
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
Posted
by sotrosh.
Last updated
.
Post not yet marked as solved
1 Replies
355 Views
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.
Posted
by AjayGol.
Last updated
.
Post not yet marked as solved
3 Replies
937 Views
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
Posted
by monika_1.
Last updated
.
Post not yet marked as solved
0 Replies
395 Views
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?
Posted Last updated
.
Post not yet marked as solved
1 Replies
313 Views
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?
Posted
by atlantex.
Last updated
.
Post not yet marked as solved
0 Replies
261 Views
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.
Posted
by Yrahoma.
Last updated
.
Post not yet marked as solved
1 Replies
398 Views
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
Posted Last updated
.
Post not yet marked as solved
0 Replies
312 Views
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.
Posted
by bruno.cm.
Last updated
.
Post not yet marked as solved
2 Replies
745 Views
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.
Posted Last updated
.
Post marked as solved
1 Replies
567 Views
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
Posted
by jw732.
Last updated
.
Post not yet marked as solved
2 Replies
562 Views
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?
Posted Last updated
.
Post not yet marked as solved
2 Replies
930 Views
We have Safari App(!) Extension, the one that has no background page. We want to port it to a Safari Web Extension, so it can run on iOS 15. The App Extension extensively uses safari.extension.dispatchMessage, and we want to replace it with browser.runtime.sendNativeMessage, which doesn't work at all. There's a couple questions: How to get a response from browser.runtime.sendNativeMessage Do we have to use browser.runtime.connectNative? How to use it? Where is the documentation on all of this?
Posted Last updated
.