Post not yet marked as solved
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 14. But there is an odd scene on Safari 15.3
It will redirect to right local page with right parameters first but redirect twice quickly without parameters leads to fail to render local page
Any comments will be appreciated.
Thanks a lot.
Post not yet marked as solved
Error instantiating template in Xcode: Error Domain=NSCocoaErrorDomain Code=642 "You can’t save the file “macOS (Extension)” because the volume is read only." UserInfo={NSFilePath=/YOU CAN READ IT Dyslexia won't stop you!/macOS (Extension), NSUnderlyingError=0x6000009a4270 {Error Domain=NSPOSIXErrorDomain Code=30 "Read-only file system"}}.
Could not create project.
Post not yet marked as solved
(void)contentBlockerWithIdentifier:(NSString *)contentBlockerIdentifier blockedResourcesWithURLs:(NSArray<NSURL *> *)urls onPage:(SFSafariPage *)page
does not trigger
I have put this into the info.plist of the Safari Extension:
<key>SFSafariAssociatedContentBlockers</key>
<array>
<string>com.thomas.bodlien.software.JavaScript-Blocker.ContentBlockerExtension</string>
What could be the problem?
Post not yet marked as solved
I made a Safari Web extension that's supposed to work like this:
WHEN: Safari is opening http://example.com/
THEN: The extension opens a page embedded in the extension instead.
This is the implementation of background.js:
browser.tabs.onUpdated.addListener(async function (tabId) {
const tab = await browser.tabs.get(tabId);
if (tab.url == "http://example.com/") {
const destination = browser.runtime.getURL("embedded-page.html");
browser.tabs.update(tabId, { url: destination });
}
}, null);
This is the source project:
https://www.icloud.com/iclouddrive/042qIjivEoJ0V3qIcLGcytAPA
When opening http://www.example.com/ for the first time, it successfully navigates to the embedded page. However, once that navigation is done, the extension no longer works that way unless I re-enable the extension. It's like the listeners are removed by that navigation.
This is the video of this issue:
https://www.icloud.com/iclouddrive/0f9Yl1jC9eQ8OmgH8vAtEA6Pw
Can you replicate this on your Mac? And do you know what's the cause?
This happens for a listener of browser.webNavigation.onBeforeNavigate too. Maybe more.
On the other hand, when I set a normal page such as https://www.apple.com/ to destination, It always works fine for me. So I'm wondering if this issue is related to the embedded page.
FYI, I already reported this issue as FB9967637 on 27th March but no reply from Apple as of now.
My environment
macOS Monterey 12.3.1 (21E258)
Safari 15.4
Post not yet marked as solved
Creating a new window with a tab ID parameter creates new window, but does not move the requested tab.
To reproduce, have an tab loaded in a window and run this snippet in an extension background page.
browser.tabs.query({}).then(tabs => {
browser.windows.create({ tabId: tabs[0].id });
});
The expected behaviour happens in Chrome.
–
I wonder if this is a documentation issue, as the MDN docs say Safari has full support for browser.windows.create
https://developer.mozilla.org/en-US/docs/Mozilla/Add-ons/WebExtensions/API/windows/create
but also say that Safari does not support tabs.move
https://developer.mozilla.org/en-US/docs/Mozilla/Add-ons/WebExtensions/API/tabs/move
I have updated my web extension to use Manifest v3.
While trying to test, I get the error:
_The service_worker script failed to load due to an error.
_
I do not see details on the error, or a place where to find details. Any suggestions?
Post not yet marked as solved
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!
Post not yet marked as solved
I recently converted my Chrome extension to a Safari extension using the Apple Conversion tool (XCode CLI). The extension is developed with ReactJS and SaSS.
It works very well on Google Chrome but when I try it on Safari after converting it, the local extension works but the CSS file that handles the extension is not applied.
There are no errors during the conversion but the Safari developer tool indicates several errors :
console tab : Failed to load resource: You are not allowed to access the required resource.
network tab : An error occurred while trying to load the resource and the resource was requested in an insecure manner.
In the extension, we isolate CSS using iframe :
/*global chrome*/
/* src/content.js */
import React from 'react';
import ReactDOM from 'react-dom';
import Frame, { FrameContextConsumer }from 'react-frame-component';
import "./content.css";
class Main extends React.Component {
render() {
return (
<Frame head={[<link type="text/css" rel="stylesheet" href={chrome.runtime.getURL("/static/css/content.css")} ></link>]}>
<FrameContextConsumer>
{
// Callback is invoked with iframe's window and document instances
({document, window}) => {
// Render Children
return (
<div className={'my-extension'}>
<h1>Hello world - My first Extension</h1>
</div>
)
}
}
</FrameContextConsumer>
</Frame>
)
}
}
Here is the manifest.json file:
{
"short_name": "My Extension",
"name": "My Extension",
"version": "1.0",
"manifest_version": 3,
"icons": {
"16": "icon16.png",
"48": "icon48.png",
"128": "icon128.png"
},
"action": {
"default_icon": {
"16": "icon16.png",
"48": "icon48.png",
"128": "icon128.png"
},
"default_title": ""
},
"background": {
"service_worker": "background.js"
},
"content_scripts" : [
{
"matches": ["<all_urls>"],
"css": ["/css/root.css"],
"js": ["/static/js/content.js"]
}
],
"permissions": [
"activeTab",
"scripting",
"storage"
],
"host_permissions": ["https://www.google.com/*"],
"web_accessible_resources": [{
"resources": [
"/static/css/content.css",
"/static/media/*"
],
"matches": ["<all_urls>"]
}]
}
After many attempts, I did not understand the exact origin of the problem and I do not know how to solve it. Do you have any suggestions ?
I am creating a Safari App Extension for users to save web links and quotes to my app. I would like to cache web page metadata when links are saved by the extension.
I am using a context menu command to capture information with the code below.
override func contextMenuItemSelected(
withCommand command: String,
in page: SFSafariPage,
userInfo: [String : Any]? = nil)
{
switch command {
case "sendToApp":
Task {
guard let properties = await page.properties(),
let pageURL = properties.url else {
return
}
let provider = LPMetadataProvider()
provider.timeout = 0.01
os_log("*** Starting metadata call ***")
let metadata = try? await provider.startFetchingMetadata(for: pageURL)
os_log("*** Continued past metadata call ***")
// ...
}
}
I get the log:
*** Starting metadata call ***
LPMetadataProvider<1>: start fetching for URL
...but I am never seeing the log "*** Continued past metadata call ***"
I wonder if the task is being killed for some reason?
I thought maybe async code was an issue in SFSafariExtensionHandler, but the first await call in the guard passes successfully.
I thought that the default timeout of 30s on LPMetadataProvider may be too great, but it still fails with a tiny timeout of 0.01s.
I have added com.apple.security.network.client to the entitlements of the extension.
Is there something I am missing please?
Post not yet marked as solved
How do I change the background of My View controller in SafariExtensionViewController? I have My View, I need to somehow change its background, NSView, I attached a screenshot https://pastenow.ru/GQ58E
Post not yet marked as solved
I'm just starting out on my journey, but please don't swear too much. Can you please tell me how to set the desired background color for Custom View, the color I need is #F8F7F7.
Post not yet marked as solved
I am facing an issue with browser extension. extension stops working if we keep the browser idle for overnight.
This happens on MacOS as well as iOS device.
Post not yet marked as solved
How to download this file and fix safari browser when iPhone 8 is out of storage space…
file:///private/var/mobile/Containers/Shared/AppGroup/3F4D1382-DC26-4CA5-8836-00458AE0A389/File%20Provider%20Storage/Downloads/39PIWDCm.download
Post not yet marked as solved
I am trying to develop a Safari Extension that can save a file from a webpage into persistent storage with minimal user input.
Problem
I don't know how to code it so that it results like manually saving a file from the "Sources" tab in Safari Web Inspector.
Equivalent manual steps
show source or resources of page
by keying ⌥⌘U or ⌥⌘A
or by navigating to Web Inspector then "Sources"
save the file
by selecting the file then by keying ⌘S
or by secondary clicking the file then clicking "Save File"
Alternative solution
Javascript get the URL of files from the HTML elements and then pass the URL to a downloader, but I don't want to download it after the browser already did. I want to save the already downloaded temporary files to reduce network trafficking.
Theory
From my current understanding, when a webpage is viewed, Safari downloads the files and loads them in memory.
Other
I tried multiple ways to Google it but I keep getting only unrelated results.
Thank you for your time to read this and in advance.
Post not yet marked as solved
I have a content blocker in my app and in app I check to see if the content blocker is enabled. Since iOS 15.4 the is enabled does not change unless the app is killed and reopened.
When the app is put into the background and the user goes to iOS Settings>>Safari>>Extensions and enables the Content Blocker then returns to the app, the content blocker state still returns isEnabled as false until the app is fully terminated and reopened. The same is issue occurs when disabling the content blocker (although in this scenario it returns isEnabled as true until the app is killed and reopened.)
This worked fine on all versions of iOS up until 15.4
This is the code I am using:
SFContentBlockerManager.getStateOfContentBlocker(withIdentifier: contentBlockerId, completionHandler: { (state, error) in
print("new ContentBlockerState - \(String(describing: state?.isEnabled))")
})
Is this an issue with iOS 15.4 or is there something else I have to do to get this working now.
Post not yet marked as solved
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()
Safari browser(especially 15.4).
I have few html pages deployed as part of extension.
When I try to set the current Tab page url to one of these html pages, extension stops working.
May I know why ? Am I doing something wrong here ?
Post not yet marked as solved
Hello,
I tried to convert an existing Chrome extension that uses alarms API. When you load the package in developper mode, you can put a "PeriodInMinute" under 1 and it triggers the alarm correctly.
In safari, after running in Xcode the converted App, the Alarms seems to be triggered only each minute.
Is there a way to allow alarms to be triggered under 1 minutes using Safari ?
Thanks !
Post not yet marked as solved
In the manifest.json file I have set the following:
"web_accessible_resources": [
"template.html"
]
Then used the following command to get the url
browser.runtime.getURL('template.html')
Which results in the following as expected:
safari-web-extension://40C1D308-F374-4C87-98C8-D9E9A4AD7945/template.html
However, when trying to fetch the file from within the script I get :
Failed to load resource: The requested URL was not found on this server.
And when pasting it as a url in safari I get :
Safari cannot open the page because the address is invalid.
The template.html file exists in the same folder as the manifest.json file. I've even tried placing it in a folder called html, then using the following with wildcard, and that doesn't work either.
"web_accessible_resources": [
"html/*.html"
]
Post not yet marked as solved
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