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

Posts under WebKit tag

200 Posts
Sort by:

Post

Replies

Boosts

Views

Activity

Crash when presenting Camera via Web View in iOS 18.2 Beta - WebCore::AVVideoCaptureSource::create
We are experiencing thousands of crashes in our application when attempting to present the camera through a Web View. The app crashes during this process, and the crash logs point to WebCore::AVVideoCaptureSource::create WebCore::RealtimeMediaSourceCenter::getUserMediaDevices. This issue has only been observed in iOS 18.2 beta versions (beta 1 - 22C5109p, beta 2 - 22C5125e, beta 3 - 22C5131e). In iOS versions below 18.2, the functionality works and we haven't identified any correlation with specific device models. The problem seems to stem from a WebCore framework introduced in these beta releases 18.2. We kindly request a review and fix for this issue in upcoming beta releases to restore functionality. Let us know if there are any workarounds or adjustments we can implement in the interim. Thank you for your attention to this matter.
2
0
140
2d
SwiftUI/WebKit Allowing popups and links
We are using an imbedded WKWebView in a SwiftUI view. There are links within the pages being viewed - they are company pages - and some link to other pages as well as open named (or unnamed) browser tabs. In our implementation, when there is a named (or unnamed) link to another browser tab, the view does not do anything. Any ideas on how to allow tabs to open in some manner and allow the users to access the links?
2
0
88
2d
WKWebView Authorization Challenge fails to refresh
I have a url that I want to stream, the stream is protected by basic auth. I am using URLAuthenticationChallenge (wkwebview navigation delegate function) method to provide my credentials. the credential changes with every stream url. The issue I am facing is that URLAuthenticationChallenge is never called upon refresh or on new URL request until the app is killed and opened again. I have tried: clearing cooking setting cache to ignore opening an another blank url using child view approach setting wkwebview instance to nil I always end up with 401 in decidePolicy (wkwebview delegate functions) on subsequent refresh call. Upon inspecting I see that it is using my previous used credentials and never calling challenge to update. *Backend has a no-cache policy in its header. **I am using http resource, the aim is to have streaming service on iOS. class ViewController: UIViewController, WKNavigationDelegate, WKUIDelegate { @IBOutlet weak var wkWebView: WKWebView! override func viewDidLoad() { super.viewDidLoad() let url = URL(string: "http://some-ip-address/some-path")! var request = URLRequest(url: url) request.httpMethod = "GET" wkWebView.configuration.allowsInlineMediaPlayback = true wkWebView.navigationDelegate = self wkWebView.load(request) } // this is just called once. we want to call it everytime our page refreshes. // we have tried clearing cache and cookies but failed to call challenge func webView(_ webView: WKWebView, didReceive challenge: URLAuthenticationChallenge, completionHandler: @escaping(URLSession.AuthChallengeDisposition, URLCredential?) -> Void) { let credential = URLCredential(user: "user", password: "password", persistence: .forSession) completionHandler(.useCredential, credential) } }
1
0
137
4d
iOS18 WKWebView URLProtocol
In our project, URLProtocol is used to intercept the request of WKWebView.loadRequest. On iOS18, if the APP is idle for more than 10 minutes and then clicks on an H5 page, the time from WKWebView.loadRequest -> URLProtocol.canInitWithRequest will be as long as 600ms or more, but the second time the H5 page is opened, it will only be 80ms. This only occurs on iOS18 models.
2
0
198
6d
WkWebView breaks with isElementEnabled preference set to true on fullscreen pause
I have an webview that loads videos in it, we would like to be able to fullscreen our videos, so we use the fullscreen preference in the documentation however when it is set to true, upon fullscreening a video then pausing it, the entire video player will disappear. You can exit fullscreen and attempt to fullscreen the video player once again, however upon doing this the entire app view will now disappear and you'll see your desktop background (or whatever is currently behind your app). This behavior seems consistent across multiple websites with the current app. I have setup a sample project you can test here The Main error that seems to trigger to the console is this. I have not been able to find a solution to, maybe I am simply missing something here. I am on Sequoia 15.2 for Mac. Attempting to update all DD element frames, but the bounds or contentsRect are invalid. Bounds: X: 0.00 Y: 0.00, W: 0.00 H: 0.00, contentsRect: X: 0.00 Y: 0.00, W: 1.00 H: 1.00 , skipping
2
0
243
1w
Errors reported by content of WKWebView (via window.onerror) are censored to "Script error.""
Script error. We've decided to implement certain highly-dynamic content in out iOS codebase using web technologies, here's what we're doing: We download a zip file containing html, javascript, and images. We unzip the archive, construct a WKWebView, and load the content using webView.loadFileURL(indexHtmlUrl, allowingReadAccessTo: parentDirectory) This works fine, but we'd also like to be notified on any rendering errors that might be raised, so we can fix them. let errorHandlerScriptString = """ (function() { var oldLog = console.log; console.log = function(message) { window.webkit.messageHandlers.consoleLog.postMessage(message); oldLog.apply(console, arguments); } })(); // don't even allow asking for location permissions navigator.geolocation.getCurrentPosition = function(success, error, options) { error({ PERMISSION_DENIED: 1, code: 1 }); }; window.onerror = (msg, url, line, column, error) => { const message = { message: msg, url: url, line: line, column: column, error: JSON.stringify(error) } if (window.webkit) { window.webkit.messageHandlers.error.postMessage(message); } else { console.log("Error:", message); } }; """ let errorHandlerScript = WKUserScript(source: errorHandlerScriptString, injectionTime: .atDocumentStart, forMainFrameOnly: false) webView.configuration.userContentController.addUserScript(templateParamsScript) This causes the error messages to be censored to just "Script error." - See here for more reference https://stackoverflow.com/questions/50229935/wkwebview-get-javascript-errors This seems to be a security measure to prevent scripts with a different origin from reading error messages. I've tried to move the javascript that hooks to window.onerror to a file that's loaded in the header of the html, as well as putting it directly at the beginning of the <body> tag. Same results, still censored. There's recommendations to load the html using webView.loadHTMLString(html, baseURL: URL(string: "http://localhost/")!), but my understanding is that than there is not way to access a local resource, such as an image that was downloaded together with the html?
2
2
163
1w
iOS18 Static Rulesets Stop Working
iOS16 and iOS17 were fine, but on iOS18, our Safari extension that blocks content via static rulesets randomly stops working. Frequently, when a tab is left in the background for a long time (i.e. hours), the content blocker will stop working (until I either kill safari, or reload the extension). I've debugged this and the background.js script reports the ruleset as being loaded, but nevertheless, our rules aren't applied. I really don't think that it's an issue with the way that the rules are defined, since iOS16 and iOS17 worked fine, and on iOS18, the rules DO work. They just stop working after a while. "declarative_net_request": { "rule_resources": [ { "id": "ruleset_1", "enabled": true, "path": "ruleset_1.json" } ] }, Some theories: I have other content blockers on my phone that have LOTS of rules (adguard). Could I be seeing the effects of too many rules? Can I debug this somehow? Do logs get printed somewhere when the max rule limit is reached? Does the use of private and regular tabs mess things up? Please, any input is appreciated, as all of our logs are normal and error-free.
0
0
160
1w
macOS 15.1 WKWebView not allowing user to contract a text selection
We have an iOS app (which runs on macOS via "Designed for iPad") which renders web content on WKWebView. Our users can select text (standard OS way of click & drag cursor across text) and then perform actions on those discrete pieces of text. On macOS 15.1, our users can only expand a text selection, they cannot contract the text selection by dragging the cursor to the left. This reduces the usability of our app on macOS 15.1. This is not an issue on macOS 14. Environment: MacBook Pro (2021 16” M1 Max), macOS 15.1 Submitted Feedback FB15726254.
0
4
193
1w
CallKit breaks web based MediaStreams
We're integrating a web based group calling application within a native iOS application and finding that every time a CallKit session gets fully established the web based media streams break, rendering as gray with no audio. Up to iOS 18 we worked around it by not fulfilling the call start action but that's no longer an option as the audio stopped getting automatically redirected to the speakers. We would now need the CXProvider's didActivateAudioSession callback but that would break the video. The sample project loads up a simple webpage in a WKWebView which contains a video tag streaming the media from the device's camera. At the same time it sets up a new CallKit session by requesting and fulfilling a CXStartCallAction transaction. You will notice that the media doesn't render and, if you are to follow the warnings we left, you will find that not fulfilling the CXStartCallAction fixes it. Unfortunately that's not a workaround we can use as we need the CXProvider delegate to inform us about audio session changes so we can redirect the audio to the speaker (so the proximity sensor doesn't activate and locking the screen doesn't end the call) Any insights or workarounds would be greatly appreciated.
4
1
205
1w
Crashing in WKWebview Often, when the video is loaded in the webview using an HTML file
Hello, Team. We used WKWebView for our project. We loaded the HTML file into the webview and added the following configuration. weak var webView: WKWebView! func configWebView() { let webViewConfig = WKWebViewConfiguration() let controller = WKUserContentController() controller.add(self, name: "sometest") webViewConfig.userContentController = controller webViewConfig.processPool = WKProcessPool() webViewConfig.setValue(true, forKey: "allowUniversalAccessFromFileURLs") webViewConfig.mediaTypesRequiringUserActionForPlayback = [] let webpagePreferences = WKWebpagePreferences() webpagePreferences.allowsContentJavaScript = true webViewConfig.defaultWebpagePreferences = webpagePreferences webViewConfig.websiteDataStore = WKWebsiteDataStore.default() webView = WKWebView(frame: .zero, configuration: webViewConfig) webView.navigationDelegate = self webView.uiDelegate = self webView.translatesAutoresizingMaskIntoConstraints = false view.addSubview(webView) NSLayoutConstraint.activate([ webView.topAnchor.constraint(equalTo: view.topAnchor), webView.bottomAnchor.constraint(equalTo: view.bottomAnchor), webView.leadingAnchor.constraint(equalTo: view.leadingAnchor), webView.trailingAnchor.constraint(equalTo: view.trailingAnchor) ]) loadWebView() } func loadWebView() { guard let documentsDirectoryURL = FileManager.default.urls(for: .documentDirectory, in: .userDomainMask).first else { return } let contentFolderURL = documentsDirectoryURL.appendingPathComponent("content") let assetFolderURL = contentFolderURL.appendingPathComponent(interactiveGUID) if FileManager.default.fileExists(atPath: assetFolderURL.path) { let documentsPath = NSSearchPathForDirectoriesInDomains(.documentDirectory, .userDomainMask, true).first! let documentsURL = URL(fileURLWithPath: documentsPath) let fileToLoadPath = (documentsPath as NSString).appendingPathComponent("content/index_p.html") let fileURL = URL(fileURLWithPath: fileToLoadPath) autoreleasepool { DispatchQueue.main.async { [weak self] in guard let self = self else { return } self.webView.loadFileURL(fileURL, allowingReadAccessTo: documentsURL) } } } We are experiencing webview crashes when loading an HTML file. What happened when I loaded the video file? It automatically looped. Webview frequently crashes when the HTM/JS file is loaded. When a webview crashes, the delegate method usually calls webViewWebContentProcessDidTerminate. This method calls webview.reload(). Also we are clear and cache/ deallocate eveything when i initialized those configuration mentioned as the above. Can you suggest a solution to this? Why is webview crashing? Thank you.
0
0
120
2w
WKWebView crashes after repeated reloads on iOS 18
Hi! I have a rather complicated SwiftUI browser app with a WKWebView. There is an option to reload the website after a configurable amount of time. Starting with iOS 18, the app crashes after repeated reloads. How many reloads that are required depends on the device, sometimes 100, sometimes 1000. Reloading is done via a timer that triggers the following code on the main thread: let request = URLRequest(url: url, cachePolicy: policy) self.parent.webView.load(request) The URL is configurable and cachePolicy can be either .reloadIgnoringLocalAndRemoteCacheData or .useProtocolCachePolicy How the crash affects the device also differs from device to device and from time to time. I have suffered from the following crashtypes: App is killed App is killed and Safari also stops working App is killed and the whole OS is really slow The WKWebView stops loading and hangs at 20%. The device is rebooted My app has an option to disable cache. Cache is disabled by setting cachePolicy to .reloadIgnoringLocalAndRemoteCacheData and by removing all cache in a rather complicated way. Basicly i'm doing something like this: dataStore.removeData(ofTypes: types, modifiedSince: Date.distantPast, completionHandler: nil) if let klazz = NSClassFromString("Web" + "History"), let clazz = klazz as AnyObject as? NSObjectProtocol { if clazz.responds(to: Selector(("optional" + "Shared" + "History"))) { if let webHistory = clazz.perform(Selector(("optional" + "Shared" + "History"))) { let o = webHistory.takeUnretainedValue() _ = o.perform(Selector(("remove" + "All" + "Items"))) } } } if let cachesPath = NSSearchPathForDirectoriesInDomains(.cachesDirectory, .userDomainMask, true).first { let contents = (try? FileManager.default.contentsOfDirectory(atPath: cachesPath)) ?? [] for file in contents { if foldersToDelete.contains(file) { let path = cachesPath.appending("/").appending(file) do { try FileManager.default.removeItem(atPath: path) } catch { print("Can't delete cache file: \(path), error: \(error.localizedDescription)") } } } } The cache state affects the intensity of the crash. Disabling the cache shortens the time the app is working, while enabling the cache reduces the intensity of the bug. Based on my investigation, I suspect that loading a website in a WKWebVew leaks memory in iOS 18. If the whole website needs to be requested (= caching off), it results in a more significant memory leak and a faster crash time. Is this a known issue? Am I doing something wrong? Is there a potential workaround?
2
0
246
2w
iOS 18.2 Beta WKWebView Navigation Breaking loadFileURL for Local Files
I am experiencing a critical issue with WKWebView navigation in iOS 18.2 beta, specifically regarding the function webView.loadFileURL(_:allowingReadAccessTo:). In previous versions of iOS, this function works as expected when loading valid file URLs from the app’s local directory (e.g., Application Support). However, in iOS 18.2 beta, the function fails to complete the navigation, producing a provisional navigation failure with WebKitErrorDomain, code 102 (Frame load interrupted). This issue severely impacts our app’s ability to load essential local resources, breaking core functionality. Here’s a summary of the troubleshooting steps and findings: File and Directory Verification: The url provided to loadFileURL is valid. Both the file path and parent directory exist within the app’s sandbox, and the directory is accessible. Configuration: The code specifies the parent directory in the allowingReadAccessTo parameter to meet sandboxing requirements, which works on iOS 18.1 and prior releases. Testing on Stable iOS Versions: The issue is exclusive to iOS 18.2 beta; testing on earlier stable iOS releases confirms that the function works as intended. Impact: This regression severely disrupts the app’s navigation and content loading, effectively blocking access to local resources required for the WKWebView to display content properly. The error log returned in the console is as follows: > Error Domain=WebKitErrorDomain Code=102 "Frame load interrupted" UserInfo={_WKRecoveryAttempterErrorKey=<WKReloadFrameErrorRecoveryAttempter: 0x303dd67e0>, NSErrorFailingURLStringKey=file:///var/mobile/Containers/Data/Application/4D128818-7E51-460E-B5D4-D2D70363EFA0/Library/, NSErrorFailingURLKey=file:///var/mobile/Containers/Data/Application/4D128818-7E51-460E-B5D4-D2D70363EFA0/Library/, NSLocalizedDescription=Frame load interrupted} We suspect this may be due to a change in WebKit permissions in iOS 18.2 beta that affects local file handling within WKWebView. Given that the our app relies heavily on these resources, we kindly request this issue be addressed promptly. If any additional information or sample code is required, please let us know, and we will gladly provide further details to assist in resolving this issue. Thank you for your attention and support. Best regards, Isabela
2
1
234
3w
WKWebView Swipe Back Gesture Sometimes Redirects to the First Page Instead of Previous Page in Cordova App (iOS 17.5.1+)
Hello everyone, I am currently facing an issue with a Cordova-based app using WKWebView. In our app, we handle page navigation within the WebView. We’ve implemented a back button at the top of the page, which successfully triggers history.goBack() when clicked. However, we also want to support the native left edge pan gesture (swipe back) to trigger history.back(). The issue is that, while the swipe back gesture works most of the time, there are cases where instead of navigating to the immediate previous page, it behaves as if it’s going back to the first page (or initial page). This only occurs on iOS versions 17.5.1 and above. I’ve already set allowsBackForwardNavigationGestures to true, and the back button itself works perfectly. Has anyone experienced a similar issue, where the swipe back gesture sometimes skips pages and seems to return to the first page on iOS 17.5.1 or later? Any suggestions on how to fix or troubleshoot this would be greatly appreciated. Thank you!
0
9
258
3w
WKWebView: Fullscreen API very unreliable on iPadOS 18.x
Since iPadOS 18.x WKWebView seems to have a bug within its Fullscreen API (which can be enabled via WKPreferences.isElementFullscreenEnabled). This bug has the effect that websites trying to make an element (for example a video player) fullscreen fail to do so. This does not always happen, most of the time the fullscreen mode does work fine, but sometimes (far too often to be ignored) it does not. If an instance of WKWebView shows this issue, it can not be "fixed" by reloading the page or loading other pages, this issue exists in this instance forever. My App is a web browser App so I can create and remove WKWebView instance easily (by opening or closing Tabs). And there are times where I never see this bug, and times where ever other tab shows this bug. It's totally unreliable. The App does not show any issues at all when running under iPadOS 17 or older. The issue is only present under iPadOS 18.x. After some testing I've found out that when the bug has affected an instance of WKWebView, the JavaScript call element.requestFullscreen() will work if the element is a video element, but does no longer work if it is another element (like a DIV). If an instance of WKWebView is not affected by this bug, element.requestFullscreen() will work for all HTML elements. Does anyone has experienced this bug as well? And maybe found a workaround? Or maybe found a pattern which helps to find out what exactly is triggering this bug?
1
0
222
Oct ’24
WKWebView process did become unresponsive in iOS 17
Recently, we ran into a bit of a problem when using WKWebView. Sometimes, problems with all pages blank occur which use WKWebView. I implemented WKNavigationDelegate and found that it stops at - (void)webView:(WKWebView *)theWebView decidePolicyForNavigationAction:(WKNavigationAction *)navigationAction decisionHandler:(void (^)(WKNavigationActionPolicy))decisionHandler and it won't call below func forever - (void)webView:(WKWebView*)theWebView didStartProvisionalNavigation:(WKNavigation*)navigation I suspected that the render process is terminated and it won't restart. Then i try to resolve this problem by call reload func [self.webView reload]; But it didn't work. In The Meanwhile, i got some error message in console I have tested it in iOS 16 and 17. only iOS 17 got the issue. Pray for some help. Thanks a lot.
1
0
298
Oct ’24