Explore the integration of web technologies within your app. Discuss building web-based apps, leveraging Safari functionalities, and integrating with web services.

General Documentation

Post

Replies

Boosts

Views

Activity

Cookies set by AJAX responses not accessible by JS when using WKWebView
Hi, we have really weird issue with one of our website embedded into iOS app using WKWebView. The website has CSRF mechanism implemented and is using some AJAX calls when user interact with it and in response some cookies are returned. Then the JS code wants to access these cookies to set proper value for next request header. Unfortunately when using document.cookie JS command these cookies are not there. However they are sent within another requests and I can see them from Safari Developer Inspector connected to my device or iOS Simulator. Another interesting thing is that the same website and solution works fine on Safari browser and with SFSafariViewController displayed inside our app. We've tried using various things for WKWebView configuration like nonPersistent data store, but without success. Does anyone have any idea how to deal with such issue and why it doesn't work with WKWebView?
0
2
147
1w
Student in need of help
So the css in this post is broken only on iphones if we view it on an android phone then there is no issues, and I can't figure out why? the scroll background is looking wired, but it's defined by: width: 60px; height: 60px;... Anyhow i'm just wondering why the css is not working as it should? Please help me 🙏
0
0
115
1w
Content blocker using Safari web extensions.
We are trying to implement ad blockers using the Safari web extension, and we are implementing this using the declarativeNetRequest, with a manifest version 2. We have added a json file which contains a rule set for over 22000 URLs, does content blocker have a limit to the number of rules we set in json? Although it does work fine, sometimes we see the behaviour different on simulators and on clearing the cache it works fine is this expected?
4
0
176
1w
Crash WKWebView startURLSchemeTask
When I use - webView: startURLSchemeTask: , I had some crash with iOS 14(14.1, 14.2, 14.3, 14.4). There is the code: - (void)webView:(WKWebView *)webView startURLSchemeTask:(id<WKURLSchemeTask>)urlSchemeTask API_AVAILABLE(ios(11.0)){ /// iOS 13可能有崩溃 NSString *version = [[UIDevice currentDevice] systemVersion]; if ([version containsString:@"13."]) { SEL sel = sel_registerName("_setLoadResourcesSerially:"); id webViewClass = NSClassFromString(@"WebView"); if ([webViewClass respondsToSelector:sel]) { #pragma clang diagnostic push #pragma clang diagnostic ignored "-Warc-performSelector-leaks" [webViewClass performSelector:sel withObject:@(FALSE)]; #pragma clang diagnostic pop } }//fi self.holdUrlSchemeTasks[urlSchemeTask.description] = @(TRUE); SCNADHtmlPreloadContext *context = [[SCNADHtmlPreloadContext alloc] init]; context.requestURL = [urlSchemeTask.request.URL.absoluteString copy]; // line 50 context.request = [urlSchemeTask.request copy]; // todo with context ...... } - (void)webView:(WKWebView *)webView stopURLSchemeTask:(id<WKURLSchemeTask>)urlSchemeTask API_AVAILABLE(ios(11.0)){ dispatch_async(dispatch_get_main_queue(), ^{ self.holdUrlSchemeTasks[urlSchemeTask.description] = @(FALSE); }); } There is the crash info: #0 Thread SIGSEGV SEGV_ACCERR WebCore void ***::__visitor_table<***::Visitor<WebCore::FormData::resolveBlobReferences(WebCore::BlobRegistryImpl*)::$_8, WebCore::FormData::resolveBlobReferences(WebCore::BlobRegistryImpl*)::$_9, WebCore::FormData::resolveBlobReferences(WebCore::BlobRegistryImpl*)::$_10>, ***::Vector<char, 0ul, ***::CrashOnOverflow, 16ul, ***::FastMalloc>, WebCore::FormDataElement::EncodedFileData, WebCore::FormDataElement::EncodedBlobData>::__trampoline_func<WebCore::FormDataElement::EncodedBlobData>(***::Visitor<WebCore::FormData::resolveBlobReferences(WebCore::BlobRegistryImpl*)::$_8, WebCore::FormData::resolveBlobReferences(WebCore::BlobRegistryImpl*)::$_9, WebCore::FormData::resolveBlobReferences(WebCore::BlobRegistryImpl*)::$_10>&, ***::Variant<***::Vector<char, 0ul, ***::CrashOnOverflow, 16ul, ***::FastMalloc>, WebCore::FormDataElement::EncodedFileData, WebCore::FormDataElement::EncodedBlobData>&) + 68 WebKit::WebURLSchemeTask::nsRequest() const + 68 -[SNADURLSchemeHandler webView:startURLSchemeTask:] (SNADURLSchemeHandler.m:50) Who knows the reason, please help me, thanks!
0
0
101
1w
How to change geolocation settings on WKWebView
We're developing an application using location feature in WKWebView. When accessing a URL that uses location information from WebView, a dialog box saying " Would Like To Use Your Current Location - Don't Allow or OK". If "Dont allow" is selected multiple times, the dialog will disappear and the location setting for that URL will be fixed as "Don't Allow". In Safari, I can change that location settings for each URL, But Application's WebView does not have such settings UI. How do I clear or change the setting so that location information is no longer available? It seems that reinstalling the application will clear the WebView location settings.
0
0
129
1w
WKWebKit crash - blank screen
We are using a WKWebKit based Cordova application and we are getting WKWebKit crash resulting in blank page. The same web app is working in browser and other platforms. Upon investigation we found the memory used in iOS app using safari debugger / profiler. The total memory used is 870.13 MB. Break up of that is Page: 549MB JavaScript: 321.13MB However, the max comparison for memory shown in safari is 1.37GB while the current usage is 870.13MB. Is there any internal memory calculation for crash cutoff? In this case the current memory is around 62% of the max comparison. Hence, we need to know whether this is the expected behaviour from iOS platform. JetsamEvent-2024-05-23-102822.ips
0
0
189
2w
Enabling Picture-in-Picture (PiP) in WKWebView
I'm working on a web browser App that's distributed via the App Store. This app renders web pages using WKWebView. Our users are requesting a way for us to allow them to play videos in Picture in Picture. After some investigation, we noticed that in order to allow PiP videos in our browser in the sandboxed environment, we need to add the com.apple.PIPAgent entitlement under the com.apple.security.temporary-exception.mach-lookup.global-name option. We tried to submit our app with this entitlement, but unfortunately, we were rejected: Guideline 2.4.50) - Performance We've determined that one or more temporary entitlement exceptions requested for this app are not appropriate and will not be granted: com.apple.security.temporary-exception.mach-lookup.global-name com.apple.P|PAgent We would like to have access to this entitlement so we can offer PiP to our users. We already created a radar about this as well: FB13814428 Additionally, we have another radar (FB13557716) regarding allowing the usage of a private flag _allowsPictureInPictureMediaPlayback, which would also be required to enable us to use PiP. Is there any way in which we can currently enable PiP? Would opening a TSI help here?
1
11
366
2w
PaymentRequest TypeError
Details at Stack Overflow We're trying to enable Apple Pay on the Web for a web application of ours, but getting this error when trying to construct the PaymentRequest object: TypeError: Type error: PaymentRequest@[native code] startApplePay@https:-myurl-:319:47 onclick@https://-myurl-:606:14:undefined
0
0
252
2w
iOS 17.5.1 safari extension - background scripts not working properly
We had developed an iOS Safari web extension (which uses non-persistent background scripts) that functioned properly until iOS 17.3. However, I've encountered inconsistent behavior on iOS 17.4.1, 17.5, and 17.5.1. Upon further debugging, I noticed that the background scripts often become idle and are unloaded frequently. They are not loaded again even for the registered webNavigation events and only trigger when interacting with the extension popup menu. This is also mentioned here. I had tried this in both manifest versions 2 & 3. I had tried using service_worker for background scripts. But, none of it seems to resolve this issue. Could you please clarify if this is a bug or an intended behavior? Our extension relies on webNavigation events without users having to interact with the popup menu often.
1
5
313
2w
JavaScript Not Executing in WebView When Modally Presenting UIViewController on iOS 17.5.1
Issue Summary: I have encountered an issue where JavaScript does not execute in a WebView when another UIViewController is presented modally with modalPresentationStyle.fullScreen. This problem only occurs on physical devices running iOS 17.5.1. The issue is not present on iOS 17.5 simulators or devices running iOS 17.4.1 or earlier. Reproduction Steps: Create a ViewController with a WebView. Load a web page (e.g., https://apple.com) in the WebView. Present another ViewController modally with modalPresentationStyle.fullScreen. Verify that JavaScript execution in the initial WebView stops working. Test Code: import UIKit import WebKit class ViewController: UIViewController { override func viewDidLoad() { super.viewDidLoad() // Set up the WebView let configuration = WKWebViewConfiguration() let webView = WKWebView(frame: view.frame, configuration: configuration) view.addSubview(webView) webView.frame = view.frame if #available(iOS 16.4, *) { webView.isInspectable = true } else { // Fallback on earlier versions } webView.load(URLRequest(url: URL(string: "https://apple.com")!)) } override func viewDidAppear(_ animated: Bool) { super.viewDidAppear(animated) let navigationController = UINavigationController(rootViewController: TargetViewController()) navigationController.modalPresentationStyle = .fullScreen present(navigationController, animated: true) } } class TargetViewController: UIViewController { override func viewDidLoad() { super.viewDidLoad() // Set up the WebView let webView = WKWebView(frame: view.frame, configuration: WKWebViewConfiguration()) view.addSubview(webView) webView.frame = view.frame if #available(iOS 16.4, *) { webView.isInspectable = true } else { // Fallback on earlier versions } webView.load(URLRequest(url: URL(string: "https://apple.com")!)) } } Observations: The JavaScript within the WebView stops executing only on physical devices running iOS 17.5.1. This issue does not occur on the iOS 17.5 simulator. Devices running iOS 17.4.1 or earlier do not experience this issue. Request for Assistance: Could you please provide any insights or potential workarounds for this issue? Additionally, if this is a known bug, any information on upcoming fixes would be highly appreciated. Thank you.
2
0
306
2w
SFSafariViewControllerDelegate not being called for redirects
This method does not seem to work consistently: SFSafariViewControllerDelegate.safariViewController(_ controller: SFSafariViewController, initialLoadDidRedirectTo URL: URL) It was working 100% of the time until this week for me, now it has about a 1-5% success rate for detecting redirects. The docs are not clear: @discussion This method may be called even after -safariViewController:didCompleteInitialLoad: if the web page performs additional redirects without user interaction. Code snippet from calling UIViewController that conforms to SFSafariViewControllerDelegate: let config = SafariViewController.Configuration() config.entersReaderIfAvailable = false let vc = SFSafariViewController(url: url, configuration: config) vc.delegate = self self.safariViewController = vc print(self.safariViewController?.delegate) self.present(vc, animated: true) Did something change? How can I make this consistent again?
1
0
243
2w
SFSafariViewControllerDelegate method for initialLoadDidRedirectTo not being triggered for subsequent reloads as specified in the docs
For some reason, not all of the time but most of the time, the SFSafariViewControllerDelegate method for initialLoadDidRedirectTo is not being triggered for subsequent reloads as specified in the docs. @discussion This method may be called even after -safariViewController:didCompleteInitialLoad: if the web page performs additional redirects without user interaction. I am allowing a user to log in with an OAuth 2.0 Provider on the Safari browser and expecting to detect the redirect to continue the flow from the app once their credentials have securely been consumed by the IdP in Safari. It was working consistently. It went from a 100% success rate up until this week to maybe 1/20 successful redirects. Code snippet: let config = SafariViewController.Configuration() config.entersReaderIfAvailable = false let vc = SFSafariViewController(url: url, configuration: config) vc.delegate = self self.safariViewController = vc print(self.safariViewController?.delegate) self.present(vc, animated: true) Why is it not always detecting the redirects?
1
0
279
2w
iOS 17.5.1 not updating permisions.
In this version of iOS our web extension is not allowed to run after allowing it run on all sites via clicking the aA icon in safari. Quitting safari makes it work so it is like the permisions are set but the extension code is never injected into the browser, this behaviour has been replicated with multiple different extension form different vendors.
0
0
200
2w
Safari Web Extension background script becomes unresponsive after 30 seconds
I'm experiencing a Safari Web Extension issue where the non-persistant background script seems to crash after 30 seconds even when the content script is messaging it. Here is a minimal-reproducible example. When running in an emulator, the background script will stay responsive forever. However, when running on a physical device, the background script becomes non-responsive after 30 seconds of activity. It never becomes responsive again until I toggle the extensions enable/disable toggle, after which it stays active for 30 seconds and then crashes again.
3
4
603
3w
Safari History Delete ISSUE
My Safari Web Extension uses a service worker and an IndexedDB database (IDB). For what hidden reason or perverse logic when deleting the Safari history all service workers are brutally shutted down and the database emptied of all its contents? And I heard about local storage too... It happens all the time in Safari macOS and iOS. Safari is the only browser in the world that takes the liberty of deleting what it shouldn't. Good Job indeed.
1
0
329
3w
Safari DNR API timing issues
I created a Xcode project to test the DNR updateDynamicRules API performances on Safari (MacOS). https://github.com/radiolondra/TestUpdateDynamicRules Following the instructions in the README file, it's possible to test the extension on Chromium and Firefox browsers (on Windows). The project uses 2 json files containing static rules, enabled by default in the manifest file. These static rules are automatically installed in the browser when the extension is installed. Using the extension popup it is possible to add/remove just one very simple dynamic rule in the browser, a rule that acts on a predefined test domain (https://iana.org). What we want to measure is the time it takes for each browser to add/remove that one dynamic rule. The results for Safari are unacceptable to say the least: Safari: from 6000 to 8000 MILLISECONDS (6/8 seconds!) <<<<<<<<< Chrome: from 5 to 6 MILLISECONDS Firefox: from 5 to 7 MILLISECONDS Notice the time needed by Safari... It would be a good idea to take a look at this monstrosity. Thanks.
5
0
428
3w
WebKit WebKit::WebURLSchemeTask::stop()
1.WebKit WebKit::WebURLSchemeHandler::stopTask(WebKit::WebPageProxy&, unsigned long long) + 80 2.WebKit WebKit::WebURLSchemeHandler::stopTask(WebKit::WebPageProxy&, unsigned long long) + 80 3.WebKit WebKit::WebURLSchemeHandler::stopAllTasksForPage(WebKit::WebPageProxy&) + 108 4.WebKit WebKit::WebPageProxy::stopAllURLSchemeTasks() + 260 5.WebKit WebKit::WebPageProxy::close() + 1168 6.WebKit -[WKWebView dealloc] + 128 7.XHBUIKit -[XHBWebView dealloc] + 84 8.Foundation _NSKVODeallocate + 184 WKWebView 在dealloc 时崩溃,我该怎么处理。
0
0
188
3w
iOS 17.5.1 Xcode WebKit Crash
iOS 17.5.1 Xcode WebKit Crash Hello, I have two iPhone devices that I have. These devices are iOS17.5.1, and all Wk related codes cause Crash. Crash occurs when Xcode Build is complete and the app is running. If you run without connecting to Xcode, Crash does not occur. Error: Thread 1: EXC_BREAKPOINT (code=1, subcode=0x19e88fa18) Xcode 15.4, MacBook Pro 14 Sonoma 14.5 There was no issue with iOS 16.5. WKWebsiteDataStore.default() .fetchDataRecords(ofTypes: WKWebsiteDataStore.allWebsiteDataTypes()) { records in records .forEach { WKWebsiteDataStore.default() .removeData(ofTypes: $0.dataTypes, for: [$0], completionHandler: {}) } } let webConfiguration = WKWebViewConfiguration()webConfiguration.preferences.javaScriptCanOpenWindowsAutomatically = true
0
0
403
3w
iOS17.5 WKWebView
Recently, our app has received feedback that WKWebview will get stuck when opening some web pages, and then the entire web page in the app will have problems opening. The feedback group is iOS17.5 or iOS17.5.1, other systems do not have this problem. Have you ever encountered such problems? and what direction should be taken to solve this problem?
2
1
495
4w