wwdc20-10665

Discuss WWDC20 Session 10665 - Introducing Safari Web Extensions

Posts under wwdc20-10665 tag

35 results found
Post marked as unsolved
199 Views

JS injection in Safari on iOS?

Does the new Safari Web Extensions allow JS injection on iOS? I have a web extension that is currently running on Chrome and Firefox, but I would like to bring it to my iOS users (who currently use it through a Siri Shortcut JS injection).
Asked
by jdnoc.
Last updated .
Post marked as unsolved
413 Views

How to correctly entitle and code sign for distribution outside the App Store?

While I can get a simple webextension to load on my development machine, I can't figure out how to package it for distribution. What are the requirements for doing so? I've tried: Enabling hardened runtime Clicking the checkbox to allow Apple events. Removing the "strip" step from the build process to avoid warnings about code signature being invalidated. Signing both Extension and App with a Developer ID Application certificate. Notarizing the App. Exporting the notarized app. After doing the above, I copy the notarized app to a testing machine. I can then run it. A dialog pops up that says: "Foo extension is currently off. You can turn it on in Safari Extension preferences." But when I click the button to open Safari Extension preferences, the extension is not listed. What am I doing wrong?
Asked
by plujon.
Last updated .
Post marked as unsolved
150 Views

How to download a file generated using a Safari Web Extension

My team is developing a web extension and we were also trying to port it to support Safari. The conversion using xcrun was pretty smooth. However, we are not able to download a file to our disk drive, and this is only broken in Safari extension (It works across other browsers and in Safari tab too). I think the issue is that the Download Permission Popup is not appearing for the user, which I got when running the extension in a tab. Here's a gist to help you understand more: domtoimage 			.toBlob(element) 			.then(function (blob) { 				const url = window.URL.createObjectURL(blob); 				saveAs(url, "data.png"); 			}); The above code works across browsers, nothing happens when running as a Safari Web Extension Let me know what you think!
Asked
by ish2gud.
Last updated .
Post marked as unsolved
187 Views

Safari Web Extensions badge background color is not customizable

For my extension that shows the latest stock prices, I call browser.browserAction.setBadgeBackgroundColor() to change the badge background to green or red depending on whether the price is up or down. The badge color should be green but it's always red. Is this expected? It's not documented in the compatibility doc here - https://developer.apple.com/documentation/safariservices/safari_web_extensions/assessing_your_safari_web_extension_s_browser_compatibility. See a side-by-side comparison screenshot - https://www.icloud.com/iclouddrive/0XIabSA-GtYrn7zlqnIAkgsIg#Screen_Shot_2020-08-08_at_4.28.47_PM with Chrome 84 on the top and Safari 14 beta 2 on the bottom.
Asked
by rayshan.
Last updated .
Post marked as unsolved
170 Views

Extension button requires double tap before it works

