Explore Safari Web Extension improvements

RSS for tag

Discuss the WWDC21 session Explore Safari Web Extension improvements.

Posts under wwdc21-10027 tag

27 Posts

Post

Replies

Boosts

Views

Activity

Block requests originating from a domain
Hi, According to Blocking Content with Your Safari Web Extension, we can now use the Declarative Net Request API to block content in a Safari Web Extension. However, not everything in the API has been implemented just yet. The supported RuleCondition are domainType, excludedResourceTypes, isUrlFilterCaseSensitive, regexFilter, and resourceTypes. Does anyone know when the initiatorDomains rule condition will be supported? In the meantime, is there a way for an extension to block requests based on an originator domain? Thanks
1
0
1.5k
Aug ’23
Safari 15.4 extension load wrong local page path
I'm developing a Safari extension and the feature is rating a web page opened by user and will show a block page if the web page contains some phishing link window.location.href = safari.extension.baseURI + "blockpage/blockpage.html?herf=" + window.location.href + "&score=" + score + "&level=1"; It works fine in Safari 15.3 and other version below 15.4. But there is an error on Safari 15.4 It seems path component of "blockpage" is missing. The right path should be "safari-extension://4506B856-D122-4301-93FD-712FDCC4EF14/blockpage/blockpage.html" Any comments will be appreciated. Thanks a lot.
0
0
525
May ’22
Access the UserDefaults from the safari extension background page
Hi, I am working on safari web extension for iOS, Since Message passing is only supported from safari extension to iOS application. To pass the data from app to safari extension, I thought of storing the required data using the Userdefault suite name and "app group" to access the UserDefaults data from the safari extension. I am stuck at how to access the data at the safari extension. Any sample javascript to access the UserDefaults data is appreciated Thanks
1
0
1.3k
May ’22
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
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
SFSafariApplication.openWindow(with:) not working
I am trying to build a utility application on macOS to manage a number of Safari windows and/or tabs. The first task that stumps me is opening a new window. I went back to the basic, created a new "Safari Extension App" project in Xcode 13.2.1. The sample code includes SFSafariApplication.showPreferencesForExtension(withIdentifier:) and that works fine. But when I add my call to : SFSafariApplication.openWindow(with: URL(string: "https://www.apple.com")!) then nothing happens. I tried adjusting the content of NSExtension in the Info.plist of the web extension handler, and a number of other things in the manifest, I verified that my extension was well loaded and active, but without any success with openWindow. Is there any obvious caveat I should be aware of when dealing with SFSafariApplication? Among other questions, should openWindow(...) be in the main app, in the native extension, or either?
1
0
1.4k
Feb ’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
SSO login using WKWebView with a Normal URL without callback feature
I need to perform SSO login using WkWebView and I am not using SFSafariViewController because the URL which I use is a normal web URL and I need to stop loading of next page as soon as I get a ID value in the URL as Query parameter. Now, When I use WKWebView I am unable to logout the previous session saved in WKWebView itself until I manually clear the cache of it. is there any way I can sync Safari and WkWebView sessions, So, if I login in WkWebView I can logout the same from Safari. I have tried using ASWebAuthenticateSession but as I said I need to stop the next page reload. HELP!!!
0
0
1.1k
Dec ’21
iOS Safari Extension Memory Limit 6MB
We are trying to develop a Safari extension for the upcoming iOS 15. We are facing unsolvable issues with the memory limit. Our extension handler uses close to zero memory, and 80% of the memory is taken by Apple libraries. So, any time we actually do something in our handler – it crosses the 6MB limit and it gets killed. Is there any way to avoid this, or are there any plans to increase the memory limit in future betas?
9
0
6.2k
Dec ’21
declarativeNetRequest block rule not working
except blocking images on any website opened except wikipedia, like https://www.mozilla.org, all images show up on every website [ { "id": 1, "priority": 1, "action": { "type": "block" }, "condition": {"regexFilter": ".*", "resourceTypes": [ "image" ] } }, { "id": 2, "priority": 1, "action": { "type": "allow" }, "condition": {"regexFilter": "wikipedia", "resourceTypes": [ "image" ] } } ] I downloaded the sample app from https://developer.apple.com/documentation/safariservices/safari_web_extensions/adopting_declarative_content_blocking_in_safari_web_extensions signed all targets, cleaned build and run on mac. Enabled the extension in safari preferences and clicking the icon in the status bar displays this "Blocks images on most webpages." message, so the extension seems to be running in safari. the sea creator sample works fine and i wonder why this web content blocker just won't adding activeTab to manifest.json didn't make a change { ... "declarative_net_request": { "rule_resources": [ { "id": "ruleset_1", "enabled": true, "path": "ruleset_1.json" } ] }, "permissions": [ "declarativeNetRequest", "activeTab" ] }
0
0
967
Dec ’21
Send message from Safari Web Extension Handler to Background Page
This documentation guide and the corresponding demo project show how the the Web Extension Handler can inherit from NSExtensionRequesetHandling and implement beginRequest to receive and reply to messages sent from the background script via browser.runtime.sendMessage(). The guide also mentions how browser.runtime.connectNative and SFSafariApplication.dispatchMessage can be used to send messages from the Handler to the background script, but the code is not in the example project. Further, it seems that SFSafariApplication is not available on iOS. How can I send a message originating from the Extension Handler to notify the background script of events coming from native code (e.g. UserDefaults changes)? Is polling from the background script the only option?
0
0
1k
Nov ’21
Issue while trying to make a startsession call from local for web implemenation
Issue while trying to make a startsession call for web touchpoint. Curl command works for same PEM file which is used which same gives error using JAVA. java.io.IOException: toDerInputStream rejects tag type -126 at sun.security.util.DerValue.toDerInputStream(DerValue.java:873) ~[?:?] at sun.security.pkcs12.PKCS12KeyStore.engineLoad(PKCS12KeyStore.java:1997) ~[?:?] at sun.security.util.KeyStoreDelegator.engineLoad(KeyStoreDelegator.java:222) ~[?:?] at java.security.KeyStore.load(KeyStore.java:1479) ~[?:?] at *************.createCustomSSLContext(***********.java:92) ~[classes/:?]
0
0
826
Oct ’21
Safari Web Extension / DeclarativeNetRequest : Safari 15 crashes when loading rules
Hi, I'm trying to implement a "content blocker" using the DeclarativeNetRequest permission in a Safari Web Extension. I tried to customize the sample app (ios+MacOS) provided by Apple (https://developer.apple.com/documentation/safariservices/safari_web_extensions/adopting_declarative_content_blocking_in_safari_web_extensions). However, I observe : a random behaviour on iOS15: rules do not always apply, or are not reloaded crashes on Monterey Beta9 and Safari 15.1 : com.apple.Safari.ContentBlockerLoader crashes on WebKit:runInitializeCode after ConteRuleListStore... Crash Report Any idea? Is this a "very beta" feature... documentation is so poor compared to Google's. Thanks
1
0
1.3k
Oct ’21
Safari Web Extension sendNativeMessage and browser.runtime.connectNative don't work
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?
2
0
1.9k
Sep ’21
Block requests originating from a domain
Hi, According to Blocking Content with Your Safari Web Extension, we can now use the Declarative Net Request API to block content in a Safari Web Extension. However, not everything in the API has been implemented just yet. The supported RuleCondition are domainType, excludedResourceTypes, isUrlFilterCaseSensitive, regexFilter, and resourceTypes. Does anyone know when the initiatorDomains rule condition will be supported? In the meantime, is there a way for an extension to block requests based on an originator domain? Thanks
Replies
1
Boosts
0
Views
1.5k
Activity
Aug ’23
Safari 15.4 extension load wrong local page path
I'm developing a Safari extension and the feature is rating a web page opened by user and will show a block page if the web page contains some phishing link window.location.href = safari.extension.baseURI + "blockpage/blockpage.html?herf=" + window.location.href + "&score=" + score + "&level=1"; It works fine in Safari 15.3 and other version below 15.4. But there is an error on Safari 15.4 It seems path component of "blockpage" is missing. The right path should be "safari-extension://4506B856-D122-4301-93FD-712FDCC4EF14/blockpage/blockpage.html" Any comments will be appreciated. Thanks a lot.
Replies
0
Boosts
0
Views
525
Activity
May ’22
Access the UserDefaults from the safari extension background page
Hi, I am working on safari web extension for iOS, Since Message passing is only supported from safari extension to iOS application. To pass the data from app to safari extension, I thought of storing the required data using the Userdefault suite name and "app group" to access the UserDefaults data from the safari extension. I am stuck at how to access the data at the safari extension. Any sample javascript to access the UserDefaults data is appreciated Thanks
Replies
1
Boosts
0
Views
1.3k
Activity
May ’22
Black video with sound but no GPU: Process
I keep seeing people with this issue being told to turn off GPU: Process and Capture. However my phone doesn’t have either. All my apps and phone are up to date. I’ve restarted it as well. No idea what else to do?
Replies
1
Boosts
0
Views
818
Activity
Apr ’22
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
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
SFSafariApplication.openWindow(with:) not working
I am trying to build a utility application on macOS to manage a number of Safari windows and/or tabs. The first task that stumps me is opening a new window. I went back to the basic, created a new "Safari Extension App" project in Xcode 13.2.1. The sample code includes SFSafariApplication.showPreferencesForExtension(withIdentifier:) and that works fine. But when I add my call to : SFSafariApplication.openWindow(with: URL(string: "https://www.apple.com")!) then nothing happens. I tried adjusting the content of NSExtension in the Info.plist of the web extension handler, and a number of other things in the manifest, I verified that my extension was well loaded and active, but without any success with openWindow. Is there any obvious caveat I should be aware of when dealing with SFSafariApplication? Among other questions, should openWindow(...) be in the main app, in the native extension, or either?
Replies
1
Boosts
0
Views
1.4k
Activity
Feb ’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
SSO login using WKWebView with a Normal URL without callback feature
I need to perform SSO login using WkWebView and I am not using SFSafariViewController because the URL which I use is a normal web URL and I need to stop loading of next page as soon as I get a ID value in the URL as Query parameter. Now, When I use WKWebView I am unable to logout the previous session saved in WKWebView itself until I manually clear the cache of it. is there any way I can sync Safari and WkWebView sessions, So, if I login in WkWebView I can logout the same from Safari. I have tried using ASWebAuthenticateSession but as I said I need to stop the next page reload. HELP!!!
Replies
0
Boosts
0
Views
1.1k
Activity
Dec ’21
iOS Safari Extension Memory Limit 6MB
We are trying to develop a Safari extension for the upcoming iOS 15. We are facing unsolvable issues with the memory limit. Our extension handler uses close to zero memory, and 80% of the memory is taken by Apple libraries. So, any time we actually do something in our handler – it crosses the 6MB limit and it gets killed. Is there any way to avoid this, or are there any plans to increase the memory limit in future betas?
Replies
9
Boosts
0
Views
6.2k
Activity
Dec ’21
declarativeNetRequest block rule not working
except blocking images on any website opened except wikipedia, like https://www.mozilla.org, all images show up on every website [ { "id": 1, "priority": 1, "action": { "type": "block" }, "condition": {"regexFilter": ".*", "resourceTypes": [ "image" ] } }, { "id": 2, "priority": 1, "action": { "type": "allow" }, "condition": {"regexFilter": "wikipedia", "resourceTypes": [ "image" ] } } ] I downloaded the sample app from https://developer.apple.com/documentation/safariservices/safari_web_extensions/adopting_declarative_content_blocking_in_safari_web_extensions signed all targets, cleaned build and run on mac. Enabled the extension in safari preferences and clicking the icon in the status bar displays this "Blocks images on most webpages." message, so the extension seems to be running in safari. the sea creator sample works fine and i wonder why this web content blocker just won't adding activeTab to manifest.json didn't make a change { ... "declarative_net_request": { "rule_resources": [ { "id": "ruleset_1", "enabled": true, "path": "ruleset_1.json" } ] }, "permissions": [ "declarativeNetRequest", "activeTab" ] }
Replies
0
Boosts
0
Views
967
Activity
Dec ’21
iOS 15 Beta Safari/WKWebView WebPage not loading shows blank screen
In iOS 15 beta 8, Safari/WKWebView is not loading some of the web pages it displays the blank white screen. Is anyone facing the same problem in Safari browser or WKWebview? How to solve this issue, Please help me to move forward on this!!!
Replies
1
Boosts
0
Views
2.6k
Activity
Nov ’21
Send message from Safari Web Extension Handler to Background Page
This documentation guide and the corresponding demo project show how the the Web Extension Handler can inherit from NSExtensionRequesetHandling and implement beginRequest to receive and reply to messages sent from the background script via browser.runtime.sendMessage(). The guide also mentions how browser.runtime.connectNative and SFSafariApplication.dispatchMessage can be used to send messages from the Handler to the background script, but the code is not in the example project. Further, it seems that SFSafariApplication is not available on iOS. How can I send a message originating from the Extension Handler to notify the background script of events coming from native code (e.g. UserDefaults changes)? Is polling from the background script the only option?
Replies
0
Boosts
0
Views
1k
Activity
Nov ’21
Issue while trying to make a startsession call from local for web implemenation
Issue while trying to make a startsession call for web touchpoint. Curl command works for same PEM file which is used which same gives error using JAVA. java.io.IOException: toDerInputStream rejects tag type -126 at sun.security.util.DerValue.toDerInputStream(DerValue.java:873) ~[?:?] at sun.security.pkcs12.PKCS12KeyStore.engineLoad(PKCS12KeyStore.java:1997) ~[?:?] at sun.security.util.KeyStoreDelegator.engineLoad(KeyStoreDelegator.java:222) ~[?:?] at java.security.KeyStore.load(KeyStore.java:1479) ~[?:?] at *************.createCustomSSLContext(***********.java:92) ~[classes/:?]
Replies
0
Boosts
0
Views
826
Activity
Oct ’21
es6 in WKWebView
is there going to be es6 javascript support in WKWebView (especially modules?)
Replies
0
Boosts
0
Views
596
Activity
Oct ’21
Safari Web Extension / DeclarativeNetRequest : Safari 15 crashes when loading rules
Hi, I'm trying to implement a "content blocker" using the DeclarativeNetRequest permission in a Safari Web Extension. I tried to customize the sample app (ios+MacOS) provided by Apple (https://developer.apple.com/documentation/safariservices/safari_web_extensions/adopting_declarative_content_blocking_in_safari_web_extensions). However, I observe : a random behaviour on iOS15: rules do not always apply, or are not reloaded crashes on Monterey Beta9 and Safari 15.1 : com.apple.Safari.ContentBlockerLoader crashes on WebKit:runInitializeCode after ConteRuleListStore... Crash Report Any idea? Is this a "very beta" feature... documentation is so poor compared to Google's. Thanks
Replies
1
Boosts
0
Views
1.3k
Activity
Oct ’21
Safari Web Extension sendNativeMessage and browser.runtime.connectNative don't work
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?
Replies
2
Boosts
0
Views
1.9k
Activity
Sep ’21
Safari crash after updated system to version 11.6 Mac OS Big Sur
I just updated my macbook to this version. I was working on Safari and it crashed. It keeps prompting to reopen but when I click on this option, it crashes again and it's a repeat. What is happening? What can I do?
Replies
1
Boosts
0
Views
617
Activity
Sep ’21