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

Posts under WebKit tag

200 Posts
Sort by:

Post

Replies

Boosts

Views

Activity

How to add WebKit Entitlement
I have an iOS native app. I have added WKWebView to view controller to show html content. class MyHTML1ViewController: UIViewController { private var webView: WKWebView! var htmlFile: String = "" // default value, can be changed override func viewDidLoad() { super.viewDidLoad() let url = Bundle.main.url( forResource: htmlFile, withExtension: "html") let request = URLRequest(url: url) webViewBase.load(request) } ... } I run the app on my iPhone through Xcode. It displays html content fine. However, on closing the view, I saw the following error messages in console: ProcessAssertion: Failed to acquire RBS assertion 'WebProcess Suspended Assertion' for process with PID=91330, 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}> Should I add webkit entitlement? how can I do it in Xcode? I prefer to get rid of this error message if they are just warning in console, does not causing app crash. My Xcode is Version 13.4.1.
3
1
4.5k
Aug ’23
decidePolicyForNavigationAction returns WKNavigationTypeOther for links clicked within iframe
When a WKWebView implements the WKNavigationDelegate protocol, clicking a link inside the webview gives back WKNavigationTypeLinkActivated as WKNavigationType in the decidePolicyForNavigationAction. But clicking on a link inside an iframe gives back WKNavigationTypeOther, which makes it impossible to know if the url is requested on load or on click. Context: When a webview loads html (and embedded css, js, iframes, or XHR calls from JS ...), decidePolicyForNavigationAction gives back WKNavigationTypeOther as actionType , so I know content is loading and should be rendered in the webview. When a link is clicked, it gives back WKNavigationTypeLinkActivated so I know I need to show an in-app browser to show the content. This isn't the case with links clicked within an iframe (an <a> tag with href attribute); they return WKNavigationTypeOther
1
3
718
Oct ’23
Hyperlinks open in Web browser instead of embedded WKWebView using Swift5/SwiftUI
Good morning! I am developing an iOS app that gets its data from an API and displays it in a list. The list item view has NavigationLink embedded in it that sends users to a detail view. In this detail view, I have some Text views but the issue I am running into is a WKWebView that I have implemented to display some HTML that's is retrieved from the API call. The WKWebView displays the HTML just how I want it to. The issue I have is in the HyperLinks that are displayed in the WKWebView. When a user taps on a link, it opens inside of the web view. Instead of opening in the web view, I would like this link to open in the user's default web browser. I have searched and found ways of doing this in older versions of Swift using classes but my web view is initialized inside of a struct that conforms to the UIViewRepresentable protocol. I don't know how to get links to open in the browser instead of the WebView so any help would be appreciated. Here is the code for my WebView that is being used on the details page. struct NewsItemWebView: UIViewRepresentable { // HTML from API Call     var text: String // Method to create the View     func makeUIView(context: Context) -> WKWebView {         return WKWebView()     } // Method to update the View by changing properties of the WebView     func updateUIView(_ uiView: WKWebView, context: Context) {         uiView.isOpaque = false         uiView.backgroundColor = UIColor.white         uiView.loadHTMLString(text, baseURL: nil)     } } Here is how I am implementing the WebView on DetailView NewsItemWebView(text: item.PageContent) .frame(height: 450) Any help on how I can make links open in a browser would be great. Thanks in advance.
3
1
6.1k
Mar ’24
how to prevernt "webViewWebContentProcessDidTerminate:"happen?
we have wkwebView page which use js bridge to launch camera to take photos. some times the "webViewWebContentProcessDidTerminate:" get called ,we have to relaod the page(it don't,the page will go blankl or unresponsive),but then the user content was lost. By my experience,this is associate with memory。at the moment we take photo,the total memory useage get high more the 10~20M high. but when I don't l;aucn the camera,it's worked well. i have question about this. how to reduce the memory useage by camera at the moment?I has already add @autoreleasepool to the take photo finish event,it's get down when finished, it has a peak but I want it keep steady。 as we know the wkwebview work in independent process,how the memory useage can affect the wk process? any other way to prevent this? please help!
1
0
1.5k
Aug ’23
Apple Music Kit Web API - User's Top Played Songs/Artists
Hello everyone! I am using the web version of the Apple Music Kit API, and similar to how Apple is able to produce a user's year in rewind playlist showing the most played artists/songs from a year, I am trying to replicate it for either a year or all time. I have been searching the internet for days trying to figure it out, but I've been completely stuck. I am able to make the following HTTP request successfully. GET https://api.music.apple.com/v1/me/library/songs/ which returns back the user's library of songs, but I haven't figured out how to get the play count. I have tried adding a query like such ?extend=playCount, but that doesn't work. I can see here that the Swift Music Kit API is able to extend a play count property, but I haven't been able to figure it out for Web. Ideally, I am looking for an endpoint that just shows a user's top artist/tracks similar to Spotify, however, whenever I try to use the heavy in rotation endpoint here, it always returns an empty array. The way that I have described is the long-roundabout way where I'll have to fetch each individual song and sort by playCount. But if anyone happens to know how I can do either of the options I've described, it will be truly appreciated ! I've seen other forums posts from years ago, but hopefully there's been a discovered way. Thank you!
2
1
1.8k
Sep ’23
Camera preview is missing while using torch on web view
We have QR-scanner feature implemented on web view (WKWebView). If it's dark we want to light our QR-code using flashlight in iPhone. In general, this feature works, but without flashlight. But have that problems: If we turn on torch then camera preview disappears. If turn off torch then camera preview appears. Do you have any idea why it's so? And how can we sort it out? Thanks
2
0
1.3k
Oct ’23
Insert Images to iCloud Notes Web on Windows
Dear Apple Developers, I am an avid user of iCloud Notes Web on Windows 10, and I have noticed that a crucial functionality is currently missing – the ability to insert or paste images. As someone who frequently uses the Notes app in both Windows and the Apple ecosystem, I believe adding this feature to iCloud Notes Web would greatly improve the user experience. Given that many of us use iCloud Notes to keep track of important information, including images, this missing feature is a significant inconvenience. Without it, users may be forced to resort to alternative products like OneNote. I strongly recommend that you consider adding the ability to insert or paste images to iCloud Notes Web in order to better serve your users and provide a more complete and functional notes-taking experience. Thank you for your attention to this matter. Best regards, Byronmonkey
1
1
1.1k
Aug ’23
Enable WKWebView Web Inspector Under Mac Catalyst?
I'm trying to enable the web inspector on WKWebView in a Mac Catalyst app. I'm only doing this for debugging purposes. In the released the web inspector will not be enabled. Doing this under Mac Catalyst does not work:  WKPreferences *prefs = [[WKPreferences alloc]init];   [prefs _setDeveloperExtrasEnabled:YES]; //Assign the WKPreferences to a WKWebViewConfiguration and create the web view.. Is there any way to do this? Thanks in advance.
4
0
1.1k
Oct ’23
WKWebView on Mac Catalyst elementFullscreenEnabled set to YES on WKPreferences but it does not work
Setting elementFullscreenEnabled property to YES on WKPreferences is not honored on Mac Catalyst.  WKWebViewConfiguration *webViewConfig = [[WKWebViewConfiguration alloc]init];  WKPreferences *prefs = [[WKPreferences alloc]init]; prefs.elementFullscreenEnabled = YES;   webViewConfig.preferences = prefs; //then create the WKWebView.. I load a Youtube url in the WKWebView. Youtube complains that the browser doesn't support full screen. Is there a workaround? Full screen does work in an AppKit app though using the exact same API...though it causes an Autolayout crash (I will be making another thread about that separate issue shortly).
4
0
920
Oct ’23
Does Web Push Notification Actions work on iOS 16.4 ?
I managed to get my Progressive Web App to send notifications to users via Web Push. However, it seems that the definable actions are not working. In Chrome, there is a button in the notification. If you click it, you get an overview of the available actions that the user can click. When I look at the notification on iOS, I only see the "View" action. My self-defined actions seem to be ignored and not displayed. Also, the "notificationclick" event should be executed by the browser as soon as the notification is clicked. In the Serviceworker I listened to the event and tried to link to a specific page of the PWA. In Chrome and Firefox this works fine. In Safari / iOS I only get to the start page of the PWA. Are the notification actions not yet supported with WebKit 16.4 ?
7
2
3.9k
Sep ’23
Occasional WKWebView didFinishNavigation:(WKNavigation*)navigation does not execute
When launching an app on iOS 16.3.1 (or other iOS 16+ versions) and opening a webpage in a webview, after using it for a while (opening and closing pages, switching to background, locking the screen, etc.), there may be occasional instances where the webview page continues to show as loading (for more than ten minutes), and this is due to the fact that the method - (void)webView:(WKWebView*)webView didFinishNavigation:(WKNavigation*)navigation was not called. Once this situation occurs, any subsequent attempt to open a webview page will fail to load. The symptom is that the method - (void)webView:(WKWebView*)webView didFinishNavigation:(WKNavigation*)navigation is not called. If the app is restarted, everything will be restored. This issue has been observed on iOS 16+ with a higher chance of recurrence on 16.3.1. I don't know if you handsome guys have encountered this situation before.
3
0
765
Sep ’23
WKWebView inline media playback issue
I have enabled inline media playback with code as below: let config = WKWebViewConfiguration() config.mediaTypesRequiringUserActionForPlayback = [] config.allowsInlineMediaPlayback = true let webView = WKWebView(frame: .zero, configuration: config) But when user touch play button on the video, it's automatically stopped the video and print out some errors as below: 2023-03-30 08:28:46.961218+0700 [22319:217776] [assertion] Error acquiring assertion: <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)}> 2023-03-30 08:28:46.961404+0700 [22319:217776] [ProcessSuspension] 0x14dfe8820 - ProcessAssertion: Failed to acquire RBS assertion 'WebKit Media Playback' for process with PID=22415, 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)} 2023-03-30 08:28:46.966357+0700 [22319:217776] [assertion] Error acquiring assertion: <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)}> 2023-03-30 08:28:46.966553+0700 [22319:217776] [ProcessSuspension] 0x14dfe8870 - ProcessAssertion: Failed to acquire RBS assertion 'WebKit Media Playback' for process with PID=22319, 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)} 2023-03-30 08:28:46.968951+0700 [22319:217776] [assertion] Error acquiring assertion: <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)}> 2023-03-30 08:28:46.969615+0700 [22319:217776] [ProcessSuspension] 0x14dfe88c0 - ProcessAssertion: Failed to acquire RBS assertion 'WebKit Media Playback' for process with PID=22422, 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)} What's the solution for this issue? Please help!
4
0
1.6k
May ’24
JavaScriptCore / WkWebView JavaScript engine speed comparison
I ran a series of CPU-intensive tests, with code written in JavaScript on my iPad. I can execute the JavaScript code using either JavaScriptCore, or by using a WkWebView and making it load and execute the JavaScript. I found that JavaScriptCore is 12 to 15 times slower than WKWebView (18.3 s instead of 1.1 s). That seems huge. Is there any way to speed it up? Is there any reason why it's so slow? While we're at it, are there differences between the WebAssembly engine in JavaScriptCore and the one in WkWebView?
1
0
1.3k
Jul ’23
Safari Extension browser.tabs.query returns invalid results
When you have a blank Safari new tab open, the browser.tabs.query API inaccurately includes those tabs in results that include a url or title in the query options. To reproduce, open several tabs, and a blank new tab. Open the background page devtools, and execute the following command: browser.tabs.query({url: 'https://github.com/'}, console.log) In addition to any potentially valid results (if you have github.com open, for example), there will also be an entry for the blank tab, which has an empty, non-matching URL. Tab { active: true, audible: false, height: 1095, highlighted: true, id: 6, incognito: false, index: 3, isArticle: false, isInReaderMode: false, mutedInfo: {muted: false}, pendingUrl: "", pinned: false, status: "complete", title: "", url: "", width: 1792, windowId: 1 } I hope that this bug can be addressed, as it causes some unexpected behavior.
1
0
668
Jun ’24
WKWebView displays white screen on some devices
Hello, I have an app that only contains a WKWebView and loads an URL at startup and that is almost all. It has been working fine for years but for about a month (I guess) some clients reported only whitescreen comes up when the app is opened. I have no idea what has changed and since it does not happen any of my device I cannot investigate what is wrong. I've been reported that it shows white screen on iPhone X (iOS 16.5.2) and also on iPhone 14 Pro Max as well. But it is running completely fine most of the devices, including my iPhone 11. The whole code is like this: // // ViewController.swift // import UIKit import WebKit class ViewController: UIViewController { var webView: WKWebView! var request: URLRequest! @IBOutlet var webViewContainer: UIView! override func viewDidLoad() { super.viewDidLoad() NSLog("View loading...") // 1 let contentController = WKUserContentController(); contentController.add( self, name: "route" ) // 2 let config = WKWebViewConfiguration() config.userContentController = contentController let url = URL(string: "https://www.someurl.com/m/?app=ios")! let request = URLRequest(url: url) webViewContainer = UIView() // 3 webView = WKWebView(frame: webViewContainer.bounds, configuration: config) webView.allowsBackForwardNavigationGestures = false webView.translatesAutoresizingMaskIntoConstraints = false webViewContainer.addSubview(webView) webView.leadingAnchor.constraint(equalTo: webViewContainer.leadingAnchor, constant: 0).isActive = true webView.trailingAnchor.constraint(equalTo: webViewContainer.trailingAnchor, constant: 0).isActive = true webView.topAnchor.constraint(equalTo: webViewContainer.topAnchor, constant: 0).isActive = true webView.bottomAnchor.constraint(equalTo: webViewContainer.bottomAnchor, constant: 0).isActive = true /* DispatchQueue.main.async { self.webView.load(request) } */ webView.load(request) view = webViewContainer NSLog("View did loaded.") } @available(iOS 10.0, *) func startNavigation(dict: NSDictionary) { let lat = dict["lat"] as? Double ?? 41.0000 let lng = dict["lng"] as? Double ?? 28.000 openMaps(latitude: lat, longitude: lng, title: "Hakan Altın") } @available(iOS 10.0, *) func openMaps(latitude: Double, longitude: Double, title: String?) { let application = UIApplication.shared let coordinate = "\(latitude),\(longitude)" let encodedTitle = title?.addingPercentEncoding(withAllowedCharacters: .urlQueryAllowed) ?? "" let handlers = [ ("Apple Maps","http://maps.apple.com/?q=\(encodedTitle)&ll=\(coordinate)"), ("Google Maps", "comgooglemaps://?q=\(coordinate)"), ("Yandex Maps","yandexmaps://build_route_on_map/?lat_to=\(latitude)&lon_to=\(longitude)"), ("Waze", "waze://?ll=\(coordinate)"), ("Citymapper", "citymapper://directions?endcoord=\(coordinate)&endname=\(encodedTitle)") ] .compactMap { (name, address) in URL(string: address).map { (name, $0) } } .filter { (_, url) in application.canOpenURL(url) } NSLog("Navigation apps count:\(handlers.count)") guard handlers.count > 1 else { if let (_, url) = handlers.first { application.open(url, options: [:]) } return } let alert = UIAlertController(title: "Please choose navigation application", message: nil, preferredStyle: .actionSheet) handlers.forEach { (name, url) in alert.addAction(UIAlertAction(title: name, style: .default) { _ in application.open(url, options: [:]) }) } alert.addAction(UIAlertAction(title: "Cancel", style: .cancel, handler: nil)) self.present(alert, animated: true, completion: nil) } } extension ViewController:WKScriptMessageHandler { func userContentController(_ userContentController: WKUserContentController, didReceive message: WKScriptMessage) { NSLog("Command received from browser") if message.name == "route", let dict = message.body as? NSDictionary { if #available(iOS 10.0, *) { startNavigation(dict: dict) } else { // Fallback on earlier versions } } else { NSLog("Unknown browser command?!"); } } } // // AppDelegate.swift // import UIKit @available(iOS 13.0, *) @main class AppDelegate: UIResponder, UIApplicationDelegate { var window: UIWindow? func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool { // Override point for customization after application launch. return true } // MARK: UISceneSession Lifecycle func application(_ application: UIApplication, configurationForConnecting connectingSceneSession: UISceneSession, options: UIScene.ConnectionOptions) -> UISceneConfiguration { // Called when a new scene session is being created. // Use this method to select a configuration to create the new scene with. return UISceneConfiguration(name: "Default Configuration", sessionRole: connectingSceneSession.role) } func application(_ application: UIApplication, didDiscardSceneSessions sceneSessions: Set<UISceneSession>) { // Called when the user discards a scene session. // If any sessions were discarded while the application was not running, this will be called shortly after application:didFinishLaunchingWithOptions. // Use this method to release any resources that were specific to the discarded scenes, as they will not return. } } Note: I've also replaced the URL content with only a red-background TEST page in order to eliminate if any javascript error cause the issue but yet clients still get all white blank screen. Any ideas?
5
1
2.6k
Oct ’23
iOS 17 beta Webkit build error
We have been testing on new iOS 17 beta for objective C iOS App project. This project import another library using Cocoapod. The library use Webkit and other frameworks. And when we built to iOS 17 emulator or device, we got the same build errors as following. I did search about changes on Webkit from iOS 17 but no information was found. Does anybody have same error or not? please give us some advices. Thanks
3
0
1k
Aug ’23
Issue with PWA Push Notifications: Unable to Redirect to Specified URL on iOS
I am currently facing an issue with PWA (Progressive Web App) push notifications on iOS and would greatly appreciate your assistance in resolving it. The problem I am experiencing is that when attempting to open a specific link from the notificationclick method using clients.openWindow('/messages'), the expected redirection to the "messages" page does not occur. Instead, the PWA opens without navigating to the desired destination. I want to emphasize that this issue is unique to iOS devices. If you have encountered a similar issue or have any suggestions on how to resolve it, please share your thoughts. Thank you in advance for your support and valuable suggestions.
8
2
1.9k
Oct ’23
PrintKitUI random crash
Code to print self.airPrintWebView.loadHTMLString(html, baseURL: nil) self.view.add(subView:self.airPrintWebView) let formatter = self.airPrintWebView.viewPrintFormatter() //1.5" margins for the page formatter.perPageContentInsets = UIEdgeInsets(top: HALF_INCH_INSET, left: ONE_INCH_INSET, bottom: ONEHALF_INCH_INSET, right: ONE_INCH_INSET) let activityVC = UIActivityViewController(activityItems: [formatter], applicationActivities: nil) // Prevents iBook and PDF from being options activityVC.excludedActivityTypes = [.openInIBooks, .markupAsPDF] activityVC.completionWithItemsHandler = { (activity, success, items, error) in self.airPrintWebView.removeFromSuperview() if shouldRemoveSenderButton { sender.removeFromSuperview() } PredictSpringApplication.sharedInstance.psAlertBlockView?.isHidden = false } if PSUtil.isIpad() { activityVC.popoverPresentationController?.sourceView = self.airPrintWebView activityVC.popoverPresentationController?.sourceRect = sender.frame } self.present(activityVC, animated: true, completion: nil) Crash Crashed: com.apple.main-thread 0 CoreGraphics 0x107e6c CGPDFDocumentIsEncrypted + 12 1 PrintKitUI 0x586b0 -[UIPrintPreviewPageFetcher redrawQuicklookPDF:] + 104 2 PrintKitUI 0x28f4c -[UIPrintPreviewViewController updateQuicklookPDF] + 148 3 Foundation 0xa6f14 NSBLOCKOPERATION_IS_CALLING_OUT_TO_A_BLOCK + 24 4 Foundation 0x7b020 -[NSBlockOperation main] + 104 5 Foundation 0x7afb0 NSOPERATION_IS_INVOKING_MAIN + 16 6 Foundation 0x3c4d8 -[NSOperation start] + 708 7 Foundation 0x3c20c NSOPERATIONQUEUE_IS_STARTING_AN_OPERATION + 16 8 Foundation 0x4189c __NSOQSchedule_f + 172 9 libdispatch.dylib 0x12fc4 _dispatch_block_async_invoke2 + 148 10 libdispatch.dylib 0x3eac _dispatch_client_callout + 20 11 libdispatch.dylib 0x126a4 _dispatch_main_queue_drain + 928 12 libdispatch.dylib 0x122f4 _dispatch_main_queue_callback_4CF + 44 13 CoreFoundation 0x98c28 CFRUNLOOP_IS_SERVICING_THE_MAIN_DISPATCH_QUEUE + 16 14 CoreFoundation 0x7a560 __CFRunLoopRun + 1992 15 CoreFoundation 0x7f3ec CFRunLoopRunSpecific + 612 16 GraphicsServices 0x135c GSEventRunModal + 164 17 UIKitCore 0x39d6e8 -[UIApplication _run] + 888 18 UIKitCore 0x39d34c UIApplicationMain + 340 19 PSStore 0xbaa0 main + 2 (main.swift:2) 20 ??? 0x1b94fedec (Missing) Any body able to solve this random crash ?
7
0
1.2k
Sep ’23