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?
Explore the integration of web technologies within your app. Discuss building web-based apps, leveraging Safari functionalities, and integrating with web services.
Selecting any option will automatically load the page
Post
Replies
Boosts
Views
Activity
We have an ObjC-based Mac App utility. A fair fraction of the functionality is built in JavaScript and resides in a couple of WKWebViews so that we can more easily share code with other platforms. Because it is a utility, usually the application will be hidden or at least not the frontmost application. But if the user hits a hotkey or provides certain other inputs, the app should respond immediately with a series of actions.
In the Obj-C part of the code, we can do this to alert the system that our non-visible, non-active, application is doing something in response to the user input:
[[NSProcessInfo processInfo] beginActivityWithOptions: NSActivityUserInitiatedAllowingIdleSystemSleep reason: @"Do the Thing"]
To get the JavaScript to do the work needed, we call evaluateJavaScript:completionHandler: on one of the WKWebViews. The JavaScript performs a series of computations, then uses window.webkit.messageHandlers.xxxx.postMessage to return results to the ObjectiveC code, which then takes action based on various SDKs, and the user sees the result.
The problem we are encountering is relatively infrequent, but it appears that macOS puts the 'Web Content' process (which every WKWebView has) to sleep, and sometimes delays of many seconds (sometimes over 15 seconds) occur between the evaluateJavaScript:completionHandler: call and the postMessage response. These observed delays are not related to complexity of the JavaScript computations or the amount of data being processed. Using the Console, we can see that evaluateJavaScript:completionHandler: seems to result in this message:
0x104682280 - [PID=0, throttler=0x1046e8498] ProcessThrottler::Activity::Activity: Starting background activity / 'WebPageProxy::runJavaScriptInMainFrameScriptWorld'
Then shortly afterward:
0x104682280 - [PID=0, throttler=0x1046e8498] ProcessThrottler::Activity::invalidate: Ending background activity / 'WebPageProxy::runJavaScriptInMainFrameScriptWorld'
So it seems that evaluateJavaScript:completionHandler: "wakes up" the WKWebView similar to the beginActivityWithOptions:. But many parts of our computation do some work, then expect the next "tick" in JavaScript to continue using the partial result to produce more work. I suspect that the delays are related to the WKWebView being put "back to sleep" before all the "next tick" code executes.
Because these actions are taken in response to user invocation, delays of more than a fraction of a second are instantly noticeable and result in user dismay.
Are there any configuration settings that can prevent the 'Web Content' process from going to sleep? Or (better) techniques or mechanisms that would force the process to "stay awake longer"? (Keeping in mind that the WKWebView is likely not visible, and/or the containing window may be hidden.)
I'm converting a Chrome Extension to a Safari Web Extension, I found it's not easy to get favicon of current tab/url natively.
The tab object in Safari doesn't have favIconUrl.
{
	"id": 121,
	"index": 6,
	"active": true,
	"width": 1324,
	"audible": false,
	"url": "https://github.com/",
	"mutedInfo": {
		"muted": false
	},
	"windowId": 2,
	"title": "GitHub",
	"incognito": false,
	"pinned": false,
	"height": 935,
	"highlighted": true,
	"status": "complete"
}
		
