Post not yet marked as solved
Ios 15 iphone 7+ safari and chrome cant open videos they stay black
Post not yet marked as solved
I have a working Chrome extension using manifest version 3, and I am following the porting instructions to turn it into a Safari extension on MacOS (Monterey) - using xcrun from the Xcode toolset. I have Safari v. 15.5.
There are two problems. First, the documentation says "Safari 15.4 and later supports manifest versions 2 and 3". So how come xcrun complains about all of the following keys:
manifest_version, icons, description, version, js, matches, service_worker, type, action, tabs, activeTab, storage, alarms, webNavigation, web_accessible_resources, name, css?
At least some of those are basic to v3 manifests.
Second, when I try to install it in Safari (it builds OK under Xcode despite the above "problem") I get an error. In my background (service worker) script I call
self.importScripts("Platform.js");
which should load said JavaScript file. It's in the same folder as the script that calls it.
This works in Chrome but fails in Safari with the error:
Failed to load resource: unsupported URL safari-web-extension://FE580C4D-9931-4639-ABF9-...../Platform.js
I tried changing that dynamic import to a static import:
import Platform from "./Platform.mjs";
(After converting Platform.js to a module Platform.mjs.) This also works on chrome but now my converted extension for Safari won't even load. I get:
The service_worker script failed to load due to an error.
But I can find no way of determining what that error is (there is no information in the service worker console).
I would appreciate help with either or both of these problems. Perhaps they are connected and there is something missing/wrong about my version 3 manifest - even though Chrome is happy with it.
Post not yet marked as solved
On macOS we have SFSafariExtensionManager and
class func getStateOfSafariExtension(withIdentifier: String, completionHandler: (SFSafariExtensionState?, Error?) -> Void)
Which allows us to inform the user in the container app if the extension is currently enabled.
This API is not available in iOS. Is there a technical reason or policy behind this or is it just a missing feature in which case I will raise a feature request?
Post not yet marked as solved
I want to send data between the app and the Safari extension, I don't found any helpful resources for that.
Post not yet marked as solved
I develop Safari Web Extension for Mac OS. It is disabled after installation. How to enable extension programmatically (in code or from command line)?
Target version of Safari is 15+.
Post not yet marked as solved
I am trying to create an app that downloads files and stores these files in the document folder that can be seen inside the Files App.
I added these to the Info.plist file
<key>UIFileSharingEnabled</key>
<true/>
<key>LSSupportsOpeningDocumentsInPlace</key>
<true/>
I also added debugging code to test that the file is indeed inside the document folder. The code can see the file, but the Files app doesn't show my app document's folder by itself (not even after adding files manually). There is a special case that does show my app folder inside the Files app: when I move an existing file I have to my app document folder. That is the only way that the Files app shows my app document folder - but the strange part is that still it doesn't show the file I downloaded inside (only the file I moved manually).
Also: I tested on the simulator using iPhone 12 Pro and on a real device: same result. I deleted and re-installed the app many times, and also restarted Xcode and restarted the real device - nothing changed.
This is the code that downloads the file into my app document folder.
func downloadFile(urlString: String, filename: String, completionHandler: @escaping (_ err: Error?) -> Void) {
let config = URLSessionConfiguration.default
guard let url = URL(string: urlString), let documentPathURL = getDestFileURL() else { return }
let request = URLRequest(url: url)
let session = URLSession(configuration: config)
os_log("getting download folder %{public}@", documentPathURL.path as CVarArg)
let fileManager = FileManager()
let task = session.downloadTask(with: request) { url, response, error in
if error != nil {
os_log("error: %{public}@", error! as CVarArg)
completionHandler(error)
return
}
guard let fileURL = url else { return }
let fileNameParts = filename.components(separatedBy: ".")
do {
var isDir:ObjCBool = true
// download folder exists?
if !FileManager.default.fileExists(atPath: documentPathURL.path, isDirectory: &isDir) {
os_log("creating new folder")
try FileManager.default.createDirectory(atPath: documentPathURL.path, withIntermediateDirectories: true, attributes: nil)
}
let savePathURL = documentPathURL.appendingPathComponent(fileNameParts[0]).appendingPathExtension(fileNameParts[1])
// dest file exists?
if FileManager.default.fileExists(atPath: savePathURL.path) {
os_log("removing existing file")
try FileManager.default.removeItem(atPath: savePathURL.path)
}
// all good? then move the file!
try fileManager.moveItem(at: fileURL, to: savePathURL)
os_log("from path %{public}@", fileURL.path)
os_log("to path: %{public}@", savePathURL.path)
// dest file exists?
if FileManager.default.fileExists(atPath: savePathURL.path) {
let files = try fileManager.contentsOfDirectory(atPath: documentPathURL.path)
try fileManager.setAttributes([FileAttributeKey.protectionKey : FileProtectionType.none, FileAttributeKey.posixPermissions: 0o777], ofItemAtPath: savePathURL.path)
let attrs = try fileManager.attributesOfItem(atPath: savePathURL.path)
os_log("list of files %{public}@", files as CVarArg)
os_log("attrs of file %{public}@", attrs as CVarArg)
os_log("move was a success")
}
completionHandler(nil)
}
catch {
os_log("final error: %{public}@", error as CVarArg)
completionHandler(MyError.couldNotDownload)
}
}
Can anyone see something wrong or missing? Thanks
Post not yet marked as solved
Hi,
I am trying to test along the tabs onUpdated event on a simple web extension/addon under Chrome.
I used the Safari XCRUN converter !
What I am trying to do is :
1- Open new tab on Google Scholar with set prefs params, from "options.js" script (code below)
2- Listen for tab to be updated and ready (e.g. tab status is complete)
3 - Then, inject a content script that will simulate the user click on save button
4- Then wait 1,5s (for GS tab to reload and finish saving) and remove the listener
5- Finally close this GS tab and back to extension Options page tab.
// Detect browser language
const gsUrl = currentBrowser.i18n.getUILanguage().includes("fr")
? GSCHOLAR_SET_PREFS_FR_URL
: GSCHOLAR_SET_PREFS_COM_URL;
// Listener to detect when the GS tab has finished loading
const gsTabListener = (tabId, changeInfo, tabInfo) => {
if (changeInfo.url && changeInfo.url.startsWith(GSCHOLAR_HOST)) {
currentBrowser.tabs.executeScript(
tabId,
{
code: `document.getElementsByName("save")[0].click();`,
},
() => {
currentBrowser.tabs.onUpdated.removeListener(gsTabListener);
setTimeout(() => currentBrowser.tabs.remove(tabId), 1500);
}
);
}
};
currentBrowser.tabs.onUpdated.addListener(gsTabListener); // Add tab listener
currentBrowser.tabs.create({
url: `${gsUrl}?inst=${gScholarInstIdList.join("&inst=")}&save=#2`,
active: false,
}); // Open GS tab according to browser language
The problem is that it works well on Chrome/Edge/Firefox, but not Safari : the GS tab isn't closed and nothing happens :-/
PS:
Of course tabs onUpdated event is well supported on Safari according to MDN.
https://developer.mozilla.org/en-US/docs/Mozilla/Add-ons/WebExtensions/API/tabs/onUpdated
I have also tried webNavigation onCompleted event, but same !
https://developer.mozilla.org/en-US/docs/Mozilla/Add-ons/WebExtensions/API/webNavigation/onCompleted
Thanks for your feedback.
Post not yet marked as solved
I'm tasked with securing a Safari browser extension that my organization created. It is using WebExtensions and has been launched across various browser extension stores, including Safari. I've searched for many hours on this and find very very little information on how to secure it. (Pretty much just https://developer.mozilla.org/en-US/docs/Mozilla/Add-ons/WebExtensions/Content_Security_Policy.) Is there anything more extensive/comprehensive? I'll be dealing with Safari Desktop as well as Safari iOS.
By comparison, when looking for resources for securing the Firefox version of the extension, I found https://extensionworkshop.com/documentation/develop/build-a-secure-extension/, which I think is a great resource. Some of that content applies to Safari, but it's hard to know to what extent. I'll need to secure Safari web and Safari mobile (i.e. iOS), but for now I'm focused on web. (But if you have anything on mobile, then please let me know also.)
Thank you!
Post not yet marked as solved
So I've been trying to debug / read console.logs from background scripts when using manifest v3 but it never fires any log. It works well in manifest v2 though.
I have set the persmission and host_permission as well changed my background to service_work in manifest but nothing really happens:
"background": {
"service_worker": "scripts/background.js"
},
My Qyestion is, is it currently possible to use manifest v3 on iOS safari web extension?
Some Notes: Reading this page: https://developer.apple.com/documentation/safariservices/safari_web_extensions/assessing_your_safari_web_extension_s_browser_compatibility It says:
"background:
In iOS, you must set the persistent attribute to false. With manifest version 3, all background pages are nonpersistent."
So I'm guessing it is somehow possible to use right?
Post not yet marked as solved
I am building a safari extension app. the code(html, css, javascript) for the safari extension that is in the AppExtension directory works good, but when I added button to Main.html to make an Action, to make the app dynamically change (the application itself not the extension), and I want to send data from the app to the extension on Safari.
Could anyone help me to fix this issue.
This my html code:
<!--Main.html -->
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<meta http-equiv="Content-Security-Policy" content="default-src 'self'">
<meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no">
<link rel="stylesheet" href="../Style.css">
<script src="../Script.js" defer></script>
</head>
<body>
<!--The makeAction() function is defined in the `Script.js` file -->
<button onclick="makeAction()">Dropdown</button>
</body>
</html>
And this is the files structure
Hey,
Is it allowed to inject an HTML item above a web page on iOS using Safari Web Extension?
If yes what amount of screen space can we allocate to the UI?
Example:
Post not yet marked as solved
Safari 15.4 Release Notes shows that webpage-to-extension messaging using externally_connectable is supported.
https://developer.apple.com/documentation/safari-release-notes/safari-15_4-release-notes
However, when I tried testing it, I was not really able to get it to work. What I have tried:
Added matches array to the externally_connectable object in manifest.json
Obtain the extensionID using browser.runtime.id
Added listener to onMessageExternal for extension
Send a message from a webpage, that is in the matches array, using chrome.runtime.sendMessage with the extensionID obtained above
With these steps, I wasn't able to receive a message sending to the extension. I am not sure if the extensionID is wrong or if I am missing any crucial steps. Can someone please recommend what I should try?
Post not yet marked as solved
I have used Safari as my primary browser for years now and it has evolved. Some very good updates and some bad.
I have noticed since iOS 14 I believe when Apple started slowly implementing more security features that pages would show up wonky or unresponsive at times, but a clear browsing history and cookies would fix this issue. Then in iOS 15 and now 16b1 it’s become almost unusable on certain pages.
Again these issues have been ongoing since the updated security features started rolling out and in non beta releases
For example. Some pages won’t load completely or when you try to use a drop down menu the pictures would overlap the drop down.
Resets or clearing cookies/cache, history would not fix this issue. Even turning off some of the privacy features wouldn’t resolve this. Menus have become unresponsive, ie. registering a new user on a forum. The menus would are static with no way to change or update your dob or address.
I hope this makes sense so far.
So here is what I have turned on and added extensions.
Tracking is off in privacy & security
[on] Block pop ups
[on] Prevent cross-tracking
[on] Hide IP and Address - Trackers & Websites // I can’t see it but I believe the Trackers & Websites is set to general location//
[on] Fraudulent website warnings
[on] Privacy Preserving Ad Measurements
All Advanced Safari settings are default and have not been touched
Extensions - 1Blocker (only these below are on)
[on] Block Ads
[on] Block Adult Sites
[on] Block Annoyances
[on] Block Trackers
I have tested things for months now, toggling these off and back on. Trying to find the combination that works. I even removed all extensions and ran just the safari settings by themselves and it still renders some type of misfire with sites (menus being static or pictures over lapping drop down menus)
The title says it all.
How can I get safari back to working and have these privacy features on without the extra bugginess that Safari is doing?
Thanks in advance!
Post not yet marked as solved
I'm converting a Chrome extension to work in Safari 15 using the xcrun safari-web-extension-converter. It partially works, but seems to fail with CORS permission issues in both the background script and content scripts.
Oddly enough neither issue exists in Chrome. I have granted all websites permission via Safari itself after installation.
In manifest.json, I have this in the permissions key:
"http://*/",
"https://*/"
I've tried a variety of permutations, including "https://*/*" but nothing works. Every XMLHttpRequest results in the same error:
Failed to load resource: Origin safari-web-extension://... is not allowed by Access-Control-Allow-Origin. Status code: 200
As mentioned, it works fine in Chrome with the same permissions. What have I missed?
Post not yet marked as solved
I am creating a Safari Web Extension to add some security features to Safari browser. Web Extension has 2 parts, 1st - script code, which loads in browser and 2nd - a separate application/process called Native App which gets notifications and data of browser activities. I am able to get notifications of various browser activities in Safari Native App. When such notification is received, this needs to be sent to other daemon process running on same MacOS machine over unix domain socket (used for local IPC). This Safari Native App is running within a sandbox.
The issue is, when trying to connect to already listening socket of other process from Safari Native App, the sandbox of Native App denies outbound socket network connection. Question: Is there a way to communicate from sandboxed Native App using socket with other processes.
Disclaimers:
Sandbox cannot be disabled, if disabled it stops getting notifications from Safari for activities, which is its basic work.
Entitlements and app groups addition can be done, but the process to which it has to communicate cannot be added to app group.
Please help/suggest what can be way out from this problem.
Post not yet marked as solved
Hi,
I'm trying to convert my chrome extension to work in Safari. I've got it mostly working but there is one issue with the webRequest.onResponseStarted.addListener api. The callback is missing fields including ip. Here is an example:
webRequest.onResponseStarted.addListener((r) => {
console.log(r);
}, {"urls": ["<all_urls>"])
In chrome this will print all the fields described in the spec.
But in safari it is missing a lot of fields, including ip, type, etc.
Does anyone know if this is a bug or if I am doing something wrong?
Thanks!
Post not yet marked as solved
Hi all, I have a stand-alone Chrome extension app, and used the xcrun converter last year to create a desktop Safari app, and used the xcrun converter again to create a mobile safari extension. Now I want to bundle that extension into an existing iOS app. However I also want the ability to update the extension as if it were a cocoapod or a swift package. Is this possible?
Post not yet marked as solved
Hello,
How can I change the commands originally set in the manifest? Is there a special internal url like in chrome since browser.commands.update does not seem to exist in Safari.
Thank you
Post not yet marked as solved
I’m developing safari web extension on macOS using Xcode. I need to send message from web extension’s background.js to containing APP.
As “Messaging a Web Extension’s Native App” describe,
I create a port in background.js as follow:
let port = browser.runtime.connectNative("application.id");
In background.js send message as follow:
port.postMessage("Hello from JavaScript Port");
how can I receive this message in containing APP? I would be very grateful if you could give an example. Thanks!
Another problem is how can connectNative start the containg APP on macOS.
As runtime.connectNative describe in MDN(https://developer.mozilla.org/en-US/docs/Mozilla/Add-ons/WebExtensions/API/runtime/connectNative)
“It starts the native application and returns a runtime.Port object to the caller.The caller can then use the Port to exchange messages with the native application using Port.postMessage() and port.onMessage”
In safari, connectNative seems cannot start the containing APP. How can I make it start the containing APP?
Post not yet marked as solved
I'm not sure what is special about Gmail, but my declarativeNetRequest rules are totally ignored.
I make an web extension that blocks email trackers (1x1 pixel images embedded in emails to track if and when you open email sent to you). All images in Gmail are loaded through Google's proxy: googleusercontent.com/proxy/#originalURL
But no matter what I do, I can't block a single image that is loaded in an email. To try and prove it is a bug in Safari, I created a new template web extension in Xcode.
I block all resourceTypes (images and other should be all that is needed) and added two rules:
Block all images loaded through Google's proxy server (this should block all embedded images in all emails)
Block any image with copper in the URL (just in case the blocking doesn't apply to the proxy root url for some reason).
{
"id": 1,
"priority": 1,
"action": { "type": "block" },
"isUrlFilterCaseSensitive": false,
"condition": {
"regexFilter": "googleusercontent.com/proxy",
"resourceTypes": [
"image",
"media",
"main_frame",
"sub_frame",
"stylesheet",
"script",
"font",
"xmlhttprequest",
"ping",
"websocket",
"other"
]
}
},
{
"id": 2,
"priority": 1,
"action": { "type": "block" },
"isUrlFilterCaseSensitive": false,
"condition": {
"regexFilter": "copper",
"resourceTypes": [
"image",
"media",
"main_frame",
"sub_frame",
"stylesheet",
"script",
"font",
"xmlhttprequest",
"ping",
"websocket",
"other"
]
}
}
]
Even though I know this isn't needed, I also added the requester domain (mail.google.com) and the proxy domain (googleusercontent.com) to the permissions list in the manifest file:
...
"declarative_net_request": {
"rule_resources": [{
"id": "ruleset_1",
"enabled": true,
"path": "rules.json"
}]
},
"permissions": [
"declarativeNetRequest",
"*://mail.google.com/*",
"*://*.googleusercontent.com/proxy/*"
]
If I open an email from copper, the image still loads in Gmail
If I right click and select "Open Image in New Tab", the image will not load and I am told it was blocked
If I open a test page that has two images in it, one the image from the email, the image is blocked and the other image is not (as expected, the second image is from wikipedia and should not be blocked)
Running the same extension in Chrome DOES block the image in Gmail (and in all the other cases too)