Post not yet marked as solved
I have been trying to use the WKWebView in my SwiftUI app. To do that, I created a wrapper that allows me to customize my WKWebView.
This view should serve a single purpose : I need to grab an authentication token from a callback.
That it why I need the last method you can find at the bottom of my CustomWebView class:
import Foundation
import SwiftUI
import WebKit
struct WebView : UIViewRepresentable {
let request: URLRequest
func makeUIView(context: Context) -> WKWebView {
return CustomWebView().webView
}
func updateUIView(_ uiView: WKWebView, context: Context) {
uiView.load(request)
}
}
class CustomWebView: UIViewController, WKNavigationDelegate {
// Create a custom WKWebView that supports Javascript
public let webView: WKWebView = {
let prefs = WKWebpagePreferences()
prefs.allowsContentJavaScript = true
let config = WKWebViewConfiguration()
config.defaultWebpagePreferences = prefs
let webView = WKWebView(frame: .zero,
configuration: config)
return webView
}()
override func viewDidLoad() {
super.viewDidLoad()
title = "Sign In"
}
// Grab the authentication token
func webView(_ webView: WKWebView, didStartProvisionalNavigation navigation: WKNavigation!) {
guard let url = webView.url else {
return
}
// Exchange the code for the authentication access token
guard let code = URLComponents(string: url.absoluteString)?.queryItems?.first(where: { $0.name == "code" })?.value else {
return
}
print("Code: \(code)")
}
}
If I don't use this last method, my code runs without any error.
But as soon as I run it, the callback loads correctly, but I get multiple errors in the console:
2022-06-21 16:50:17.985187+0200 MyAppsName[39758:7506939] [assertion] Error acquiring assertion: <Error Domain=RBSServiceErrorDomain Code=1 "target is not running or doesn't have entitlement com.apple.runningboard.assertions.webkit" UserInfo={NSLocalizedFailureReason=target is not running or doesn't have entitlement com.apple.runningboard.assertions.webkit}>
2022-06-21 16:50:17.985870+0200 MyAppsName[39758:7506939] [ProcessSuspension] 0x1180642a0 - ProcessAssertion: Failed to acquire RBS assertion 'ConnectionTerminationWatchdog' for process with PID=39759, error: Error Domain=RBSServiceErrorDomain Code=1 "target is not running or doesn't have entitlement com.apple.runningboard.assertions.webkit" UserInfo={NSLocalizedFailureReason=target is not running or doesn't have entitlement com.apple.runningboard.assertions.webkit}
I tried to look for specific lines in "Signing & Capabilities" that could unlock any WebKit capabilities, but I can't find anything. Does anyone have a lead?
Post not yet marked as solved
I have an idea of an app that I need to enquire about its acceptance in the Apple app store.
The idea of the app is I am a middle man between the customer and the store, the app will have multiple online stores, the stores will be presented in the app as webview (Using WKWebView) of their websites then the app will identify the products on the website so the customer can add the product in the app's cart, after that the customer will submit the order inside the app.
I'm building the app because in my country Yemen does not have online stores and the closest way is by ordering from online stores in the neighbor countries but these stores don't deliver to Yemen so I am acting as the middleman to deliver to Yemen .
Post not yet marked as solved
in iOS12 we use WKURLSchemeHandler to handle "http" request ,but it raise the exception here is the log
if I keep the WKURLSchemeTask then the request can not be stoped,it keep loadding
above iOS13.0 every thing is ok,any help?
Post not yet marked as solved
hello.
Switch the app to background when loading a webpage in webview,
webpage's JavaScript will stop working.
Resume the app webpage fails to load and the screen is not drawn.
Any solution?
Post not yet marked as solved
I’m using Swift Playground on my iPad 9th gen. I’m trying to implement a website that uses camera inside of the Swift app. Can someone help me out pointing to what should I use to access the live video?
Post not yet marked as solved
The following is the stack trace.
Call graph:
2246 Thread_14270191 DispatchQueue_1: com.apple.main-thread (serial)
+ 2246 start (in dyld) + 462 [0x1125c851e]
+ 2246 WebKit::XPCServiceMain(int, char const**) (in WebKit) + 85 [0x7ff911bbb759]
+ 2246 xpc_main (in libxpc.dylib) + 99 [0x7ff80d4af239]
+ 2246 _xpc_objc_main (in libxpc.dylib) + 773 [0x7ff80d4af816]
+ 2246 -[NSRunLoop(NSRunLoop) run] (in Foundation) + 76 [0x7ff80e70e8d7]
+ 2246 -[NSRunLoop(NSRunLoop) runMode:beforeDate:] (in Foundation) + 216 [0x7ff80e683d9a]
+ 2246 CFRunLoopRunSpecific (in CoreFoundation) + 562 [0x7ff80d82f7ac]
+ 2237 __CFRunLoopRun (in CoreFoundation) + 1276 [0x7ff80d830368]
+ ! 2237 __CFRunLoopServiceMachPort (in CoreFoundation) + 319 [0x7ff80d831cdd]
+ ! 2237 mach_msg (in libsystem_kernel.dylib) + 56 [0x7ff80d72ece8]
+ ! 2237 mach_msg_trap (in libsystem_kernel.dylib) + 10 [0x7ff80d72e97a]
+ 8 __CFRunLoopRun (in CoreFoundation) + 2010 [0x7ff80d830646]
+ ! 3 __CFRunLoopDoTimers (in CoreFoundation) + 307 [0x7ff80d849ef8]
+ ! : 2 __CFRunLoopDoTimer (in CoreFoundation) + 923 [0x7ff80d84a388]
+ ! : | 2 __CFRUNLOOP_IS_CALLING_OUT_TO_A_TIMER_CALLBACK_FUNCTION__ (in CoreFoundation) + 20 [0x7ff80d84a899]
+ ! : | 1 WebCore::timerFired(__CFRunLoopTimer*, void*) (in WebCore) + 18 [0x7ff90edb9a62]
+ ! : | + 1 ***::AutodrainedPool::AutodrainedPool() (in JavaScriptCore) + 0 [0x7ff825ef0050]
+ ! : | 1 WebCore::timerFired(__CFRunLoopTimer*, void*) (in WebCore) + 31 [0x7ff90edb9a6f]
+ ! : | 1 ***::Detail::CallableWrapper<WebCore::ThreadTimers::setSharedTimer(WebCore::SharedTimer*)::$_0, void>::call() (in WebCore) + 148 [0x7ff91092a534]
+ ! : 1 __CFRunLoopDoTimer (in CoreFoundation) + 104 [0x7ff80d84a055]
+ ! : 1 CFRetain (in CoreFoundation) + 65 [0x7ff80d7b598e]
+ ! 2 __CFRunLoopDoTimers (in CoreFoundation) + 191 [0x7ff80d849e84]
+ ! : 1 __NSArrayM_new (in CoreFoundation) + 50 [0x7ff80d7cf1cc]
+ ! : | 1 __CFAllocateObject (in CoreFoundation) + 15 [0x7ff80d7b58ef]
+ ! : | 1 class_createInstance (in libobjc.A.dylib) + 64 [0x7ff80d5fe1da]
+ ! : | 1 _malloc_zone_calloc (in libsystem_malloc.dylib) + 60 [0x7ff80d59eb75]
+ ! : | 1 szone_malloc_should_clear (in libsystem_malloc.dylib) + 66 [0x7ff80d5837d2]
+ ! : | 1 tiny_malloc_should_clear (in libsystem_malloc.dylib) + 32 [0x7ff80d584765]
+ ! : 1 objc_msgSend (in libobjc.A.dylib) + 26 [0x7ff80d5fe41a]
+ ! 2 __CFRunLoopDoTimers (in CoreFoundation) + 205 [0x7ff80d849e92]
+ ! : 1 -[__NSArrayM insertObject:atIndex:] (in CoreFoundation) + 399 [0x7ff80d7d27ee]
+ ! : | 1 _platform_bzero$VARIANT$Haswell (in libsystem_platform.dylib) + 0 [0x7ff80d77e600]
+ ! : 1 -[__NSArrayM insertObject:atIndex:] (in CoreFoundation) + 257 [0x7ff80d7d2760]
+ ! 1 __CFRunLoopDoTimers (in CoreFoundation) + 222 [0x7ff80d849ea3]
+ 1 __CFRunLoopRun (in CoreFoundation) + 1280 [0x7ff80d83036c]
2246 Thread_14270227: WebCore: Scrolling
+ 2246 thread_start (in libsystem_pthread.dylib) + 15 [0x7ff80d766f6b]
+ 2246 _pthread_start (in libsystem_pthread.dylib) + 125 [0x7ff80d76b4e1]
+ 2246 ***::wtfThreadEntryPoint(void*) (in JavaScriptCore) + 9 [0x7ff825ef0039]
+ 2246 ***::Thread::entryPoint(***::Thread::NewThreadContext*) (in JavaScriptCore) + 246 [0x7ff82711ffa6]
+ 2246 ***::RunLoop::run() (in JavaScriptCore) + 19 [0x7ff827109c53]
+ 2246 CFRunLoopRun (in CoreFoundation) + 40 [0x7ff80d8b782b]
+ 2246 CFRunLoopRunSpecific (in CoreFoundation) + 562 [0x7ff80d82f7ac]
+ 2246 __CFRunLoopRun (in CoreFoundation) + 1276 [0x7ff80d830368]
+ 2246 __CFRunLoopServiceMachPort (in CoreFoundation) + 319 [0x7ff80d831cdd]
+ 2246 mach_msg (in libsystem_kernel.dylib) + 56 [0x7ff80d72ece8]
+ 2246 mach_msg_trap (in libsystem_kernel.dylib) + 10 [0x7ff80d72e97a]
1 Thread_14270224 DispatchQueue_13: com.apple.root.default-qos (concurrent)
1 start_wqthread (in libsystem_pthread.dylib) + 15 [0x7ff80d766f57]
1 _pthread_wqthread (in libsystem_pthread.dylib) + 326 [0x7ff80d767fd0]
1 _dispatch_workloop_worker_thread (in libdispatch.dylib) + 753 [0x7ff80d5c0eee]
1 _dispatch_mach_invoke (in libdispatch.dylib) + 484 [0x7ff80d5c9b77]
1 _dispatch_lane_serial_drain (in libdispatch.dylib) + 342 [0x7ff80d5b61cd]
1 _dispatch_mach_msg_invoke (in libdispatch.dylib) + 445 [0x7ff80d5c9041]
1 _dispatch_client_callout4 (in libdispatch.dylib) + 9 [0x7ff80d5b03b1]
1 _xpc_connection_mach_event (in libxpc.dylib) + 1382 [0x7ff80d4a5947]
1 _xpc_connection_call_event_handler (in libxpc.dylib) + 56 [0x7ff80d4a6b6c]
1 WebKit::LaunchServicesDatabaseManager::handleEvent(NSObject<OS_xpc_object>*) (in WebKit) + 176 [0x7ff911a6b0de]
1 -[LSDatabaseContext(WebKitChangeTracking) observeDatabaseChange4WebKit:] (in LaunchServices) + 519 [0x7ff80dd8e80a]
1 _LSDatabaseCreate (in LaunchServices) + 68 [0x7ff80dcc7a7c]
1 _LSDatabaseCreateWithAccessQueue (in LaunchServices) + 769 [0x7ff80dd81865]
1 _CSGetStringForCharacters (in CoreServicesStore) + 56 [0x7ff8100cc7af]
1 CSStore2::String::Find(CSStore2::Store&, char const*, unsigned int) (in CoreServicesStore) + 554 [0x7ff8100cca02]
1 invocation function for block in CSStore2::String::Find(CSStore2::Store&, char const*, unsigned int) (in CoreServicesStore) + 27 [0x7ff8100ccbfe]
Looks like the last thread is stuck in a database read call.
Can anyone please help in a workaround for this?
Post not yet marked as solved
(TL;DR at bottom)
Hi everyone,
Going into this I'd like to say first that I am by no means a web developer and I know nothing about how browsers are built.
I've got a really specific use case that requires me to disable hardware acceleration on my browser. When away from each other, my partner and I like to watch shows and movies together over Zoom's Screen Sharing. For a while I've just been using Chrome to handle that and Safari for everything else. The reason I use Chrome for this is that when I turn off hardware acceleration on Chrome it lets me share my screen on websites like Netflix, Hulu, etc. without an empty screen appearing.
But I just don't want Chrome on my computer anymore, if I can somehow get hardware acceleration off on Safari. It's nice to just use one browser for everything, especially since Safari is great for my battery.
I looked into this online and something I read says that you just aren't able to do this anymore in Safari but then I asked my friend who does dabble in this sort of stuff and he says there's probably something under: Develop --> Experimental Features that I can mess around with to turn it off.
If anybody has pointers for me, I'd really appreciate it! Thanks :-)
TL;DR - I'm looking for a way to turn off hardware acceleration on Safari like you are able to do in Chrome
I am trying to load a WKWebView in my MacOS Authorization Plugin view. All I get is a blank white screen. But when I initiate the login (i.e, pass on the login mechanism to the next system login mechanisms), the webview starts to load. I added WKNavigationDelegate methods to see when they are getting called. All delegate methods (didCommit, didFinish etc..) are getting called after the current login mechanism had passed.
I want to load the WKWebView in my custom login mechanism. What should I do?
Post not yet marked as solved
unload, pagehide event works in wkwebview. However, when i try to add beforeunload event listener, it won't get called in wkwebview.
Post not yet marked as solved
When I learned to use webview in my app, just added a webview and detected a memory leak,
import SwiftUI
import WebKit
struct SWKWebView: UIViewRepresentable {
@Binding var url: String?
func makeUIView(context: Context) -> WKWebView {
let webview = WKWebView()
webview.navigationDelegate = context.coordinator
return webview
}
func updateUIView(_ uiView: WKWebView, context: Context) {
if let url = url, let requetURL = URL(string: url) {
uiView.load(URLRequest(url: requetURL))
}
}
func makeCoordinator() -> Coordinator {
Coordinator()
}
class Coordinator: NSObject,WKNavigationDelegate {
func webView(_ webView: WKWebView, didFinish navigation: WKNavigation!) {
webView.evaluateJavaScript("document.title") { (result, error) in
print("didFinish:\(String(describing: result ?? ""))")
}
}
}
}
struct TTTest: View {
@State var url: String? = "https://www.google.com"
var body: some View {
SWKW

ebView(url: $url)
}
}
Post not yet marked as solved
Dear all,
I'm using WKWebView to connect a URL2. The webview will load a request which contains http header.
But I can't have it works. There is a message below came from Output window.
[Process] 0x1260c0218 - [pageProxyID=13, webPageID=14, PID=15418] WebPageProxy::didFailProvisionalLoadForFrame: frameID=3, domain=WebKitErrorDomain, code=102, isMainFrame=1
I've searched some relevant solutions to solve it.
I've added the privilege in Info.plist, like Allow Arbitrary Loads, Allow Arbitrary Loads in Web Content.
Also I've added my URL in exception domain.
But all of these solutions are still not able to work.
Do I miss any solution? Please help me out. Thank you in advance.
BTW, it works if the WKWebView connect to URL1. But the URL2 doesn't. The prefix is https, so it shouldn't have http problem.
Post not yet marked as solved
Our TPP excludes our own processes from oversight, which makes some things very easy. Only I just found out that when our app uses a WKWebView... it's very securely shuffled off into its own process. With its own signing identifier. And a ppid of launchd.
How could I tell that a com.apple.WebKit.Networking process is related to our process? (I note that the Endpoint Security Framework has added a "responsible" audit token, presumably for this sort of situation.)
Post not yet marked as solved
My app loads a webview using WKWebView class, so it uses safari to render the web content. However, the content is quite complex and Chrome does perform considerably better than Safari. So i wonder if would be possible to use Chrome engine in WKWebview, instead of Safari.
Post not yet marked as solved
Why is it that pdf files in ownCloud (https://owncloud.com) cannot be zoomed by pinch-in and pinch-out using WKWebView but they can be zoomed by using SFSafariViewController?
Is this problem related to WebKit or only WKWebView?
The only way that it can be zoomed in is by using a
menu like the one inside the red rectangle.
Post not yet marked as solved
Safari freezes when we try to use canvas.putImageData to draw image to canvas. Safari version is 15. happen in MacOs and iPad.
I have made a reproduction here.
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<style>
* { padding: 0; margin: 0 }
html,body {
width: 100%;
height: 100%;
}
</style>
</head>
<body>
<div>
<button id="btn">
get random number
</button>
<button id="btn2">
open a tab
</button>
</div>
</body>
</html>
<script>
let i = 1;
const btn = document.querySelector('#btn');
const btn2 = document.querySelector('#btn2');
const urls = ['https://st-gdx.dancf.com/gaodingx/0/uxms/design/20210914-213851-d8b8.png'];
urls.length = 1;
btn.onclick = () => {
console.time('click');
btn.innerHTML = Math.random();
console.timeEnd('click');
}
btn2.onclick = () => {
window.open(window.location.href);
}
for(let i = 0; i < urls.length; i++) {
const img = new Image();
img.src = urls[i];
img.crossOrigin = 'anycrossorign';
img.onload = () => {
const canvas = document.createElement('canvas');
canvas.width = 1000;
canvas.height = 1000;
const ctx = canvas.getContext('2d');
ctx.drawImage(img, 0, 0);
const pixels = ctx.getImageData(0, 0, 1000, 1000);
for (let i = 0; i < pixels.data.length; i += 4) {
pixels.data[i + 3] = 255;
}
ctx.putImageData(pixels, 0, 0, 0, 0, 1000, 1000);
document.body.appendChild(canvas);
}
}
</script>
Post not yet marked as solved
We have an App that uses WKWebview component on Mac OS.
One of our customers recently noticed the keyboard input in the WKWebview is not working correctly.
When the Delete or up/down/left/right keys of keyboard are used in a text field they do not give the normal action, but instead a strange symbol is added to the text field.
So it looks like a bug was introduced in the keyboard handling of WKWebview.
We have checked this on two Mac OS 12.3.1 systems and both show this issue.
On another system running Mac OS 10.15.4 we don't see this issue.
Post not yet marked as solved
I am trying to load a file from memory and preview it in a WebView in SwiftUI.
I already made the same procedure in Swift and it's working, but it's not working in SwiftUI.
Files and successfully save to memory and retrieved, but I am getting this error:
WebPageProxy::didFailProvisionalLoadForFrame: frameID=3, domain=NSPOSIXErrorDomain, code=1, isMainFrame=1
This function will return the WebView
private func createURL() -> AnyView{
DocumentManager.shared.save(text: "Hey dear", toDirectory: DocumentManager.shared.documentDirectory(), withFileName: "test345.docx")
let fileURL = DocumentManager.shared.read(fromDocumentsWithFileName: "test345.docx")
return AnyView(Webview(url: URL(fileURLWithPath: fileURL)))
}
This is my UIViewRepresentable:
struct Webview: UIViewRepresentable {
let url: URL
let navigationHelper = WebViewHelper()
func makeUIView(context: UIViewRepresentableContext<Webview>) -> WKWebView {
let webview = WKWebView()
webview.navigationDelegate = navigationHelper
let request = NSURLRequest(url: url as URL) as URLRequest
webview.load(request)
return webview
}
func updateUIView(_ webview: WKWebView, context: UIViewRepresentableContext<Webview>) {
let request = URLRequest(url: self.url, cachePolicy: .returnCacheDataElseLoad)
webview.load(request)
}
}
And this is my WebView helper class:
class WebViewHelper: NSObject, WKNavigationDelegate {
func webView(_ webView: WKWebView, didFinish navigation: WKNavigation!) {
print("webview didFinishNavigation")
}
func webView(_ webView: WKWebView, didStartProvisionalNavigation navigation: WKNavigation!) {
print("didStartProvisionalNavigation")
}
func webView(_ webView: WKWebView, didCommit navigation: WKNavigation!) {
print("webviewDidCommit")
}
func webView(_ webView: WKWebView, didReceive challenge: URLAuthenticationChallenge, completionHandler: @escaping (URLSession.AuthChallengeDisposition, URLCredential?) -> Void) {
print("didReceiveAuthenticationChallenge")
completionHandler(.performDefaultHandling, nil)
}
}
Post not yet marked as solved
Hi,
I think I never thought about this but... let's say I have my iOS app (swift) and I have a ViewController with a WKWebView. If I open a link of a page with a pdf, where are the pdf and that page's files stored? Is there a way to clean the directory in which those files get stored? Is it something I shouldn't worry about?
Thanks in advance
Post not yet marked as solved
I'm adding a WKWebView to my (Mac) app, and it works fine except that the navigationDelegate is never called. Even stranger, if that delegate implements decidePolicyForNavigationAction, that method is never called either, but as a side effect the view now won't load any pages!
In detail: I've created a class implementing WKNavigationDelegate, I've implemented some of the methods, and assigned an instance to the view's navigationDelegate property. Easy stuff. I've done this in the past using the old-school WebView class. I've triple-checked my work.
As an experiment, I added a -respondsToSelector: method to my delegate class and made it log the selector. I see it being called several dozen times, with the selectors for all of the delegate methods and many other private(?) methods; so I know WebKit sees my object. It just never calls it at all.
My hunch so far is that this is an OS bug, that Apple no longer bothers to test WebKit APIs in Objective-C. I'd hate for that to be true.
(I realize Obj-C is basically deprecated nowadays. I'm using it because my non-UI code is all in C++, and it's vastly easier to integrate with C++ in Obj-C. To use Swift I'm going to have to wrap my API in C functions, yuck.)
I have a question very similar to this one, from 5 years ago:
https://developer.apple.com/forums/thread/75710
I have a macOS app, in which I have a webview, which loads a login page for the user.
The user can log in using an SSO, and the SSO login process might require verifying that a certificate is installed on the user's machine.
The certificate and the user login credentials aren't related to my app in any way. The certificate should be already installed at the Keychain.
My question is related to the function
webView(_ webView: WKWebView, didReceive challenge:)
Should I implement this function? As I said, the certificate is not related to my app, so it would be better to let the OS handle the challenge, if possible.
In case I have to implement this function, is there any way for my app to answer this challenge? Any example on how to do it?