2. I didn't find Safari has similar thing like chrome://favicon
3. I found Safari's favicon caches in ~/Library/Safari/Favicon Cache/favicons but have no idea how to use them in Safari Web Extension.
Hello everyone.
I have a very strange behavior with smart app banners in Safari.
When I don't have installed app on my phone, I can't see the banner on our product main page. When I installed the app, I can see the banner, which allows me to go directly to the app. When I put any other app's ID in the meta tag it works perfectly even if I don't have its installed app.
So the code is right, what can be the reason of this behavior? Any settings of the app are required?
Is it possible to open the native app from a web extension?
I have tried creating a new tab that uses the app's URL scheme but the UI asking the user to open the app is not shown until the new page UI is dismissed.
Creating a tab with an HTTPS URL that the app is setup to handle does not work and always the link in a new tab.
I tried sending a message to the app extension and using NSExtensionContext.open(_:completionHandler:) but the URL is not opened and the closure received false, indicating it was not handled.
Having the option to link back to the native app would be very useful.
The extension popups don't seem to support the dark mode media query.
The only way the query gets detected is when a color-scheme is added:
<meta name="color-scheme"content="light dark">
I have a web extension that I want to send data to, and receive a response containing modified data.
My understanding is that the native app is only contactable by a background script. How does a webpage contact the background script?
One answer is by adding a content script, which is able to communicate with the background script using browser.native.sendMessage(). Unfortunately this triggers a warning that "this extension can read and alter web pages".
I do not want to read and alter web pages, nor do I want users to be concerned about a permission the app doesn't need. I just want to receive data, and then return a response.
What API should I be using to achieve this?
Hello,
We do not have explicitly set it our website, but still Smart Banner appears since we have universal link setup. (current URL matches the universal link patterns set in your apple-app-site-associations file ). Also, I understand it appears only for users having our app installed.
We do not want to show this banner in any case. is there any way to choose not to show the app banner? either setting additional meta or any other way would work.
regards,
Hussain
I am new to PHP. I have developed my own web site with a lot of javascript in simple HTML files. I want to do some extensions with PHP but I can't make a simple web page function. I am sure something simple is wrong. Help!
Here is the test web page I made: hello.html
<html>
<head>
<title>Hello World</title>
</head>
<body>
<?php echo 'Hello World!'; ?>
</body>
</html>
Pointing Safari at hello.html gives me a new tab with the correct title, but no "Hello World" in the page itself.
Here is the output of php --version:
WARNING: PHP is not recommended
PHP is included in macOS for compatibility with legacy software.
Future versions of macOS will not include PHP.
PHP 7.3.24-(to be removed in future macOS) (cli) (built: Jun 17 2021 21:41:13) ( NTS )
Copyright (c) 1997-2018 The PHP Group
Zend Engine v3.3.24, Copyright (c) 1998-2018 Zend Technologies
I have a Safari Web Extension that successfully receives a message from a webpage and returns a response.
I now want to add a user interface to the Safari Web Extension. How do I do this?
I have modified the default template code as follow to add an NSAlert for testing. The modal runs, but no alert ever appears, and the code remains stuck at runModal.
What is the correct way to add a UI to a webextension?
- (void)beginRequestWithExtensionContext:(NSExtensionContext *)context {
id message = [context.inputItems.firstObject userInfo][SFExtensionMessageKey];
NSLog(@"Received message from browser.runtime.sendNativeMessage: %@", message);
NSAlert* alert = [[NSAlert alloc]init];
[alert setMessageText:message[@"request"]];
[alert setInformativeText:@"Hello"];
[alert runModal];
NSExtensionItem *response = [[NSExtensionItem alloc] init];
response.userInfo = @{ SFExtensionMessageKey: @{ @"id": message[@"id"], @"uuid": message[@"uuid"], @"contentType": message[@"contentType"], @"response": message[@"request"] } };
[context completeRequestReturningItems:@[ response ] completionHandler:nil];
}
@end
Hello
I have a webrtc-based web app that is loaded inside a WKWebView.
The web app gets loaded just fine in our iOS App running WKWebView on an iPad with iOS 15.1.
We are using the exact same app, built for Mac Catalyst. However, on the Mac version, the web app gets loaded but the RTCPeerConnection object is undefined.. Meaning that our web app assumes that WebRTC is not available in that browser.
Isn't the native app supposed to work the exact same on iOS and MacOS? Is the Mac version of WKWebView more limited than its iOS counterpart ?
Is there any resource that states exactly what is supported in WKWebview in each platform?
Thanks
I wrote a code like the example below to execute javascript code that has no return value.
let webView: WKWebView
// after load complete
let result = await webView.evaluateJavascript("someFunction()") // :0: Fatal error: Unexpectedly found nil while implicitly unwrapping an Optional value
but when i use method with completion handler manner, it doesn't be crashed. but Xcode enforces me to use 'await' keyword and warning is bordering me
await webView.evaluateJavaScript("someFunction()", completionHandler: nil) // warning: Consider using asynchronous alternative function
The differnce I found is the different signature. Completion handler version has Optional result type, but async/await version has just Any result type
func evaluateJavaScript(_ javaScriptString: String,
completionHandler: ((Any?, Error?) -> Void)? = nil)
func evaluateJavaScript(_ javaScriptString: String) async throws -> Any
my Xcode version is 13.2.1. Hope to fix it soon.
Hi there,
I'm experiencing several crashes on JavaScriptCore pas_panic_on_out_of_memory_error, only on devices with tvOS 15.4 and 15.4.1. This happens with users using the app for several hours as well as 5 seconds after launching the app.
Devices: AppleTV6,2 and AppleTV5,3
Thread 14 —
JavaScriptCore pas_panic_on_out_of_memory_error (JavaScriptCore)
JavaScriptCore bmalloc_try_iso_allocate_impl_impl_slow (JavaScriptCore)
JavaScriptCore bmalloc_heap_config_specialized_local_allocator_try_allocate_small_segregated_slow (JavaScriptCore)
JavaScriptCore bmalloc_allocate_impl_casual_case (JavaScriptCore)
JavaScriptCore ***::String::String(char16_t const*, unsigned int) (JavaScriptCore)
JavaScriptCore JSC::LiteralParser<char16_t>::parsePrimitiveValue(JSC::VM&) (JavaScriptCore)
JavaScriptCore JSC::LiteralParser<char16_t>::parse(JSC::ParserState) (JavaScriptCore)
JavaScriptCore JSC::jsonProtoFuncParse(JSC::JSGlobalObject*, JSC::CallFrame*) (JavaScriptCore)
JavaScriptCore llint_entry (JavaScriptCore)
JavaScriptCore llint_entry (JavaScriptCore)
JavaScriptCore llint_entry (JavaScriptCore)
JavaScriptCore llint_entry (JavaScriptCore)
JavaScriptCore vmEntryToJavaScript (JavaScriptCore)
JavaScriptCore JSC::Interpreter::executeCall(JSC::JSGlobalObject*, JSC::JSObject*, JSC::CallData const&, JSC::JSValue, JSC::ArgList const&) (JavaScriptCore)
JavaScriptCore JSC::boundThisNoArgsFunctionCall(JSC::JSGlobalObject*, JSC::CallFrame*) (JavaScriptCore)
JavaScriptCore vmEntryToNative (JavaScriptCore)
JavaScriptCore JSC::Interpreter::executeCall(JSC::JSGlobalObject*, JSC::JSObject*, JSC::CallData const&, JSC::JSValue, JSC::ArgList const&) (JavaScriptCore)
JavaScriptCore JSC::profiledCall(JSC::JSGlobalObject*, JSC::ProfilingReason, JSC::JSValue, JSC::CallData const&, JSC::JSValue, JSC::ArgList const&) (JavaScriptCore)
JavaScriptCore JSObjectCallAsFunction (JavaScriptCore)
JavaScriptCore -[JSValue invokeMethod:withArguments:] (JavaScriptCore)
ITMLKit -[IKJSObject invokeMethod:withArguments:] (ITMLKit)
ITMLKit -[IKJSEventListenerObject invokeMethod:withArguments:thenDispatchEvent:extraInfo:] (ITMLKit)
ITMLKit __43-[IKJSXMLHTTPRequest setRequestReadyState:]_block_invoke (ITMLKit)
ITMLKit -[IKAppContext _doEvaluate:] (ITMLKit)
ITMLKit -[IKAppContext _evaluate:] (ITMLKit)
ITMLKit __41-[IKAppContext evaluate:completionBlock:]_block_invoke (ITMLKit)
ITMLKit -[IKAppContext _sourcePerform] (ITMLKit)
ITMLKit -[IKConcurrentEvaluator lockSchedulingForEvaluation:] (ITMLKit)
ITMLKit IKRunLoopSourcePerformCallBack (ITMLKit)
CoreFoundation __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ (CoreFoundation)
CoreFoundation __CFRunLoopDoSource0 (CoreFoundation)
CoreFoundation __CFRunLoopDoSources0 (CoreFoundation)
CoreFoundation __CFRunLoopRun (CoreFoundation)
CoreFoundation CFRunLoopRunSpecific (CoreFoundation)
ITMLKit -[IKAppContext _jsThreadMain] (ITMLKit)
Foundation __NSThread__start__ (Foundation)
libsyste...ad.dylib _pthread_start (libsystem_pthread.dylib)
libsyste...ad.dylib thread_start (libsystem_pthread.dylib)
This issue seems very similar to this existing thread, although not sure its related
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!
As with the adoption of MV3 standards among all major browser vendors that allow browser extensions at the client-side, I understand that this is the same with Safari as well, as mentioned here (https://www.wwdcnotes.com/notes/wwdc22/10099/). However, as with Firefox, browsers may choose to adopt them incompletely and with few changes. I had a few questions regarding how Safari views this transition and what would be the next steps from here.
Thus, it would be really great if the browser team could provide your insights on any or all of the following points:
Would Safari adopt the exact standards proposed by the Chromium ecosystem such as with functionalities like header-based modifications in the coming days.
What would be the general timeline be for this in general?
Does this also translate to the fact that existing standards with MV2 standards would not be allowed to operate any further, as with the timeline with Chromium?
Regards
Hello,
I'm not able to get the webauthn attestation statement using the option (attestation.direct) on Safari. The answer I get is a fmt of none and a aaguid of zeros.
The same code works on Chrome and I was able to get a none zero aaguid and a packed fmt attestation.
Can you explain why this does not work on Safari ?
Thank you.
I’m deploying a pac file through jamf using the auto global http proxy. The purpose of this file is to block some traffic on the network level. We’re deploying the pac on iPhones.
I tried to use
|| shExpMatch(url, “*.pdf”)
to block any url with .pdf but iOS seems to just skip that line without implementing it. Am I doing something wrong or is there an apple specific function that I should use?
thanks
Everything was working fine for 4 years.
But since Ventura, when the WKWebView is in focus, the keyDown event are not happening. Not only they don't fire inside of web page input box, but they won't register in the app either.
As long as a WKWebView is in focus, the keyboard events won't work.
The app does not receive the key events, and the web page will not receive the js events keyDown and friends. This is particularly painful with auto complete input box.
Test with an empty project with only a WKWebView with this page
https://www.toptal.com/developers/keycode/for/d
It does work fine on iPhone and iPad.
Message to Apple : You force us to use your Safari engine, yet it is always broken. Don't wait for 8 months to fix it this time, we would be tempted to go full web and skip native app with all the store certification problems.
I'd like to know the install state of my iOS safari extension in the associated swift app. Is there any way to get this? As we have seen it is available for macOS here, is there anyway to know iOS Safari extension is enabled or not?
Thanks
version: iOS 16.4(20E5239a)
both on my iphone and Simulator,Safari -> develop shows "no inspectable applications"