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

Posts under WebKit tag

200 Posts
Sort by:

Post

Replies

Boosts

Views

Activity

Password AutoFill not working WKWebView
I've implemented Password AutoFill for our webpage. It's working fine in safari browser and SFSafariViewController Safari browser Same way, in our mobile app, we are using a web-based login page. For the login, we are using WKWebView, but in WKWebView the popup is not showing, instead, it’s showing the normal keyboard. WKWebView - App Already configured Associated Domains under Capability. webcredentials:prod.auth.TestDomain.org
0
1
735
Nov ’23
WKWebView displays white screen after the application goes into the background
I have a project that must upload data in background and keep data going even when the app is closed/terminated. In very rare cases I have encountered the problem that when background uploading is in process (app was fully closed/terminated) and when I open the application a white (blank) screen appears. No splash screen, no content in webview, but I still can see my logs that the background tasks is producing. After the completion of data uploading the white screen does not go away, obviously. My application is built React on gets loaded in a WebView. I noticed one thing, although I see only a white screen, according to the inspector the DOM is fully loaded and functional and the connection between React app and native app is still there (callbacks, facades). Reloading page or opening another page doesn't have any positive effect. Also I am able to highlight elements using Safari's inspector and can visually observe their outlines on the end device. They're present, but content doesn't renders at all. The problem lies precisely because of the incorrect operation of WebKit when the application goes into the foreground during background tasks active, after when the user swipes away the application and the system terminates the application (app termination is an important condition). To solve this problem I used the following: An attempt to catch the system closing Webkit and then reload React App. I implemented this method func webViewWebContentProcessDidTerminate(_ webView: WKWebView) However I never get into this method (unless I destroy the process associated with webkit in the emulator myself). Obviously process doesn't gets terminated and it's not the cause. 2. Trying to resize the WebView doesn't solve the problem either. 3. I tried to do webView.reload() after the application gets into willEnterForeground, but this does not always work correctly and does not completely solve the problem. Sometimes the webView is rendered, and sometimes there is still a white screen even though the method was called. 4. I tried calling webView.loadHTMLString on a "broken" webview just to make sure that React app is not the cause and it still doesn't render anything, yet i can see the new content from inspector but white screen still stay. 5. Complete recreation of WKWebView (removing the old one from WebViewContainer, creating and adding the new one, loading react app) is solving the problem, but it is a pretty much rough workaround, similiar to app restarting. And also I find it difficult to find a right moment/event to apply this workaround. Are there any known related issues or any known causes of this? What can be putting webview into this weird state?
4
3
2.2k
Nov ’23
ASWebAuthenticationSession initiated session, file:// URL is not loaded and "Confirm the file to load" is presented instead
We are relying on ASWebAuthenticationSession to do web authentication. Since the API doesn't support POST requests directly we have to generate local file in ~/Library/Application Support/<foo.bar>/WebAuth.html containing the POST and use initial URL as file:///Users//Library/Application%20Support//WebAuth.html Problem is that Safari sometimes pops a dialog "Confirm the file to load" and sometimes it doesn't. This doesn't depend on "Full Disk access" TCC. Does anybody know a way to prevent this from happening? MDM option or something? Also styling of the popup is a rather poor UI choice - looks very confusing and like the user may choose another file to load. Chrome f.e. doesn't do such popups. I already have FB13340210 for this.
1
0
749
Jan ’24
Safari responds to a successful "fetch" of a file:// URL with a status of 0
I built a web application that is designed to be run from my application bundle by using webView.loadFileURL(htmlFile, allowingReadAccessTo: projectFolder) on a WKWebView. Inside of the site's folder is a directory of svg images (from the ionicons project). At runtime the code tries to load one of those images using: req = fetch(url).then((rsp) => { if (rsp.ok) { return rsp.text().then((svgContent) => { if (svgContent && sanitize !== false) { svgContent = validateContent(svgContent); } (code from the ionicons project). The rsp.ok check simply examines the response to the fetch request to see if the status code is in the range 200-299. For the "file://" URL, however Safari on both MacOS and iOS returns 0 in the status. In spite of that 0, however the request has succeeded and the browser has the content of the file. If I modify the code to ignore rsp.ok the following call accessing rsp.text() succeeds. I'm not sure what the expectations are for a file:// URL passed through fetch. Is the 0 status code a bug in Webkit or Safari, or is it an expected result for a file:// URL and the code making the fetch request needs work?
0
0
463
Nov ’23
WKWebView is Blank
I’m trying to add a window to myMacOS application that will displace html content. I have a .xib with a window with a WKWebView. In my NSWindowController subclass implementation I have an IBOutlet WKWebView *myWebView. The outlet is connected to the WKWebView in the .xib I initialize my subclass of NSWindowController with: self = [super initWithWindowNibName: @“WindowName”]; Then in the windowDidLoad method I initialize the WKWebView with code like this: WKWebViewConfiguration *webConfiguration = [[WKWebViewConfiguration alloc] init]; [webConfiguration defaultWebpagePreferences]; myWebView = [[WKWebView alloc] initWithFrame: [myWebView frame] configuration: webConfiguration]; [webConfiguration release]; //Yes, I know I could use ARC [myWebView setUIDelegate: nil]; This looks fine in the debugger and doesn’t log any errors. Then I can create and load a URLRequest with Apple’s example: NSURL *appleURL = [NSURL URLWithString: @"https://www.apple.com"]; NSURLRequest *myURLRequest = [NSURLRequest requestWithURL: appleURL]; [myWebView loadRequest: myURLRequest]; In order for this to work I have to check the Network Incoming Connections (Server) box in the target’s App Sandbox. (It would be EXTREMELY helpful if this was mentioned in the Developer Documentation) OR I can get file URLs and folders from the Application Bundle and load than with: [myWebView loadFileURL: helpFileURL allowingReadAccessToURL: helpBundleURL]; In order for this to work I have to check the Network Outgoing Connections (Server) box in the target’s App Sandbox. (It would be EXTREMELY helpful if this was mentioned in the Developer Documentation) Then when the window is opened and displayed the WKWebView remains blank. No errors are logged. XCode logs: “WebContent process (0x150001200) took 1.3841 seconds to launch.” so XCode seems to think that the web content was loaded correctly but the WKWebView remains blank. Trying to force it to display with methods like reload and setNeedsDisplay: YES don't fix it. How can I get the WKWebView to actually display the content?
2
0
546
Nov ’23
Bug iOS 17.2 Beta only webView.configuration.userController.add(_ scriptMessageHandler: WKScriptMessageHandler, name: String) Not Working
I have the following lines of code in our app: @objc convenience init(webView: WKWebView, delegate: SomeDelegate, navigationDelegate: WKNavigationDelegate) { self.webView = webView self.webView.makeInspectable() self.webView.navigationDelegate = navigationDelegate self.webView.uiDelegate = self self.webView.configuration.suppressesIncrementalRendering = true self.webView.configuration.userContentController.add(weakSelf ?? self, name: "handlerOne") self.webView.configuration.userContentController.add(weakSelf ?? self, name: "handlerTwo") injectUserScripts() // Injects WKUserScripts into the webView.configuration.userContentController } My JS script looks as follows: (function() { addEventListener('mousedown', function() { window.webkit.messageHandlers.handlerOne.postMessage('WKUserScriptMouseDown'); }, true); })(); if (MyApp.getProperty("os") != null) { window.webkit.messageHandlers.handlerTwo.postMessage(url); } else { console.log(url); // non-mobile browser (for testing) } However I keep seeing an error in my Safari debugger: TypeError: undefined is not an object (evaluating 'window.webkit.messageHandlers.handlerOne') TypeError: undefined is not an object (evaluating 'window.webkit.messageHandlers.handlerTwo')
4
2
1.4k
Nov ’23
webkit crashing on Babylon.js after update to iOS 17.x.x
In my company, we have built 3D configurator using Babylon.js engine. It is used by our clients as an embed on their websites. After the update to iOS 17.x.x we are noticing a notorious jetsam event caused by a possible memory leak, when resizing the canvas. The problem seems to be non-existent on older iOS versions. Safari and Chrome on iOS 17.x.x either reloads the page or completely crashes and reloads the whole app. We've had similar issues in the past and resolved them by limiting the size of the meshes and textures, but further optimization is not possible. After the latest iOS update, the problem returned. Has anyone noticed similar behavior?
1
0
376
Nov ’23
WKWebView: Failed to acquire RBS assertion 'WebKit Media Playback'
Hi there! I'm new to App Development and I'm running into the following error when playing audio on a website loaded through a WKWebView: 0x112000cc0 - ProcessAssertion::acquireSync Failed to acquire RBS assertion 'WebKit Media Playback' for process with PID=70.197, error: Error Domain=RBSServiceErrorDomain Code=1 "(originator doesn't have entitlement com.apple.runningboard.assertions.webkit AND originator doesn't have entitlement com.apple.multitasking.systemappassertions)" UserInfo={NSLocalizedFailureReason=(originator doesn't have entitlement com.apple.runningboard.assertions.webkit AND originator doesn't have entitlement com.apple.multitasking.systemappassertions)} Looking through this forum, it seems more people have this issue, yet no one has found a solution (or posted it...). The solutions that I did find (Background Modes capability, webView.configuration.allowsInlineMediaPlayback = true), did nothing. To make sure the issue had nothing to do with my own code, I created an empty project to reproduce the issue. I'm not sure on the best way to share it, but it's a small file (forgive me, I have no clue what it does, actually chatGPT made it for me. My real application is a WebApp wrapped with Capacitor, so it handles all the Swift stuff) import SwiftUI import WebKit struct WebView: UIViewRepresentable { let urlString: String func makeUIView(context: Context) -> WKWebView { let webView = WKWebView() webView.configuration.allowsInlineMediaPlayback = true webView.configuration.allowsAirPlayForMediaPlayback = true webView.navigationDelegate = context.coordinator return webView } func updateUIView(_ uiView: WKWebView, context: Context) { if let url = URL(string: urlString) { let request = URLRequest(url: url) uiView.load(request) } } func makeCoordinator() -> Coordinator { Coordinator(self) } class Coordinator: NSObject, WKNavigationDelegate { var parent: WebView init(_ parent: WebView) { self.parent = parent } func webView(_ webView: WKWebView, didFailProvisionalNavigation navigation: WKNavigation!, withError error: Error) { print("Web page loading failed: \(error.localizedDescription)") } } } struct WebViewDemo: View { var body: some View { NavigationView { WebView(urlString: "https://www.w3schools.com/html/tryit.asp?filename=tryhtml5_audio_all") .navigationBarTitle("Web View") } } } struct WebView_Previews: PreviewProvider { static var previews: some View { WebViewDemo() } } Nothing special, right? When I build the app and navigate to a website that has an tag (https://www.w3schools.com/html/tryit.asp?filename=tryhtml5_audio_all). I still see the error when I play the audio. It plays nonetheless, but the error is there. I'm not at all interested in actually playing audio in the background/when the app is closed/suspended. I just want the error to go away! I've tried different iOS versions (14,15,16,17), but the problem persists. Anyone know what's happening?
3
3
3.3k
Oct ’23
PWA fails with login loop under iOS 17
We have a PWA that worked well until iOS 17 (17.0.3). We are using AngularJS. It seems like the entire app just loses connection to its IndexedDB, and returns to the login screen, whereupon it uses LocalStorage info to successfully log back in again. After looping in this process a few times (lose connection, login screen, login, rehydrate indexedDB, etc), then LocalStorage eventually gets wiped and the user has to login from scratch. This is terrible and we have no idea why this is happening. Please fix ASAP!
0
0
285
Oct ’23
How to make my app available to set as a default browser
Good day, I have an application that opens links in various browsers available on the device. For this reason, I want to make the app eligible to be chosen as the default browser. To do this, I reviewed the Apple article at this link: https://developer.apple.com/documentation/xcode/preparing-your-app-to-be-the-default-browser. However, unfortunately, I still haven't figured out how to do it. The article mentions that you need to send an email request. I sent an email, but my message was ignored. Dear colleagues or Apple staff, could you please explain in the most detailed and step-by-step manner how I can make my app available to be set as the default browser? I would greatly appreciate it because, unfortunately, this question isn't widely discussed in the community, and there are no videos with step-by-step guides. Thank you very much!
0
0
409
Oct ’23
A Web Page's Javascript Causing an Error in My WKUserScript Loaded in a Custom Content World
I have a global variable in WKUserScript declared as a const in Javascript. I load this script in a custom WKContentWorld I create with my own name (not the pageWorld or default world). There some nasty javascript out there on most popular sites. I noticed that unhandled errors on the page can break stop my WKUserScript from working. In one particular case there is this nasty script on page for ads that uses document.write like so: b.contentWindow.document.write(e), b.contentWindow.document.close() And the web inspector shows an error here "Can't create duplicate variable: 'MyGlobalVariableNameInsMyUserScriptHere'" This script being used on the web page is going to end up getting blocked. But my question is this, isn't using my own content world supposed to protect me against this type of thing? This global javascript variable (an array) is global in my javascript file and holds some data in it but it is not inserted into the DOM. Shouldn't document.write/document.close calls from the page not cause this type of error in my user script? And if the entire DOM is being rewritten shouldn't a new script (representing my user script) be created from scratch? I think I can avoid the error by changing the variable from const to var (haven't tried yet). But is this how it's supposed to be?
1
0
399
Oct ’23
Webrtc zoom/resize issue in safari 17
I am learning to develop webrtc apps and have noticed that starting with safari and safari mobile 17 there is a noticeable zoom distortion that occurs when resizing some webrtc players. This seems to be safari specific and only on version 17. What feature change could cause this? Here is an example of catalina vs Sonoma. Sorry i dont have access to any other versions in between atm but i have only seen this issue since updating to safari 17
2
4
606
Oct ’23
WKWebView occasionally shows white screen and persists until app restart
I am encountering an intermittent issue with WKWebView in my iOS app. The problem occurs infrequently, but when it does, the WKWebView consistently displays a white screen and remains in this state until the app is forcefully terminated and relaunched. To provide more context, here are the key characteristics of the issue: The white screen problem occurs sporadically and is not easily reproducible. The WKWebView remains unresponsive despite attempts to interact with it. Reloading the webpage or navigating to a different URL does not resolve the white screen issue. The problem persists until the app is terminated and relaunched. This issue is specific to the WKWebView; other components of the app function correctly. The WKWebView renders normally, and the main document synchronously loads resources both offline and online without any issues. The bridge and JavaScript execution also work as expected. However, when interacting with the WKWebView, it becomes unresponsive to user clicks, and the web inspector fails to respond. Additionally, asynchronous network requests also do not receive any response. The problem occurs exclusively on HTTPS pages, whereas HTTP pages load without any issues. Other components, such as workers, function correctly. addUserScript injection during WKWebView creation is effective, and evaluateJavaScript during the page loading process works as expected. However, when the document becomes unresponsive, executing evaluateJavaScript only triggers the callback after the WKWebView is destroyed. I have discovered a reliable method to reproduce the white screen issue in WKWebView. This method involves the following steps and conditions: Create a WKWebView instance. Load an HTML page using the loadRequest method(https url request). Before the WKWebView is attached to the UI (not yet visible to the user), call the evaluateJavaScript function. This issue has occurred in almost all iOS versions, including the latest iOS 17.x version.
3
0
789
Oct ’23
Safari, WKWebView video slow loading issue
my web service has video content. the problem is in chrome browser, downloading and playing video is much faster than Webkit browser (Safari and WkWebView). we are struggling to find the reason why there is huge gap between two browsers. we've checked browser inspector and there's something look like error in safari inspector that doesn't appear in chrome. There are two cases in network section. First red header case that I think something went wrong Second yellow header csae that I think succeeded to donwload
0
0
509
Oct ’23
WKWebView -resumeAllMediaPlayback: deprecated Replacement is -setAllMediaPlaybackSuspended:completionHandler:
I see the -resumeAllMediaPlayback: says the replacement method is -setAllMediaPlaybackSuspended:completionHandler: I don't believe suspending and resuming media playback are matching actions, which would mean -resumeAllMediaPlayback: doesn't have a replacement API? The deprecated -resumeAllMediaPlayback: method doesn't seem to work on Sonoma (pauseAllMediaPlaybackWithCompletionHandler: does work but resume does not).
1
0
396
Oct ’23
How do i find the culprit of "exceeded mem limit" errors on iOS devices visiting a particular web page?
With a physical iPhone attached to the dev tools on my laptop, the memory usage of this web page https://nypost.com/2023/10/11/australian-swimmers-almost-walk-into-shark-as-it-swims-close-to-shore/ consistently grows until it reaches the memory limit of the device (in my case, about 1.5GB) The safari dev tools has a memory profiler timeline which breaks down memory usage into categories including "Javascript", "Layers", and "Page"; is there a way to break these down further to individual scripts/resources? I have also tried looking at the Javascript allocations profiler, but the computed heap size reported in its snapshots never comes anywhere close to the 700+ MB of "JavaScript" memory usage reported by the Memory profiler.
2
0
739
Oct ’23