Hello, I am facing issues when I try to download a file in a safari browser extension.
I tried multiple methods, I followed also this thread https://developer.apple.com/forums/thread/119017. But they did not work for me.
For a safari browser extension, it seems that the download href attribute does not work.
browser.downloads api is not available, also the window.saveAs is not available.
In a safari browser extension, the download attribute doesn't do anything, it just opens the file in the same tab, and the user is loosing the current tab of the extension. Using window.open as suggested in the topic above helps, but the UX is terrible, because the user has to allow the popup to be opened.
So is there a way to perform file downloads from safari extension?
Here are the methods that I tried:
Creating an element from javascript. The issue here is that the download attribute does not work, it moves the user to the file in the same tab. And the user can't go back.
const element = document.createElement('a');
element.setAttribute('href', uri);
element.setAttribute('download', filename);
element.style.display = 'none';
document.body.appendChild(element);
element.click();
document.body.removeChild(element);
}
Using window.open. Here the user needs to approve the popup, and it's a hard/confusing thing to do for a non-experienced user.
function downloadPWA(content)
{
var file = new Blob([content],
{
type: 'text/xml;charset=UTF-8'
});
var reader = new FileReader();
reader.onload = function()
{
var popup = window.open();
var link = document.createElement('a');
link.setAttribute('href', reader.result);
link.setAttribute('download', 'filename.txt');
popup.document.body.appendChild(link);
link.click();
}
reader.readAsDataURL(file);
}
Here is a GitHub repo of a small dummy test extension where I tested the download functions https://github.com/mihainsto/Safari-extension-download-file .
Selecting any option will automatically load the page
Post
Replies
Boosts
Views
Activity
Hello, I want to test build & sign manually a safari extension for self distribution.
The safari extension contains no content, just a hello world pop-up.
For this kind of extension do I need to have custom Entitlements or a Provisioning profile? I can't find anywhere on the internet if a blank/empty safari extension needs some Entitlements for manually code signing.
To sign a safari browser extension manually I just have to take the compiled .app and manually code-sign it? With no entitlements and no provisioning profile and no other stuff?
Does anyone have some experience with manually signing Safari browser extensions and can help with this?
Thanks!
Hello!
I am trying to build a CI pipeline for a safari browser extension. And in order to achieve this I am manually signing the .app.
The file that creates problems is the .appex. From "extensionName.app/Contents/PlugIns/extenstionName Extension.appex". Not signing this file causes the notarization to flag the package as invalid. The order that I achieved the signing and caused the notarisation to work is this.
(not actual signing request lines, I simplified them for easier readability)
# Signing first all the .dylib files
-timestamp --options runtime "extenstionName.app/Contents/Frameworks/*.dylib"
# Then signing the binary from the appex
--prefix=com.domain. --timestamp --options runtime "extenstionName.app/Contents/PlugIns/extenstionName Extension.appex/Contents/MacOS/extenstionName Extension"
# Then signing the .app package
--prefix=com.domain. --timestamp --options runtime "extenstionName.app/"
# And at the end signing the .appex
--prefix=com.domain. --timestamp --options runtime "extensionName.app/Contents/PlugIns/extensionName Extension.appex"
If I do the signing this way the notarization works, and the .app is code signed and can be verified. The issue is that the extension does not load at all in safari, not even with Allow Unsigned Extensions enabled. And I can't find any way to debug this. Clicking Quit and Open Safari Extensions Preferences... does nothing, nothing appears inside the Safari Extension Preferences menu.
I tried multiple combinations of signing order.
Signing the .appex before the .app causes the code signature to not be valid at all.
Do not sign the .appex at all causes the .app to be verified and signed but in safari you need to have unsigned extension enabled. And also the notarization fails throwing errors about the .appex that is not signed
Not signing the binary from the .appex causes the notarization to fail throwing error that that binary is not signed.
Also I tried to run the signed and notarized .app on a clean macOS computer, and it does not load into safari, the same that happens on the development computer.