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

Posts under WebKit tag

200 Posts
Sort by:

Post

Replies

Boosts

Views

Activity

window.open() does not return a valid object since MacOS14.4
I have the following html that is opened in a WKWebView. <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8" /> <meta name="viewport" content="width=device-width, initial-scale=1.0" /> <title>Popup Window Test</title> </head> <body> <textarea id="myTextarea" cols="5" rows="1">Empty</textarea> <script> function openWindow() { const popup = window.open( "https://www.apple.com/", "PopupSample", "width=400,height=400,dialog=yes,dependent=yes,scrollbars=yes,location=yes" ); console.log("Popup closed: ", popup.closed); document.getElementById("myTextarea").value = popup.closed ? "Closed" : "Open"; const timer = setInterval(() => { console.log(popup.location.href); if (popup.closed) { clearInterval(timer); console.log("Popup closed: ", popup.closed); document.getElementById("myTextarea").value = "Closed"; } }, 1000); } </script> <button onclick="openWindow()">Open Window</button> </body> </html> When I click the button and open page "https://www.apple.com/" in another WKWebView, the javascript code does not work as expected here, the popup object returned from window.open() does not refer to the valid window object, and the closed property is set to true even the new popup window is still alive. This is a regression since MacOS14.4 updated, I've reported to apple DTS, but they said it's out of their scope. Does anyone has any clue about this?
0
0
269
May ’24
[WKWebView takeSnapshotWithConfiguration:completionHandler:] function does not work
- (void)viewDidLoad { [super viewDidLoad]; UIBarButtonItem *rightButton = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemAdd target:self action:@selector(rightButtonTapped:)]; self.navigationItem.rightBarButtonItem = rightButton; WKWebViewConfiguration *configuration = [[WKWebViewConfiguration alloc] init]; _webView = [[WKWebView alloc] initWithFrame:self.view.bounds configuration:configuration]; _webView.navigationDelegate = self; [self.view addSubview:_webView]; NSURL *url = [NSURL URLWithString:@"https://www.apple.com"]; NSURLRequest *request = [NSURLRequest requestWithURL:url]; [_webView loadRequest:request]; } - (void)rightButtonTapped:(UIBarButtonItem *)sender { NSLog(@"self.webView.scrollView.contentSize.height:%f", self.webView.scrollView.contentSize.height); WKSnapshotConfiguration* configuration = [WKSnapshotConfiguration new]; configuration.rect = CGRectMake(0, 0, self.webView.scrollView.contentSize.width, self.webView.scrollView.contentSize.height); // configuration.afterScreenUpdates = NO; [self.webView takeSnapshotWithConfiguration:configuration completionHandler:^(UIImage * _Nullable snapshotImage, NSError * _Nullable error) { if (error) { NSLog(@"fail"); } else { NSLog(@"succ"); } }]; } Running the code above, I get a blank image
0
0
176
May ’24
WKScriptMessageHandlerWithReply and strict concurrency checking
Hi, I'm trying to implement a type conforming to WKScriptMessageHandlerWithReply while having Swift's strict concurrency checking enabled. It's not been fun. The protocol contains the following method (there's also one with a callback, but we're in 2024): func userContentController( controller: WKUserContentController, didReceive message: WKScriptMessage ) async -> (Any?, String?) WKScriptMessage's properties like body must be accessed on the main thread. But since WKScriptMessageHandlerWithReply is not @MainActor, neither can this method be so marked (same for the conforming type). At the same time WKScriptMessage is not Sendable, so I can't handle it in Task { @MainActor in this method, because that leads to Capture of 'message' with non-sendable type 'WKScriptMessage' in a `@Sendable` closure That leaves me with @preconcurrency import - is that the way to go? Should I file a feedback for this or is it somehow working as intended?
3
0
249
May ’24
Blob URLs not Working on iOS 17.4.1
Hi Apple Team, We have a PWA which supports downloading and playback for audio and video content. Downloaded content is stored in IndexedDB in the form of blobs and blob URLs are generated on runtime through which content is played. We have observed that the blob URLs have stopped working on iOS 17.4.1. They work on iOS 17.4 and iOS 17.3 as well. This feature is very critical for us as it is the heart of the offline mode of the app. Thanks!
1
0
418
May ’24
WebKit Framework for watchOS
As part of a university project, we need to be able to display a website on an Apple Watch and log in to a service. Is it possible to get access to the WebKit framework in a watchOS app? We also need to be able to execute JavaScripts in the browser so that the login process works.
2
0
250
Apr ’24
IndexedDB in WebView, get deleted?
Hi. I plan to use a WebView in an iOS app (SWIFT) and this should run a web app with WASM and using IndexedDB for permanent credentials. I found rumors and information on Apple deleting data in IndexedDB and localStorage after 7 days (see links below). But I found no official information that tells me if this is true for my WebView in my ordinary mobile App (not PWA). A test cycle over a week to find out is hard to do... Is there any reliable and clear information on this and am I affected? Thank you! . Links about this topic: https://news.ycombinator.com/item?id=28158407 https://www.reddit.com/r/javascript/comments/foqxp9/webkit_will_delete_all_local_storage_including/ https://searchengineland.com/what-safaris-7-day-cap-on-script-writeable-storage-means-for-pwa-developers-332519
0
0
281
Apr ’24
ProxyConfiguration in WKWebView doesn't allow trusting self-signed certificate
I have an HTTP3 relay setup and I'm trying to get WKWebView traffic to use it. The relay has a self-signed certificate for TLS traffic. When using URLSession to make a call, everything works as expected, but in WKWebView, it doesn't. Here is how I setup my ProxyConfiguration let options = NWProtocolTLS.Options() // sample options to trust any certificate for testing sec_protocol_options_set_verify_block(options.securityProtocolOptions, { (sec_protocol_metadata, sec_trust, sec_protocol_verify_complete) in sec_protocol_verify_complete(true) }, DispatchQueue.global()) let relayServer = ProxyConfiguration.RelayHop(http3RelayEndpoint: relayEndpoint, tlsOptions: options) let relayConfig = ProxyConfiguration(relayHops: [relayServer]) I connect that to my webview by simply doing the following: let configuration = WKWebViewConfiguration() configuration.websiteDataStore = WKWebsiteDataStore.nonPersistent() configuration.websiteDataStore.proxyConfigurations = [relayConfig] let webView = WKWebView(frame: .zero, configuration: configuration) The sec_protocol_options_set_verify_block is never called for the WKWebView (it is when I use URLSession) I get the following error in XCode [pageProxyID=7, webPageID=8, PID=73105] WebPageProxy::didFailProvisionalLoadForFrame: frameID=1, isMainFrame=1, domain=NSURLErrorDomain, code=-1202, isMainFrame=1, willInternallyHandleFailure=0 Is there some API I am missing to get the webview to do custom TLS validation with an HTTP3 relay?
1
2
328
Apr ’24
How to specify "Connection: close" for a request in WKWebView
I would like to specify "Connection: close" for a request that I load in WKWebView - which actually CAN be done by setting the value on the request that is loaded (and it actually works). However, the documentation at https://developer.apple.com/documentation/foundation/nsurlrequest#1776617 states that it shouldn't be used because the URL loading system handles persistent connections for you. So - my question is how can I indicate to the URL Loading System that I do NOT want to use persistent connections for this particular request? Or - am I safe to just set the header even though it's listed as reserved (because - as mentioned - it does work)?
0
0
224
Apr ’24
wkwebview not loading some resource
On ios15, when loading a page, occasionally all resources under a domain name cannot be loaded. the code like this: <html><head> <title>issue page</title> <meta charset="utf-8"> <meta http-equiv="X-UA-Compatible" content="ie=edge"> <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no"> </style></head> <body><div> <script type="text/javascript" src="https://wx.qq.com/open/js/jweixin-1.6.0.js"></script> <script type="text/javascript" src="https://wap.xxxx.com/static/webapp/common_res/3rd/jquery-3.6.2.min.js"></script> <script type="text/javascript" src="https://statres.ok.com/quickapp/js/qa_router.min.js"></script> <script type="text/javascript" src="https://wap.xxxx.com/static/webapp/common_res/js/utils.min.js"></script> </div></html> This is a simplified page code. The problem is that the page cannot be loaded. Resources under wx.qq.com and statres.ok.com can be loaded, but all resources under wap.xxxx.com fail to be loaded. (Debugging via safari) wkwebview did not call back to didFinishNavigation, and the page load progress was stuck at 0.5. And then it didn't go out of time. It just stayed there. Here are some of the solutions I tried: 1、At first I thought it was a resource problem, but everything worked fine when I copied it to safari. In addition, most of the time in my page is fine, but once this problem occurs, the page will no longer load out until I restart the app. 2、thought is to cache problem, repetition, I added NSURLRequestReloadIgnoringLocalCacheData, also was not used. 3、 I captured the system logs through idevicesyslog and found no obvious anomalies in webkit. 4、When I used wireshark to find the problem, wap.xxxx.com did not even initiate dns requests, as if the browser ignored the resource.(Normally, I caught the dns request for this page) Please help me divergent ideas, thank you!
1
0
372
Apr ’24
Error with Download Container on iPadOS17 and Xcode15
From Xcode15, when Download Container in Window > Devices and Simulators for iPadOS17, an error occurs. The specified file could not be transferred. Domain: com.apple.dt.CoreDeviceError Code: 7000 User Info: { DVTErrorCreationDateKey = "2023-11-21 05:52:37 +0000"; NSURL = "file:///Users/administrator/Desktop/<bundle identifer>%202023-11-21%2014:52.14.006.xcappdata/AppData/Library/WebKit/WebsiteData/IndexedDB/v0"; } -- Performing a file system operation failed: Failed to open Library/WebKit/WebsiteData/IndexedDB/v0 for reading, openat(2) returned POSIX error code 62 (parentParam = 51) Domain: com.apple.dt.remoteservices.error Code: 11001 -- Failed to open Library/WebKit/WebsiteData/IndexedDB/v0 for reading, openat(2) returned POSIX error code 62 (parentParam = 51) Domain: NSPOSIXErrorDomain Code: 62 Failure Reason: Too many levels of symbolic links -- System Information macOS Version 14.0 (Build 23A344) Xcode 15.0.1 (22266) (Build 15A507) indexedDB is not used in the app. I was able to download successfully with Xcode15 and iPadOS16. I was able to download successfully with Xcode14 and iPadOS17. Why do I get an error with Xcode15 and iPadOS17?How should I fix it? That you.
9
2
1.6k
Apr ’24
How to Achieve Safari-like Scaling in WKWebView
I am currently developing an iOS app that needs to embed a third-party website. On this website, the best view is achieved in the standard Safari app by pressing the 'Aa' button on the left side of the address bar and setting the zoom to 50%. I want to replicate this 50% scaling in WKWebView, but I'm not sure how to accomplish it. I've tried using webView.pageZoom = 0.5 and setting webView.scrollView.minimumZoomScale = 0.5 webView.scrollView.maximumZoomScale = 0.5 but it doesn't display the same way as it does in Safari. How can I achieve the same scaling effect in WKWebView?
0
0
279
Apr ’24
In iOS17.5 beta, the html code cannot open the camera in WKWebView
in demo ,load index.html into WKWebView, when i click file button, the camera page present and then dismiss quickly ViewController.h @property (nonatomic, strong) WKWebView *wkWebView; @end @implementation ViewController - (void)viewDidLoad { [super viewDidLoad]; WKWebViewConfiguration *configuration = [WKWebViewConfiguration new]; self.wkWebView = [[WKWebView alloc] initWithFrame:CGRectMake(0, 0, 400, 300) configuration:configuration]; NSURL *url = [[NSBundle mainBundle] URLForResource:@"index" withExtension:@"html"]; [self.wkWebView loadFileURL:url allowingReadAccessToURL:[[NSBundle mainBundle] bundleURL]]; self.wkWebView.backgroundColor = [UIColor blueColor]; [self.view addSubview:self.wkWebView]; } index. html <html lang="en"> <head> <meta charset="UTF-8"> </head> <body> <div> <label style="font-size: 40px;">open camera</label> <input type="file" accept="image/*" capture="camera" id="file-input" class="file-input"> </div> </body> </html>
3
0
527
Apr ’24
Webview crashes when keyboard pops up in ios17.4.1
appState=foreground 2024-04-10 10:01:12:439,IPHONE_1ND,10.5.80.6000,3,460000000000000|86dmsu7m2t8cs7w,83D44481-559B-4D5D-BC1F-2E643CF08A16,2088512449022223,exception,-,call_write_crash_log_api,-,-,MonitorPoint_Crash,-,apple-iphone,release,-,-,-,-,-,iPhone16 2,17.4.1,WIFI|--,-,10.5.80.6000,ZbsnB/YU+YsDAEHUUPE53+9a,follow_system_zh-Hans-CN,-,-,-,-,-,-,VoiceOver=0^TimeZone=Asia/Shanghai^AppStatus=background^CIP=(null)^AppSession=195C885D-0152-46E8-8E6D-F6D38D5E0A81^appMode=normal^editionId=300003^lowEnd=T^buildNumber=21E236^simC=2,1,00000000-0000-0000-0000-000000000000 Incident Identifier: 795088EB-76F2-460F-A323-9290DEE9B37F CrashReporter Key: Hardware Model: iPhone16 2 Process: AlipayWallet [972] Path: /private/var/containers/Bundle/Application/EAD57E87-932E-4952-9714-C0B852F3A773/AlipayWallet.app/AlipayWallet Identifier: com.alipay.iphoneclient Version: 10.5.80 (10.5.80.6000) Code Type: ARM-64 Parent Process: [1] Date/Time: 2024-04-10 02:00:47 +0000 OS Version: iPhone OS 17.4.1 (21E236) Report Version: 104 Exception Type: SIGBUS Exception Codes: BUS_ADRERR at 0x16b477fe8 Crashed Thread: 0 Thread 0 Crashed: 0 CoreFoundation 0x0000000190fd5aa8 _generationCountFromListOfSources :104 (in CoreFoundation) 1 CoreFoundation 0x0000000190fd389c -[CFPrefsSearchListSource alreadylocked_generationCountFromListOfSources:count:] :80 (in CoreFoundation) 2 CoreFoundation 0x0000000190f7a3fc -[CFPrefsSearchListSource alreadylocked_getDictionary:] :492 (in CoreFoundation) 3 CoreFoundation 0x0000000190f79f68 -[CFPrefsSearchListSource alreadylocked_copyValueForKey:] :172 (in CoreFoundation) 4 CoreFoundation 0x0000000190f79e9c -[CFPrefsSource copyValueForKey:] :52 (in CoreFoundation) 5 CoreFoundation 0x0000000190f79e50 ___76-[_CFXPreferences copyAppValueForKey:identifier:container:configurationURL:]_block_invoke :32 (in CoreFoundation) 6 CoreFoundation 0x0000000190fcafb4 ___108-[_CFXPreferences(SearchListAdditions) withSearchListForIdentifier:container:cloudConfigurationURL:perform:]_block_invoke :392 (in CoreFoundation) 7 CoreFoundation 0x0000000190fcadc4 _normalizeQuintuplet :356 (in CoreFoundation) 8 CoreFoundation 0x0000000190fcac38 -[_CFXPreferences withSearchListForIdentifier:container:cloudConfigurationURL:perform:] :164 (in CoreFoundation) 9 CoreFoundation 0x0000000190fcab38 -[_CFXPreferences copyAppValueForKey:identifier:container:configurationURL:] :156 (in CoreFoundation) 10 CoreFoundation 0x0000000190fca940 __CFPreferencesCopyAppValueWithContainerAndConfiguration :112 (in CoreFoundation) 11 CoreFoundation 0x000000019101a5ec __CFPreferencesGetAppIntegerValueWithContainer :56 (in CoreFoundation) 12 WebKit 0x00000001a651d77c -[WKWebViewConfiguration init] :232 (in WebKit) 13 WebKit 0x00000001a651de28 -[WKWebViewConfiguration copyWithZone:] :48 (in WebKit) 14 WebKit 0x00000001a64e00f8 -[WKWebView configuration] :28 (in WebKit) 15 WebKit 0x00000001a6d93d54 -[WKContentView(WKInteraction) _cascadeInteractionTintColor] :36 (in WebKit) 16 WebKit 0x00000001a6d93f3c -[WKContentView(WKInteraction) _updateTextInputTraitsForInteractionTintColor] :24 (in WebKit) 17 WebKit 0x00000001a6d9d0d0 -[WKContentView(WKInteraction) _updateTextInputTraits:] :1004 (in WebKit) 18 WebKit 0x00000001a6db5de0 -[WKContentView(WKInteraction) extendedTraitsDelegate] :136 (in WebKit) 19 WebKit 0x00000001a6d93a54 -[WKContentView(WKInteraction) insertionPointColor] :48 (in WebKit) 20 UIKitCore 0x000000019338f674 +[UIKBRenderConfig configForAppearance:inputMode:traitEnvironment:] :272 (in UIKitCore) 21 UIKitCore 0x000000019338eb9c -[UIView(UIKB_UIViewExtras) _inheritedRenderConfig] :332 (in UIKitCore) 22 UIKitCore 0x0000000193d32794 -[UICandidateViewController overrideUserInterfaceStyle] :44 (in UIKitCore) 23 UIKitCore 0x00000001939790c4 ___78-[UIViewController _traitCollectionByApplyingLocalOverridesToTraitCollection:]_block_invoke :172 (in UIKitCore) 24 UIKitCore 0x00000001931fbd10 -[UITraitCollection _traitCollectionByModifyingTraitsCopyOnWrite:] :252 (in UIKitCore) 25 UIKitCore 0x0000000193978b08 -[UIViewController _traitCollectionByApplyingLocalOverridesToTraitCollection:] :116 (in UIKitCore) 26 UIKitCore 0x0000000193201c40 -[UIViewController traitCollection] :228 (in UIKitCore) 27 UIKitCore 0x0000000193206a9c __UIGetCurrentFallbackTraitCollection :180 (in UIKitCore) 28 UIKitCore 0x0000000193205568 _UIViewCommonInitWithFrame :548 (in UIKitCore) 29 UIKitCore 0x00000001932052f4 -[UIView initWithFrame:] :132 (in UIKitCore)
3
0
440
Apr ’24
Syncing UITabBarController selected item state inside of webwrapper -- highlight tab item after webViewBack
I am trying to sync up the selected tab bar item once a user presses back and navigates back in the web wrapper iOS app. Here is how the app works: When a user logs in, they are presented with the Home Screen. To navigate, the select a tab item on the tab bar. This tells webkit to redirect to that URL and then that webpage is shown in the app (wrapped). A back button also appears. When a user presses the back button, the webView.goBack() method sends the user back on in the webView.backForwardList. What happens then is that the user is now on the previous page, however the tab bar has not updated. In other words, the user is back on the first tab but the second tab is highlighted. I tried fixing this by telling the tab bar controller what item to select, however this creates a state malfunction because it also tells the webView to navigate to that url again, so in fact this means that the user isn't going back through web history, but actually is going forward while simulating going back. I need to be able to highlight the tab bar items that sync up with the page that we have gone back to without selecting it. Does anyone have an idea for how to manually highlight or select a tab bar item without actually navigating to that tab bar item? Thank you!
0
0
211
Apr ’24
3 Warning after analyzing myiphone SE 2022
Hi Everyone, I scanned my iPhone SE 3d generation with the iMazing app developed by Amnesty International, and after the scan it detected 3 Warnings on my iphone. Any of you is able to understand what´s the issue is about? That would be great help! Following the 3 Warnings: Warning - Database Query Error - WebKit Observations - 'AppDomain-com.apple.tips/Library/WebKit/WebsiteData/ResourceLoadStatistics/observations.db' cannot be parsed (no such table: ObservedDomains). Warning - Database Query Error - InteractionC - 'HomeDomain/Library/CoreDuet/People/interactionC.db' cannot be parsed (no such table: ZINTERACTIONS). Warning - Database Query Error - InteractionC Attachment - 'HomeDomain/Library/CoreDuet/People/interactionC.db' cannot be parsed (no such table: ZATTACHMENT).
2
0
425
Apr ’24
Mysterious error when using a WKWebView in an InputMethodKit app
I modified an InputMethodKit example (fairly recent one from github, compiled fine and worked as expected on my machine as it was) to create a window with a WKWebView and the window doesn't load. I know that loadView is getting called, but the window never appears after calling showWindow on the window controller and there is a mysterious error in the console: bootstrap_check_in(): (os/kern) unknown error code (44c) From googling this it seems App Sandbox related, but I think I have everything set up correctly (App Sandbox on with outgoing connections allowed) Totally stumped, any help or ideas would be appreciated Here's the relevant code: View controller import Foundation import WebKit import AppKit class InputWindowViewController: NSViewController, WKUIDelegate { var webView: WKWebView! override func loadView() { NSLog("LoadView") webView = WKWebView() self.view = webView webView.uiDelegate = self webView.needsDisplay = true } override func viewDidLoad() { super.viewDidLoad() webView.load(URLRequest(url: URL(string:"https://www.apple.com")!)) } } Window controller import AppKit import Foundation import WebKit class InputWindowController: NSWindowController { var controller: InputWindowViewController? override init(window: NSWindow?) { controller = nil super.init(window: window) } override func loadWindow() { self.window = NSWindow(contentViewController: controller!) } required init?(coder: NSCoder) { controller = nil super.init(coder: coder) } } AppDelegate import Cocoa import InputMethodKit import WebKit // Necessary to launch this app class NSManualApplication: NSApplication { private let appDelegate = AppDelegate() override init() { super.init() self.delegate = appDelegate } required init?(coder: NSCoder) { // No need for implementation fatalError("init(coder:) has not been implemented") } } @main class AppDelegate: NSResponder, NSApplicationDelegate { var server = IMKServer() var candidates = IMKCandidates() var inputWindowController = InputWindowController() func applicationDidFinishLaunching(_ notification: Notification) { // Insert code here to initialize your application server = IMKServer(name: Bundle.main.infoDictionary?["InputMethodConnectionName"] as? String, bundleIdentifier: Bundle.main.bundleIdentifier) inputWindowController = InputWindowController() inputWindowController.controller = InputWindowViewController() inputWindowController.loadWindow() inputWindowController.showWindow(self) candidates = IMKCandidates(server: server, panelType: kIMKSingleRowSteppingCandidatePanel, styleType: kIMKMain) NSLog("tried connection") } func applicationWillTerminate(_ notification: Notification) { // Insert code here to tear down your application } } This code is probably awful in a lot of other ways I don't realize, but I wanted to get a webview window up before I put a bunch of time into this thing XCode 13.4 MacoOS 12.7.4
1
0
303
Apr ’24