Display web content in windows and implement browser features using WebKit.

Posts under WebKit tag

200 Posts
Sort by:

Post

Replies

Boosts

Views

Activity

Safari and WkWebView Memory Limit Causing App Interruptions
I'm working on a rather complex web application that includes 3D terrain, 2D mapping, and SVG animations. Both Safari and the Swift app I've built using WkWebKit reload the page after some period of time. Safari pops up a small text block that says: This webpage was reloaded because it was using significant memory. Yes. That's true. It's also true that the M1 Max Mac was in now way experiencing issues, nor were any of the other web pages running in other tabs or windows. The memory limit is simply too low for modern web apps. So far I've not found any way to adjust the parameters in Safari or WkWebView. Apple, help a brother out. It's not 1997 anymore. Web apps are big. And resetting them at some arbitrary point causes more problems that is solves. Anyone have any suggestions? Quinn, any way (other than casting a stone into the one-way abyss of Radar) of getting help from the big A here?
1
0
260
1w
WKWebView intercepting Https URL
I'm developing an application that utilizes WKWebView to display a webpage. My goal is to improve the performance and loading speed of this webpage by intercepting specific API calls and providing pre-stored JSON responses directly from within the app, ensuring the webpage renders instantaneously. The challenge I am encountering is the inability to intercept HTTPS URL schemes directly from WKWebView. Any insights or solutions from the community on how to effectively manage and overwrite these particular network requests would be greatly appreciated.
1
0
254
Oct ’24
WKWebView gpuProcessExited IdleExit Code=18
I'm injecting some javascript into a WKWebview on iOS. At a certain point the web view spits out these warnings into the console and the javascript execution stops. 0x109018c40 - [PID=778] WebProcessProxy::gpuProcessExited: reason=IdleExit 0x109019200 - [PID=779] WebProcessProxy::gpuProcessExited: reason=IdleExit Failed to terminate process: Error Domain=com.apple.extensionKit.errorDomain Code=18 "(null)" UserInfo={NSUnderlyingError=0x303c3c060 {Error Domain=RBSRequestErrorDomain Code=3 "No such process found" UserInfo={NSLocalizedFailureReason=No such process found}}} I can't find any solution for this so am looking if anyone has any idea of what to try. None of the WKWebview delegate functions trigger when this occurs so I can't attempt to reload the webview at this stage
0
0
365
Oct ’24
Safari WKWebview local storage not being transferred to external Safari tab
Hi. I've noticed on both iOS 17 and iPadOS 16 that when an user opens a website in a WKWebview (e.g from Gmail), then requests it to be opened in the external Safari app (through the "compass" icon), their localStorage data is not transferred to the Safari tab. This behaviour breaks web experiences that rely on data being locally stored, e.g auth tokens or user identification data. It effectively stops users from being able to use some websites outside of an in-app context. I am aware of Webkit's tracking prevention mechanisms such as https://webkit.org/tracking-prevention/#partitioned-third-party-localstorage, but I don't think this should apply to this case. Here the user is navigating between two Safari tabs (one internal and one external) on the same domain, exact same URL, by pressing a native Safari webview icon. There is no third-party cross-domain tracking happening. Is this a bug or intended behaviour?
1
0
266
Oct ’24
Help by Swift Playground App
I would like to program an app in Swift Playground that displays WhatsApp Web in a webview, so to speak. But I keep seeing an error like in the screenshot. My Code: import SwiftUI import WebKit import PlaygroundSupport struct WebView: UIViewRepresentable { let url: URL func makeUIView(context: Context) -> WKWebView { let webView = WKWebView() let request = URLRequest(url: url) webView.load(request) return webView } func updateUIView(_ webView: WKWebView, context: Context) { } } struct ContentView: View { var body: some View { WebView(url: URL(string: "https://web.whatsapp.com")!) .edgesIgnoringSafeArea(.all) } } PlaygroundPage.current.setLiveView(ContentView())
0
0
199
Oct ’24
WKWebView default SameSite value for cookies is different in iOS18
In iOS18, WKWebView's default cookie SameSite value is Lax. Prior to iOS18, the default value is None. Is this intentional, or a bug? This change is not documented anywhere. I made a sample XCode project (ViewController code below) to show this change. It loads www.apple.com into a WKWebView and prints cookies. That site has several cookies, but it only explicitly sets SameSite to None for one cookie, s_vi. Every other cookie relies on default WKWebView behavior. When looking at cookies, either in the console or in Safari's Web Inspector, the SameSite value differs. If older than iOS18, every cookie has SameSite of None. If iOS18, all cookies except s_vi have SameSIte of Lax. I also tried manually setting the following cookies: testCookie-none with SameSite set to None testCookie-lax with SameSite set to Lax testCookie-strict with SameSite set to Strict testCookie- with SameSite set to an empty string When looking at these cookies, testCookie-none and testCookie- have their SameSite of None if older than iOS18, but are both Lax in iOS18. So, it seems we cannot manually set the SameSIte to None either. I realize updating the server to return the SameSite value would resolve this. However, in my app where I'm struggling with this issue, that server is Salesforce. Only they can update their response headers. Since this change isn't documented by Apple, I am assuming it is a bug and not intentional. Are there any workarounds? Any input by Apple on a fix? Below is the ViewController code, and images of the cookies in Safari's Web Inspector. import UIKit import WebKit class ViewController: UIViewController, WKNavigationDelegate { var webView: WKWebView! override func loadView() { // Create WKWebView let config = WKWebViewConfiguration() webView = WKWebView(frame: .zero, configuration: config) // Allow inspection in Safari debugger webView.isInspectable = true // Track the request to load our website webView.navigationDelegate = self // Manually add four cookies: // testCookie-none with SameSite set to None // testCookie-lax with SameSite set to Lax // testCookie-strict with SameSite set to Strict // testCookie- with SameSite set to an empty string addTestCookies() view = webView } override func viewDidLoad() { super.viewDidLoad() // Load a website let urlString = "https://www.apple.com" self.webView.load(URLRequest(url: URL(string:urlString)!)) } // Once the website loads, print the cookies. func webView(_ webView: WKWebView, didFinish navigation: WKNavigation!) { WKWebsiteDataStore.default().httpCookieStore.getAllCookies { cookies in for cookie in cookies { print(cookie) } } } /* Manually add the following cookies for domain .apple.com testCookie-none with SameSite set to None testCookie-lax with SameSite set to Lax testCookie-strict with SameSite set to Strict testCookie- with SameSite set to an empty string In older iOS versions, both testCookie-none and testCookie- will have their SameSite as none. In iOS18, no cookie will have SameSite as None. */ func addTestCookies() { let httpCookieStore = WKWebsiteDataStore.default().httpCookieStore for sameSitePolicy in ["none", "lax", "strict", ""] { httpCookieStore.setCookie(HTTPCookie(properties: [ HTTPCookiePropertyKey.path: "/", HTTPCookiePropertyKey.name: "testCookie-"+sameSitePolicy, HTTPCookiePropertyKey.value: "1", HTTPCookiePropertyKey.domain: ".apple.com", HTTPCookiePropertyKey.secure: true, HTTPCookiePropertyKey.sameSitePolicy: sameSitePolicy ])!) } } }
1
1
708
Oct ’24
faulty Transparent Video in iPhone browsers
I need to play a Video with transparent background on our website. It works perfectly on Windows, Mac & Android (in all browsers). On iPhone however, no matter what Browser, The transparent parts of the video act almost like an "overlay", making everything behind it a lot brighter. This effect gets worse, the higher I set the iPhone screen brightness. This is of course not the behavior I'm looking for. The Video Element has two listed sources. One .WEBM (VP8 with alpha channel) and one .MP4 (HEVC with alpha channel). I am sure, that something is wrong with the MP4 file, but I don't understand why it works in Safari on Mac, but doesn't on iPhone. Shouldn't they both play the same File? Here is my workflow: masking the subject in DaVinci Resolve exporting as QuickTime - Apple ProRes 444 - "Export Alpha" using Shutter Encoder (v15.7) to convert the file to H.265 (.mp4) under "Advanced Features": Hardware acceleration to "OSX VideoToolbox" & check "Enable alpha channel" also converting the first file to VP8 (.webm) with "Enable alpha channel" then adding the Videos to the website like this: <video height="450px" autoplay loop muted playsinline disablepictureinpicture> <source src="(url of the mp4)" type='video/mp4; codecs="hvc1"'> <source src="(url of the webm)" type="video/webm"> </video> Here is how it looks on Safari (Mac) This is what it looks like in any browser on iPhone I have re-exported, re-converted and re-implemented it multiple times and I just can't get it to work on iPhone. Does anyone have an idea, what the cause could be, or what I can do differently?
2
0
396
Oct ’24
WKWebView Synchronous Ajax/XmlHttpRequest timeout
PLATFORM AND VERSION iOS Development environment: Other: Xamarin iOS App Run-time configuration: iOS 14.4.2 and above DESCRIPTION OF PROBLEM We are using WKWebView control in our application. It loads a page, wherein there is a code which gets triggered to execute a Synchronous Ajax/XmlHttpRequest. This request needs about 1 min time to complete, but it gets aborted after 10 secs. Observed in iPhone 6S 14.4.2. Also seen the same behavior in the latest version of iPhone and iPad OS. Need help on the below points: How can I extend this timeout? Making it an Asynchronous call would have regression. Hence the ask for any other alternative to extend this timeout. STEPS TO REPRODUCE In the WKWebView have a webpage, which gives a Synchronous ajax/XmlHttpRequest call to a Web API, which takes more than 10 seconds to complete. The Ajax call sample code is as below, which uses jquery: var startTime = performance.now(); $.ajax({ async: false, // Synchronous ajax call type: "POST", url: "http://testsite:8000/api/RunTestTimer", contentType: "application/json; charset=utf-8", data: JSON.stringify({ timeInSeconds: 15 }), // timeInSeconds is the parameter name in the Web API, which I used to run a timer on the server-side for the value passed to the ajax call dataType: "json", beforeSend: skelta.forms.utilities.addRequestHeaders }) .done(function (result) { var endTime = performance.now(); var message = "Request Successful (Time Taken to execute: " + ((endTime - startTime) / 1000).toFixed(3) + " secs; Type: " + "POST" + "; Async: " + "FALSE" + "; Timer: " + "15" + " seconds):" + JSON.stringify(result); console.log(message); }) .fail(function (result) { var endTime = performance.now(); var message = "Request Failed (Time Taken to execute: " + ((endTime - startTime) / 1000).toFixed(3) + " secs; Type: " + "POST" + "; Async: " + "FALSE" + "; Timer: " + "15" + " seconds):" + JSON.stringify(result); console.log(message); });
1
0
321
Sep ’24
iOS 18 HTML images are not loading in WKWebView
iOS 18 WKWebView images are not loading, no errors in older versions. The example while loading HTML is as follows. A problem occurs when you pull an image from a url. To get a URL image you need a cookie or something. I add them too, but it doesn't work on iOS 18. I get the error "An error occurred trying to load the resource." and a blue question mark on the screen. webView.configuration.websiteDataStore.httpCookieStore.setCookie(cookie) <html> <head> <style> body { font-family: -apple-system; margin: 0; padding: 0; text-align: center; } img { width: 100%; height: auto; } </style> </head> <body> <h1>Resim Görüntüleme</h1> <img src="https://xx.***.xx/example.png"> </body> </html> """
2
1
793
Sep ’24
WebView Loading Issue iOS 18.1
Since iOS 18.1 launched as a beta, we've been getting reports from end users on iPhone 15 Pro and iPhone 15 Pro Max specifically. They're reporting that our WebView is unable to load our local HTML content. I'm curious if anyone else has had their app or users run into this issue? So far I've tried installing the most recent XCode Beta 16B5014f and installed an 18.1 emulator, but our app worked fine. It's also working fine on all my real devices, but we don't have a 15 Pro to test on. I'm curious if this is related to the processor on these devices and how they are intended to support Apple's new AI coming in 18.1.
3
1
790
Sep ’24
First-Party-Cookies Retention Policy using Capacitor App
Hello, we built an ios app using the capacitor framework (app rendered in webview) and recently implemented a cookie based authentication mechanism. What we have no reliable information about is for how long these first-party cookies are stored and if/when they are cleared by some Apple policy. There is a lot of conflicting information out there and I want to reach out here to get some definitive information about this topic. For how long are first-party cookies persisted using ios webview via capacitor. Is there any way to influence that behaviour? Thank you very much. Best Regards Marcus
0
0
186
Sep ’24
Previously working projects fail
I have a small example project that ran on both the simulator and a connected iPhone but now it and all other projects are failing with the same error. I am using Xcode 16.0 on MacOS Sonoma 14.6.1., iPhone 11 with iOS 18. Thank you in advance. The error is: Failed to resolve host network app id to config: bundleID: com.apple.WebKit.Networking instance ID: Optional([_EXExtensionInstanceIdentifier: 1163B5D2-09D3-4704-9564-61099502138B]) WebContent process (0x114018680) took 1.375772 seconds to launch GPU process (0x1140a0630) took 1.228457 seconds to launch Networking process (0x114034d00) took 1.426249 seconds to launch 0x105820a20 - [pageProxyID=7, webPageID=8, PID=34786] WebPageProxy::didFailProvisionalLoadForFrame: frameID=1, isMainFrame=1, domain=NSURLErrorDomain, code=-1200, isMainFrame=1, willInternallyHandleFailure=0 Message from debugger: killed Below is the code from one of the examples: import UIKit import WebKit class ViewController: UIViewController { let webView: WKWebView = { let prefs = WKWebpagePreferences() prefs.allowsContentJavaScript = true let configuration = WKWebViewConfiguration() configuration.defaultWebpagePreferences = prefs let webView = WKWebView(frame: .zero, configuration: configuration) return webView }() override func viewDidLoad() { super.viewDidLoad() view.addSubview(webView) guard let url = URL(string: "https://google.com") else { return } webView.load(URLRequest(url: url)) //evaluate JavaScript DispatchQueue.main.asyncAfter(deadline: .now()+5){ self.webView.evaluateJavaScript("document.body.innerHTML") { result, error in guard let html = result as? String, error == nil else { return } print(html) } } } override func viewDidLayoutSubviews(){ super.viewDidLayoutSubviews() webView.frame = view.bounds } }
2
1
1.1k
Sep ’24
Sandbox and WKWebView
When I run this program on iphone ( ios 18.0 with Xcode 16.0 (16A242d) ) I get these warnings from iphone ( not from the preview running ) : Could not create a sandbox extension for '/var/containers/Bundle/Application/7BAE-82-4A3-98D-75A49B/xxxx.app' Updated list with error: DownloadFailed Updated list with error: DownloadFailed Updated list with error: DownloadFailed Updated list with error: DownloadFailed Updated list with error: DownloadFailed The programe is simple : import SwiftUI import WebKit struct ContentView: View { let htmlContent = """ &lt;html&gt; &lt;head&gt; &lt;meta content="text/html; charset=UTF-8" http-equiv="content-type"&gt; &lt;meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no"&gt; &lt;/head&gt; &lt;body&gt; &lt;h1&gt;Hello, World!&lt;/h1&gt; &lt;p&gt;This is a simple webpage displayed in a WebView.&lt;/p&gt; &lt;/body&gt; &lt;/html&gt; """ var body: some View { WebView(htmlContent: htmlContent) .edgesIgnoringSafeArea(.all) } } struct WebView: UIViewRepresentable { let htmlContent: String func makeUIView(context: Context) -&gt; WKWebView { let webView = WKWebView() webView.loadHTMLString(htmlContent, baseURL: nil) return webView } func updateUIView(_ uiView: WKWebView, context: Context) { // No need to update the view since the content is static } } struct ContentView_Previews: PreviewProvider { static var previews: some View { ContentView() } } any reason for this ? otherwise the program is running correctly, but is this a bug or a programming problem?
1
0
434
Sep ’24
Getting a crash in Webkit on iOS 18. Any solutions for this?
Here are the crash logs from Firebase Crashlytics Crashed: com.apple.IPC.ReceiveQueue 0 libsystem_platform.dylib 0x70c8 _os_unfair_lock_recursive_abort + 36 1 libsystem_platform.dylib 0x42d8 _os_unfair_lock_lock_slow + 308 2 WebKit 0xe2a5f0 <redacted> + 44 3 WebKit 0xe2a264 <redacted> + 320 4 WebKit 0xe29b24 <redacted> + 304 5 WebKit 0x1d8fc <redacted> + 740 6 libdispatch.dylib 0x40d0 _dispatch_client_callout + 20 7 libdispatch.dylib 0x7580 _dispatch_continuation_pop + 596 8 libdispatch.dylib 0x1b53c _dispatch_source_latch_and_call + 420 9 libdispatch.dylib 0x1a104 _dispatch_source_invoke + 836 10 libdispatch.dylib 0xb560 _dispatch_lane_serial_drain + 368 11 libdispatch.dylib 0xc1e0 _dispatch_lane_invoke + 380 12 libdispatch.dylib 0x17258 _dispatch_root_queue_drain_deferred_wlh + 288 13 libdispatch.dylib 0x16aa4 _dispatch_workloop_worker_thread + 540 14 libsystem_pthread.dylib 0x4c7c _pthread_wqthread + 288 15 libsystem_pthread.dylib 0x1488 start_wqthread + 8
4
4
383
Sep ’24
XPCConnectionTerminationWatchdog Crash
I recently update my ionic app to ionic angular 7. I'm having this crash that does not happen in the same way, neither in the same place. Aside from needed some entitlements that I've already requested the app is crashing all the time. This is the error. ⚡️ TO JS {"value":"en"} 2024-09-24 15:43:56.097126+0200 App[33392:5520337] [Process] 0x10d003260 - [PID=33408] WebProcessProxy::didClose: (web process 0 crash) 2024-09-24 15:43:56.097185+0200 App[33392:5520337] [Process] 0x10d003260 - [PID=33408] WebProcessProxy::processDidTerminateOrFailedToLaunch: reason=Crash 2024-09-24 15:43:56.097270+0200 App[33392:5520337] [ProcessSuspension] 0x10c020720 - ProcessAssertion: Failed to acquire RBS Background assertion 'XPCConnectionTerminationWatchdog' for process because PID 0 is invalid 2024-09-24 15:43:56.097368+0200 App[33392:5521826] [ProcessSuspension] 0x10c020720 - ProcessAssertion::acquireSync Failed to acquire RBS assertion 'XPCConnectionTerminationWatchdog' for process with PID=0, error: (null) 2024-09-24 15:43:56.098184+0200 App[33392:5520337] [Process] 0x142832618 - [pageProxyID=8, webPageID=9, PID=33408] WebPageProxy::processDidTerminate: (pid 33408), reason=Crash 2024-09-24 15:43:56.101821+0200 App[33392:5520337] [Loading] 0x142832618 - [pageProxyID=8, webPageID=9, PID=33408] WebPageProxy::dispatchProcessDidTerminate: reason=Crash 2024-09-24 15:43:56.117084+0200 App[33392:5522124] [com.apple.VisionKit.processing] Error processing request from MAD on result: Error Domain=NSOSStatusErrorDomain Code=-128 "Request was canceled" UserInfo={NSLocalizedDescription=Request was canceled} request: <VKCImageAnalyzerRequest: 0x2830d0690> requestID: 6 madRequestID: 6 cancelled: YES 2024-09-24 15:43:56.245502+0200 App[33392:5520337] [Process] 0x10c07c380 - GPUProcessProxy::gpuProcessExited: reason=IdleExit 2024-09-24 15:43:56.245552+0200 App[33392:5520337] [Process] 0x10d002ce0 - [PID=33412] WebProcessProxy::gpuProcessExited: reason=IdleExit 2024-09-24 15:43:57.682680+0200 App[33392:5520337] Could not signal service com.apple.WebKit.WebContent: 113: Could not find specified service 2024-09-24 15:44:04.249892+0200 App[33392:5520337] Could not signal service com.apple.WebKit.WebContent: 113: Could not find specified service 2024-09-24 15:44:12.223579+0200 App[33392:5520337] Could not signal service com.apple.WebKit.WebContent: 113: Could not find specified service 2024-09-24 15:44:26.098426+0200 App[33392:5520337] Could not signal service com.apple.WebKit.WebContent: 113: Could not find specified service 2024-09-24 15:44:59.812245+0200 App[33392:5522961] [MADService] Client XPC connection invalidated
1
0
270
Sep ’24
SFSafariViewController not loading web pages on Xcode 16 Simulator with iOS 18
After updating Xcode to the latest version we observed that SFSafariViewController is not loading web pages on Xcode 16 Simulator with iOS 18, whenever it is presented the View Controller is empty (does not load any content) and the app freezes, but other screens that use WKWebView are working normally. Also, during tests on physical devices with iOS 18 it seems to work just fine, so it might be just a IDE version problem. Is anyone experiencing the same issue? If so, did anyone find a solution for it?
11
8
1.6k
Sep ’24
WKWebView can not play audio with webrtc on iOS 18 and iPadOS 18
I am experiencing an issue with my app, which includes a WKWebView used for displaying and playing WebRTC content (audio and video). Everything works fine on macOS, but on iOS 18, while the video is displayed correctly, there is no sound. I am wondering if this could be related to privacy permissions on iOS. Could you please clarify if there are any specific privacy permissions I need to address? I would like to confirm: AVAudioSession.sharedInstance().setCategory requires any special configuration for WebRTC audio. Are there any particular settings needed for this? My setting codes are below: try AVAudioSession.sharedInstance().setCategory(.playback, mode: .default, policy: .longFormAudio) Do the JavaScript codes in the HTML file require any special handling to ensure WebRTC audio works properly on iOS? const audioRender = document.createElement('audio'); audioRender.id = 'xxxid'; audioRender.srcObject = streamSource; audioRender.autoplay = true; audioHolder.appendChild(audioRender); Does WKWebViewConfiguration need any specific parameter adjustments to ensure audio playback in WebRTC works as expected? let webViewConfiguration = WKWebViewConfiguration() let contentController = WKUserContentController() contentController.add(self, name: "***") webViewConfiguration.userContentController = contentController webViewConfiguration.allowsInlineMediaPlayback = true
2
1
383
Sep ’24
Compatibility Issue with WebKit.WKWebView.evaluateJavaScript(_:completionHandler:) in Xcode 16
I've encountered an issue after upgrading to Xcode 16. I have an overridden func of WebKit.WKWebView.evaluateJavaScript(_:completionHandler:), which no longer compiles in the new Xcode. I noticed that in Xcode 16, the completionHandler now has @MainActor and @Sendable annotations, which causes a compilation error. public override func evaluateJavaScript(_ javaScriptString: String, completionHandler: (@MainActor @Sendable (Any?, (any Error)?) -> Void)? = nil) When I add these annotations to my overridden method, it compiles fine in Xcode 16. However, this breaks compilation in older versions of Xcode. The documentation for this API doesn't explicitly mention any changes, but the behavior is clearly different between versions. https://developer.apple.com/documentation/webkit/wkwebview/1415017-evaluatejavascript Xcode 15: Xcode 16: What would be the best way to handle this situation? Should I use a compilation condition to differentiate between the versions? If so, what would be the correct condition to check? Was there a Swift compiler update in Xcode 16 that could be affecting this? Or is it better to drop support for versions of Xcode earlier than 16? Or I should not override that? Thanks in advance for any insights!
4
1
642
Oct ’24