Safari Extensions

RSS for tag

Enhance and customize the web browsing experience on Mac, iPhone, and iPad with Safari Extensions

Safari Extensions Documentation

Posts under Safari Extensions tag

214 Posts
Sort by:
Post not yet marked as solved
1 Replies
217 Views
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?
Posted Last updated
.
Post not yet marked as solved
2 Replies
338 Views
I am trying to write a safari web extension that redirects users to Y URL if they type X URL without ever loading the X URL. The piece of code that I have attached below works smoothly on chrome, but not on safari. background.js function onBeforeNavigate(event) { const redirectURL = "https://google.com/" chrome.tabs.update(event.tabId, { url: redirectURL }) } chrome.webNavigation.onBeforeNavigate.addListener(onBeforeNavigate,{ url: [ {urlMatches: "https://girlcodeit.com/*"}, {urlMatches: "http://girlcodeit.com/*"} ] }) manifest.json "manifest_version": 2, "name": "", "description": "", "version": "1.0", "background": { "scripts": [ "background.js" ] }, "permissions": [ "webNavigation", "tabs" ] } I have tried writing browser.tabs.update and just tabs.update in place of chrome.tabs.update in safari version, no change. I want to achieve the redirection anyhow through a safari web extension, please suggest changes in this one or share any other approaches. webRequestBlocking is not supported by Safari, so that doesn't work either.
Posted
by mt2107.
Last updated
.
Post not yet marked as solved
1 Replies
87 Views
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?
Posted Last updated
.
Post not yet marked as solved
1 Replies
125 Views
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?
Posted
by Dannark.
Last updated
.
Post not yet marked as solved
1 Replies
157 Views
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!
Posted
by Whiskey.
Last updated
.
Post not yet marked as solved
4 Replies
929 Views
Safari Version 14.0.1 (16610.2.11.51.8) I am porting a Chrome/Firefox/Edge extension to Safari Web Extension. Mostly, the process was painless, I am, however, seeing quite different behavior in the tab ids generated by Safari compared to Chrome, Firefox, and Edge. My extension has callbacks for each of these browser.webNavigation events: browser.webNavigation.onBeforeNavigate browser.webNavigation.onCommitted browser.webNavigation.onDOMContentLoaded In each of these I rely on the tab id for various future tab targeting operations. When opening a new tab, the details object passed to each of these callbacks has a non-zero tabId on Chrome, Firefox, and Edge. However, in Safari, the tabId is always zero. To debug, I added one more callback: browser.webNavigation.onCompleted At this point Safari finally has a non-zero tabId in the details param. Needless to say this is causing some consternation with achieving the same outcomes as tab tracking on Chrome, Firefox, and Edge. It's like Safari is treating new tabs as "non tabs" until navigation completes. You can even see it when trying to get the tab by tabId=0: browser.tabs.get(tabId) // tabId=0 here 	.then(tab => { 		// tab is undefined 	}); Seems like this might be a bug. I can't imagine why the behavior is so different from other browsers. Any ideas on how to work around?
Posted
by lollimatt.
Last updated
.
Post not yet marked as solved
3 Replies
996 Views
Hello I am facing issue while implementing browser.tabs.onUpdated.addListener(function (tabID, changeInfo, tab).... This is only working while page is getting reloaded but if only URL is updated without reloading the page this event is not firing. The same thing is working fine in firefox and chrome. Do I need to add something extra?
Posted
by ganeshj.
Last updated
.
Post not yet marked as solved
3 Replies
1.3k Views
Hi, I am building a Safari Web Extension and I am seeing this warning in my console: [NSExtension] Extension request contains input items but the extension point does not specify a set of allowed payload classes. The extension point’s NSExtensionContext subclass must implement +_allowedItemPayloadClasses. This must return the set of allowed NSExtensionItem payload classes. In future, this request will fail with an error. Extension: <EXConcreteExtension: 0x7f9ca5abe440 I am not sure how to go about this. I have not found any documentation regarding usage of allowedItemPayloadClasses has anyone seen this before?
Posted Last updated
.
Post not yet marked as solved
0 Replies
126 Views
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 + "&amp;score=" + score + "&amp;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.
Posted Last updated
.
Post not yet marked as solved
1 Replies
569 Views
I'm trying to load JSON from somewhere other than my bundle, but it's not working. I can't get debugger breakpoints to work, print() doesn't work (swift), even NSLog doesn't work (doesn't even go to Console).Is there any way to be able to debug the ActionRequestHandler in the extension?
Posted
by RandyHill.
Last updated
.
Post not yet marked as solved
0 Replies
134 Views
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.
Posted Last updated
.
Post not yet marked as solved
2 Replies
581 Views
runtime.oninstalled is invoked when I install the extension for the first time in the browser. But if I uninstalled it again (by dragging the app to bin), and tried reinstalling the runtime.oninstalled is not invoked. is that an expected behavior? If so, how can I test this case during extension development? Because it is difficult to find a new browser to test this case every time. Thanks.
Posted
by Priya_.
Last updated
.
Post not yet marked as solved
4 Replies
1.1k Views
Hi! What is basic difference between Safari extension which has NSExtensionPointIdentifier set to com.apple.Safari.extension and Safari web extension with NSExtensionPointIdentifier value set to com.apple.Safari.web-extension. I'm asking because to me it seems that permissions for those two work differently. When I set same set of permissions to manifest.json of extension I have different behaviour. Case 1: For com.apple.Safari.extension when user turns on the extension in Safari preferences, there is a popup with question: Are you sure you want to turn on the extension "extension_name"?. User can either cancel it and not turn on extension, or user can click Turn on and allow all extension requested permissions on all pages. Case 2: For com.apple.Safari.web-extension when user turns on the extension in Safari preferences, there is no popup, but there are 2 buttons, Edit websites where user can enable/disable extension separately for each and every website and there is Always allow on Every Website which basically does the same as Turn On in first example. But if user does not accept some webpage, when user gets to that page first time and tries to click on extension icon, there will be popup with warning about permissions and with several options for user to allow or disable extension. To create extension I used safari-web-extension-converter tool which automatically creates Safari web extension, but problem is our users do not like permission behaviour that happens in Case 2. Is there a way to have Safari web extensions (com.apple.Safari.web-extension) which has behaviour described in Case 1.
Posted Last updated
.
Post not yet marked as solved
1 Replies
165 Views
(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?
Posted Last updated
.
Post not yet marked as solved
1 Replies
277 Views
Our extension uses fecth API from the background to check if the user is properly logged. But we get this error message : Refused to connect to https://example.com/foo/user because it does not appear in the connect-src directive of the Content Security Policy. Even if the link https://example.com/foo/user is specified in the manifest : { ... "content_security_policy": "script-src 'self';object-src 'self'; connect-src 'https://example.com/foo/user' ", ... } We've tried "content_security_policy": "script-src 'self';object-src 'self'; connect-src https://example.com/foo/user" "content_security_policy": "script-src 'self';object-src 'self'; connect-src https://example.com/*" "content_security_policy": "script-src 'self';object-src 'self'; connect-src * " Same error message when we're trying to make a WebSocket connection (wss://exampe.com/service/bar). For info, our Chrome/Firefox extension work perfectly with connect-src * directive . Does someone have the same issue? If yes, how did you manage to make it work?
Posted
by Smionean.
Last updated
.
Post not yet marked as solved
1 Replies
617 Views
Hi,how can I create a transparent scalable ToolbarItemIcon.pdf for a SafariExtension?Regards
Posted Last updated
.
Post not yet marked as solved
0 Replies
104 Views
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
Posted
by arthurc.
Last updated
.