When I enable extension for Safari, and first time I tap on the button, it shows me privacy dialog box and when I grant permission, the dialog box is dismissed and to make my extension work, I have to again click on the extension button. I have requirement that my extension should work only when user taps on the button post enabling the extension. So, for each and every page I visit I need to manually tap on button before my injected content-script comes into action. My background.js is where extension click method is registered and executes, chrome.browserAction.onClicked.addListener(function (tab) { 		getActiveTab(function (tabID) { 				chrome.tabs.sendMessage(tabID, { name: 'inject-content' }); 		}); }); function respond(message, sender, callback) { 		console.log(">>>> PROCESS MESSAGE => " + message); } chrome.runtime.onMessage.addListener(respond); Here, from background script, extension button is handled and when tapped, load() from content-script is called via chrome.tabs.sendMessage() and processes different things. My content-script.js is like, var loadInit = function loadInit(message, sender, callback) {   console.log("SAFARI => " + message.name);   if (message.name == 'inject-content') {    //chrome.runtime.onMessage.removeListener(loadInit)    load();   } }; console.log("SAFARI Message=> "); chrome.runtime.onMessage.addListener(loadInit); function load() { 		console.log("Loading action methods"); 		chrome.runtime.sendMessage({ init: true }); } Here, chrome.runtime.sendMessage() is handled in background script and code in respond() method will be executed. My query is, are we able to avoid second tap we make on extension button after we granted permission for the extension? Should permission grant not execute extension button code without explicit tap second time?
Asked
Last updated .
Post marked as unsolved
102 Views

Permissions exposure and message changes

I have been working on an extension which I migrated with xcrun safari-web-extension-converter PATH. When I press extension button on safari toolbar it shows me message like, This extension would be able to read and alter webpages and see your browsing history on this website. This could include sensitive information, including passwords, phone numbers, and credit cards. However, my extension is only accessing url to bookmark it and localstorage to access user tokens, tabs so new tab with somedomain.in can be opened open bookmarked link into new tab. Here is excerpt from manifest.json, "permissions" : [   "*://*.domain.in/*",   "activeTab",   "storage",   "notifications",   "tabs"  ], "optional_permissions": ["activeTab", "*://*.domain.in/*"],     "content_security_policy": "script-src 'self' 'unsafe-eval'; object-src 'self'",  "web_accessible_resources": [   "corner.css",   "js/init.js",   "init.bundled.js",   "js/jquery.min.js",   "js/taggle.min.js",   "js/typeahead.bundle.min.js",   "ext.html.js",   "assets/*"  ], It feels access to sensitive information is a bit scary for extension which just stores and manages URLs. Would you suggest me any solution over here so I can use limited permission and avoid sensitive info message..?
Asked
Last updated .
Post marked as unsolved
154 Views

Extension AUTH : How to give default allow permission for Auth purpose?

I have working cross-platform extension which I converted for Safari using xcrun safari-web-extension-converter PATH. Goal of extension is to bookmark any URL into my website account. My extension is perfectly working fine for Chrome but for Safari version, everything works well if user allows access permission for every website. The case is, when user presses extension button, we are checking user is logged into its account or not by opening our website URL into another tab. var openSignin = function openSignin() { 	console.log('hey'); 	chrome.tabs.create({ url: _config.baseURL + '?extension=1', active: false }); }; When this AUTH tab is loaded, following method will be called as it happens in Chrome which in turn extracts public and private tokens generated when any user logs into our website. chrome.tabs.onUpdated.addListener(function (tabID, changeInfo, tab) { if (tab.status == 'complete' && tab.url.startsWith(_config.baseURL)) {   chrome.tabs.executeScript(tab.id, { code: 'localStorage.getItem("PUBLIC")' }, function (r) {    localStorage['PUBLIC'] = JSON.parse(r[0]);    chrome.tabs.executeScript(tab.id, { code: 'localStorage.getItem("PRIVATE")' }, function (r) {     localStorage['PRIVATE'] = JSON.parse(r[0]);     if (localStorage['PRIVATE'] && tab.url === _config.baseURL + '?extension=1') {      chrome.tabs.remove(tabID);     }    });   });  } }); The issue lies here is that until user does not grant for "Always Allow on Every Website" (I mean grant permission for https://www.OURDOMAIN.com/extension?extension=1), chrome.tabs.onUpdate is giving tab.url = "" and it does not give proper URL value so we come to know that particular user is signed in or not (we don't get that our domain tab is loaded or not due to this issue). Do we have any way to allow access for our website without user's consent? Following is our manifest.json: { 	"name": "EXT NAME", 	"description": "DESCRIPTION", 	"manifest_version": 2, 	"version": "1.0.181", 	"minimum_chrome_version": "23", 	"offline_enabled": true, 	"browser_action" : { 		"default_icon" : { 			 "64": "logo/stash.png" 		}, 		"default_title" : "Add to Stash" 	}, 	"background" : { 		"scripts" : [ 			"bundle.js" 		] 	}, 	"content_scripts": [{ 			"js": [ "init.bundled.js" ], 			"matches": [ "<all_urls>" ] 	}], 	"icons": { 		 "16": "logo/stash_small.png", 		 "64": "logo/stash.png" 	}, 	"permissions" : [ 			"https://*.stash.ai/*", 		"activeTab", 		"gcm", 		"storage", 		"notifications", 		"identity", 		"contextMenus", 		"tabs", 		"idle" 	], 	"externally_connectable": { 		"matches": ["https://*.stash.ai/*"] 	}, 	"content_security_policy": "script-src 'self' 'unsafe-eval'; object-src 'self'", 	"web_accessible_resources": [ 		"corner.css", 		"js/init.js", 		"init.bundled.js", 		"js/jquery.min.js", 		"js/taggle.min.js", 		"js/typeahead.bundle.min.js", 		"ext.html.js", 		"assets/*" 	], "commands": { 		 "_execute_browser_action": { 			 "suggested_key": { 				 "default": "Ctrl+Shift+S", 				 "mac": "Command+Shift+S" 			 }, 			 "description": "Send a link to Stash!" 		 } 	 } } Please check permissions and content_scripts properties where I tried to put proper options but no solution. I event tried externally_connectable but still without user's consent I am not able to receive proper URL for that particular tab. Would you suggest me any solution of how I can authenticate my user here? The main authentication is done backend side only and I am not using any API here. I am just opening new tab which if loaded successfully authentication will be validated. I hope my problem is clear. If there are any queries let me know.
Asked
Last updated .
Post marked as solved
110 Views

Safari 13 deployment

I am able to convert my extension to via XCode 12 Beta and it works great. However, I am very unclear of backward compatibility. Right now it needs Safari 14 only and its not shown on Safari 13 . So, will I be able to distribute my extension for Safari 13 as well? Or do I have any other option for Backward compatibility?
Asked
Last updated .
Post marked as unsolved
147 Views

Will Safari app extension be deprecated in support of Safari web extension?

At present I have safari app extension which supports macOS version 10.13. 6 and 10.12. If i switch to Safari web extension, their support will be lost. Is there any plan for deprecation of safari app extension.
Asked
by technakul.
Last updated .
Post marked as unsolved
230 Views

No webRequestBlocking?

The following keys in your manifest.json are not supported by your current version of Safari. If these are critical to your extension, you should review your code to see if you need to make changes to support Safari: storage webRequestBlocking incognito privacy What am I supposed to use for webRequestBlocking with Safari? (Seems this would be one of the most desired keys for web extensions?)
Asked
by lbutlr.
Last updated .
Post marked as solved
130 Views

Safari App Extension to Safari Web Extension migration

We currently have a working Safari App Extension that was converted from a Chrome extension. We want to migrate to a Safari Web Extension so that we can have a unified code base. My question is with packaging the extension in the container app. Ideally we'd like to package both the old App Extension and the new Web Extension in the same container app, so that we can support both Safari 13 and 14. However, when users are using Safari 14 we'd like them to see only the Web Extension and not the old App Extension. Is there a way to do this?
Asked
Last updated .
Post marked as solved
160 Views

Sending a Native Message to a Web Extension *activates* Safari :(

In some applications, a Safari Web Extension must receive a Native Message and process it in the background, without activating Safari. For example, assuming that Safari Web Extensions will soon support the browser.bookmarks API - https://developer.mozilla.org/en-US/docs/Mozilla/Add-ons/WebExtensions/API/bookmarks, when a bookmarks syncing application needs to push a new bookmark from a source of truth into Safari's bookmarks, it will send a Native Message to the extension, and this may happen when Safari is not the active macOS application, for example if the user is writing email in Mail. I am modifying Apple's Sea Creator - https://developer.apple.com/documentation/safariservices/safari_web_extensions/developing_a_safari_web_extension sample code to establish a proof of concept for such an application. So far, pretty good. I am able to send over 150 MB of data – far more than will be needed – from the app, to the extension's background.js script, and vice versa. However, it seems when Safari receives the message from the app, it activates – that is, it becomes the frontmost macOS application. This will not be appreciated by the user who is writing email. This activation seems to be triggered by something within Safari, because it occurs even if I comment out all of the JavaScript and HTML code in the extension. It occurs whether I send 150 bytes or 150 MB of data, although in the latter case it occurs about 5 seconds after the message is sent, indicating that Safari is apparently buffering the message or something before activating – even if the background script has no message handler because the call to addListener() is commented out. Should I file a bug with my minimal project, or have I overlooked some way to prevent this activation of Safari?
Asked
Last updated .
Post marked as unsolved
131 Views

How to wait for content scripts to load

In her WWDC20 talk, Ellie Epskamp-Hunt mentioned in passing that you should assume that just because DOMContentLoaded has occurred that the script is loaded (for example, user might have to give it permission to load). But she doesn't say how you should determine that the script has loaded. How should you do that?
Asked
by jackrg.
Last updated .
Post marked as solved
522 Views

Xcode 12 Web Extension Converter Tool Not Found

I downloaded and installed the Xcode 12 Beta in hopes of trying out the Web Extension converter tool. I ran: xcrun safari-web-extension-converter /path/to/my/extension and got the following error: xcrun: error: sh -c '/Applications/Xcode.app/Contents/Developer/usr/bin/xcodebuild -sdk /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk -find safari-web-extension-converter 2> /dev/null' failed with exit code 17664: (null) (errno=No such file or directory) xcrun: error: unable to find utility "safari-web-extension-converter", not a developer tool or in PATH This seems to indicate I'm running the Xcode 11 version of xcrun (which I also have on my machine) which doesn't have the tool. The path to xcrun was /usr/bin/xcrun. How do I run the 12 Beta version of xcrun so I can run the Converter tool? Or do I need to uninstall v11? I thought you could run both at the same time. Thanks! Chris
Asked
by cweirup.
Last updated .
Post marked as unsolved
157 Views

How can my WKWebView app support Safari Extensions?

I have an app that primarily revolves around a WKWebView. A community has created quite a few browser extensions around the website that my app as a client for. I would love to allow users to incorporate those extensions easily. Is there a way to do that?
Asked
Last updated .