WebKit JS

RSS for tag

Access and modify DOM elements within a webpage, including touch events and visual effects, using WebKit JS.

Posts under WebKit JS tag

200 Posts

Post

Replies

Boosts

Views

Activity

MediaRecorder onstop callback doesn't get called in iOS15
Hi, I'm using MediaRecorder for screen recording of canvas , along with audio. simplified code to implement screen recorder //intialise stream const canvas = document.querySelector('.main-canvas'); const stream = await navigator.mediaDevices.getUserMedia({ audio: true }); for (let track of canvas.captureStream().getTracks()) { stream.addTrack(track); } recorder = new MediaRecorder(stream); chunks = []; recorder.ondataavailable = ({ data }) => { if (data) chunks.push(data); }; recorder.start(); recorder.onstop = () => { const videoBlob = new Blob(chunks, { type: 'video/mp4' }); chunks = [] //stop mic access after use try{ for (let track of stream.getTracks()) { track?.stop(); } }catch(e){} return videoBlob; } so when i call recorder.stop() , the recorder.onstop method is not getting called sometimes randomly. And also in case when recorder.onstop is not called , recorder.ondataavailable is not called even a single time,So it returns empty Blob output. This only occurs in iOS 15 device's , it occurs randomly 40% of the times. Is there any workaround for this, or what is cause of this issue? Thanks in advance
6
2
3.2k
Oct ’23
Webview Application Crash WebProcessProxy & WebPageProxy
I randomly get this crash in my webview application when loading data. There is no pattern to it, it can happen in all areas where images are being loaded into vram. Here is the error: 2023-09-16 19:57:55.404378+0200 Bluelife[3284:194440] [Process x10d004350 - [PID=3445] WebProcessProxy: :didClose: (web process 0 crash) 2023-09-16 19:57:55.404500+0200 Bluelife3284:194440] [Process] 0x10d004350 - [PID=3445 WebProcessProxy::processDidTerminate0rFailedToLaunch: reason=Crash 2023-09-16 19:57:55.404579+0200 Bluelife[3284:194440] [ProcessSuspension] 0x10c01dfe - ProcessAssertion: Failed to acquire RBS Background assertion 'XPCConnectionTerminationWatchdog' for process because PID 0 is invalid 2023-09-16 19:57:55.410251+0200 Bluelife[3284:194440] [Process] 0x130856218 - [pageProxyID=14, webPageID=15, PID=3445] WebPageProxy: :processDidTerminate: (pid 3445), reason=Crash 2023-09-16 19:57:55.411392+0200 Bluelife[3284:211863] [ProcessSuspension] 0x10c01dfe - ProcessAssertion::acquireSync Failed to acquire RBS assertion 'XPCConnectionTerminationWatchdog' for process with PID=0, error: (null) 2023-09-16 19:57:55.424321+0200 Bluelife[3284:194440] [Loading] 0x130856218 - [pageProxID=14, webPageID=15, PID=3445] WebPageProxy::dispatchProcessDidTerminate: reason=Crash
1
1
1.7k
Sep ’23
iOS 17.0 Webkit 'display:flex' issue
When rendering 2 'div' components with 'display:flex' placed on top of each other, the preceding one sometimes comes up. The 'position:absolute' has been set and the second 'div' component is being generated after the first one. However, when inspecting the iOS webview in Safari, I enable-disable the 'display:flex' property, everything starts working again. This is possibly a bug in the layout engine. I tried the same process in iOS 16.4 and there are no issues at all.
3
0
2.7k
Sep ’23
WebKit mic permission
Hello. I'm trying to stop my webview from asking for mic permission every time it runs, as I already handle it out in the application. This is the code I use, but it doesn't seem to run the code for the permission at all (tried printing and debugging, and it doesn't go into it at all). I am using visionOs if that makes a difference. Are there any alternative solutions to this? import SwiftUI import WebKit import AVFAudio struct WebView: UIViewRepresentable { let urlString: String func makeUIView(context: Context) -> WKWebView { let webView = WKWebView() webView.navigationDelegate = context.coordinator if let url = URL(string: urlString) { let request = URLRequest(url: url) webView.load(request) } return webView } func updateUIView(_ uiView: WKWebView, context: Context) {} func makeCoordinator() -> Coordinator { Coordinator() } class Coordinator: NSObject, WKUIDelegate, WKNavigationDelegate { // Handle media capture permissions func webView(_ webView: WKWebView, decideMediaCapturePermissionsFor origin: WKSecurityOrigin, initiatedBy frame: WKFrameInfo, type: WKMediaCaptureType) async -> WKPermissionDecision { return .grant } // Handle URL authentication challenges func webView(_ webView: WKWebView, didReceive challenge: URLAuthenticationChallenge, completionHandler: @escaping (URLSession.AuthChallengeDisposition, URLCredential?) -> Void) { let username = "user" let password = "password" let credential = URLCredential(user: username, password: password, persistence: .forSession) completionHandler(.useCredential, credential) } } } struct AssistantView: View { @Environment(\.dismissWindow) private var dismissWindow var body: some View { WebView(urlString: "https://somelink.com/") .edgesIgnoringSafeArea(.all) .frame(width: 500, height: 800) } }
1
0
1.1k
Aug ’23
Safari / IOS WKWebView waiting for 250 bytes before rendering content. Delaying execution of external .js
We have observed that safari / IOS WKWebView waits for ~250 renderable bytes before it starts to render HTML as received in the browser. This is different from the behaviour in chrome / Firefox where they start to render the content as soon as the first byte is available. We wanted to know if there’s a way to stop this behaviour, to bring parity across the two browsers. Also is there any official doc / announcement establishing this limit of ~250 characters which we’ve found experimentally. Details of our experiment: We created a simple HTTP Server In python that: Emits a stream of (100) characters Sleeps for 3 seconds Emits some more characters You can find the experiment code towards the end of the post The ideal behaviour (which we observed in chrome) is that the content should be rendered progressively. Implying that the 100 characters before the .sleep() should be rendered immediately. This should be followed by a gap of 3 seconds, and then the rest of the characters are displayed. You can see this behaviour where I reload the page: https://drive.google.com/file/d/1JD_ZbghX3OOz_CpSR2iGn_Se7_2HDRTw/view?usp=sharing The text "Before Sleep" followed by a line of 100 dashes is the content before .sleep() which appears immediately. The text “After Sleep” apears after a time of 3 seconds which is the desired behaviour. In safari however, all of the content appears at once after 3 seconds, instead of being rendered progressively as seen here when I reload the page : https://drive.google.com/file/d/1RiD7eFuwGYL5lGIcU1CF2gcpoSysHJ9C/view?usp=sharing However if we increase the number of characters emitted before the .sleep() to ~250 (256 to be exact) safari behaves similar to chrome and the content appears progressively. You can see this here on page reload : https://drive.google.com/file/d/1JlHFbZPdFuIiaAlkgYCWo61amBIysKL1/view?usp=sharing We found this value of ~250 experimentally via hit and trial. Not only rendering, we also found this delaying the execution of external .js (that is present in a separate .js file embedded via tag). To prove this, I added a simple console.log(performance.now()) at the top of the .js file (outside of any function). In safari with artificially inserted ~260 extra bytes this log was printed at ~1 - 1.5 secs. However without the extra bytes this log came at ~3 - 4 seconds. This gap corresponds to the time taken to make rest of the page ready. Note that embedded .js present in the HTML was not affected by this. Wondering if other’s have faced the same problem and if there's an official doc stating this limit / any workarounds. Python HTTP Server code that we executed for our experiment from http.server import BaseHTTPRequestHandler, HTTPServer import time import sys class handler(BaseHTTPRequestHandler): def do_GET(self): self.send_response(200) self.send_header('Content-type','text/html') self.end_headers() self.flush_headers() # Content before .sleep() message = f' <!DOCTYPE html> \ <html lang="en"> \ <head> \ <meta charset="UTF-8"> \ <title></title> \ </head> \ <body> \ ' self.wfile.write(bytes(message, "utf8")) self.wfile.flush() beforeSleep = 'Before Sleep' self.wfile.write(bytes(beforeSleep, "utf8")) self.wfile.flush() lineBreak = '<br/>' self.wfile.write(bytes(lineBreak, "utf8")) self.wfile.flush() blankChar = "-" fillerString = ""; for x in range(260): fillerString = fillerString + blankChar self.wfile.write(bytes(fillerString, "utf8")) # Sleep for 3 seconds time.sleep(3) self.wfile.write(bytes(lineBreak, "utf8")) self.wfile.flush() # Content after .sleep() which should be rendered progressively afterSleep = "After Sleep" self.wfile.write(bytes(afterSleep, "utf8")) self.wfile.flush() with HTTPServer(('', 8000), handler) as server: server.serve_forever()```
0
0
842
Aug ’23
How to check origin URL when loading a web archive inside WKWebView
Introduction We load a saved web archive (NSData) into a WKWebView instance using following method: [self.webView loadData: archive MIMEType:@"application/x-webarchive" characterEncodingName:@"" baseURL:baseURL]; We also have some custom scripts injected safely into the web view using following snippet WKUserScript *userScript = [[WKUserScript alloc] initWithSource:<jsfilename> injectionTime:WKUserScriptInjectionTimeAtDocumentStart forMainFrameOnly:onMainFrame]; [webview.configuration.userContentController addUserScript:userScript]; Things work fine till here. Observation When I get the call from Javascript Layer to the native iOS Layer via: -[CustomWebViewController userContentController:didReceiveScriptMessage:] the value message.frameInfo.request.URL.absoluteString is "about:blank" Question Is there any way to get the original baseURL back here? Alternatives Considered: Store the baseUrl in an instance variable and use it here but since we are using this url to determine if the request is coming from valid domains, having a url from this method will be most credible. We are looking a way to piggyback this info (baseURL domain) to our web archive at the time of loading it in webView and extract that from the -[CustomWebViewController userContentController:didReceiveScriptMessage:] method Any help will be much appreciated.
0
0
948
Aug ’23
Notification requestPermission always returns denied
Hi, I am trying out push notification for IOS 16.4 beta Simulator using Xcode 14.3 beta (14E5197f). Inside my JS code I have the following: Notification.requestPermission((permission) => { console.log(permission); }).catch((error) => { deviceNotSupported(); }); } Unfortunately "permission" always returns "denied". Please kindly assist
10
1
9.2k
Aug ’23
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
2.2k
Jul ’23
WKWebView document.onvisibilitychange event not always being fired. Need to detect page changes reliability from WKUserScript
I need to prepare an object when the user navigates to a new page in WKWebView and refresh UI. I run a WKUserScript on behalf of the user to do this. I'm using the readystatechange event listener to detect initial page load. I'm also listening to the visibilitychange event to refresh UI if the DOM is already loaded on a "Go back" or "Go Forward" action. document.addEventListener('visibilitychange', () => { //do whatever if the DOM is already loaded and if we are visible. }); document.addEventListener('readystatechange', (event) => { //do whatever when page is loaded }); On certain websites however I noticed that neither of these events are being fired when I navigate -goForward: and -goBack: I'm not sure why. My WKUserScript is in WKContentWorld.defaultClientWorld so it shouldn't be interfering with the javascript of the page. Is there another JS event I'm missing? I could pick up the changed URL on the native code side but it would be nice to keep this all contained within the WKUserScript as this UI is for the "webview" and the native code shouldn't have to be bothered with having to patch in the additional glue. Is there another DOM event I need to listen to? I tried listening to window's pageshow but that didn't work. Also experimented a bit with the window's popstate event but no luck.
4
0
2k
Jul ’23
How can I prevent WKWebView initialization from hurting app startup time so much?
For many mid and large-size iOS apps, startup time is delayed by 100+ milliseconds due to 1 or more WKWebViews being created. This is usually due to 0-1 WKWebViews being created by first-party code and 1 or more different SDKs each creating their own WKWebView (IIRC for them to use a JS VM). Although SDK providers may not be willing (or able) to defer the creation of these WKWebViews past startup, I'm hopeful that there are still some ways to improve WKWebView creation time, and that I can share those ideas with them. Note that much of the time spent under the hood for WKWebView initialization seems to be on process pool creation and management. My ideas so far are: Defer WKWebView creation. This is an obvious one, but I generally want to look past it because SDKs are often unwilling to defer work like that and because it's going to cause frame drops whenever it does get loaded, even if not at startup. Use a shared WKProcessPool. Many companies wouldn't care all that much about sharing the same process space, so this would be a nice win Create the WKProcessPool or the WKWebViewConfiguration on a background thread (is this even safe to do?) Use some sort of lower-level API to run a JS VM, e.g. through WebKit2 directly, if such a public and stable API exists. Use JavaScriptCore. However, for reasons I can't recall, I believe this was a non-starter. It may have been JavaScriptCore's far slower performance, or the need to render actual web content. What are people's thoughts on these ideas? Does anyone have any other ideas?
0
0
869
Jul ’23
Webauthn with React in Safari
I am creating a react app and am making use of Webauthn to use TouchID or FaceID for user authentication. I have built my app so that when the button is clicked, navigator.credentials.create is the only call made. With attestation set to none, there are no issues however as soon as I set attestation to direct I get an alert saying 'The operation can't be completed' and 'NotAllowedError: This request has been cancelled by the user.' is logged to console. The issue only presents itself on Safari and iOS devices however works perfectly on other browsers like Chrome. Has anyone encountered a similar issue and possibly know how to resolve it? Thanks Shay
2
1
2.1k
Jun ’23
How add to clipboard image in browser on iPhone?
I'd like to add some image to clipboard from my web browser(Chrome, Safari) on iPhone. For example: I have canvas element with some picture. I get from the canvas element Blob type of data Create "ClipboardItem" with correct type and data Add to ClipboardItem to clipboard using write And on the MacBook, Windows laptops, Android devices, in chrome all correct work, but on iPhones nope (( Help me please, my code example here 👇🏻 canvasEl.toBlob((blob) => { if (!blob) return; navigator.clipboard.write([ new ClipboardItem({ "image/png": new Promise(async (resolve) => { resolve(new Blob([blob!], { type: "image/png" })); }), }), ]); });
0
0
1.1k
Jun ’23
event.preventDefault() call invalid autocorrect | Safari
Found a problem with Webkit. If in the safari browser, in the contenteditable field, using js, interrupt the keydown event and implement the same functionality programmatically, then the autoreplacement starts to produce incorrect results. As you can see in the image below, the content has been programmatically removed, but the autocorrect outputs incorrect options.
0
0
790
May ’23
CloudKit JS saveRecords with asset field for png from base64string
I want to save a CK record with a png-image as data into an asset field. The image is representated by a base64-string variable in the javascript. Have given up after one week searching for an answer.
Replies
2
Boosts
0
Views
854
Activity
Oct ’23
MediaRecorder onstop callback doesn't get called in iOS15
Hi, I'm using MediaRecorder for screen recording of canvas , along with audio. simplified code to implement screen recorder //intialise stream const canvas = document.querySelector('.main-canvas'); const stream = await navigator.mediaDevices.getUserMedia({ audio: true }); for (let track of canvas.captureStream().getTracks()) { stream.addTrack(track); } recorder = new MediaRecorder(stream); chunks = []; recorder.ondataavailable = ({ data }) => { if (data) chunks.push(data); }; recorder.start(); recorder.onstop = () => { const videoBlob = new Blob(chunks, { type: 'video/mp4' }); chunks = [] //stop mic access after use try{ for (let track of stream.getTracks()) { track?.stop(); } }catch(e){} return videoBlob; } so when i call recorder.stop() , the recorder.onstop method is not getting called sometimes randomly. And also in case when recorder.onstop is not called , recorder.ondataavailable is not called even a single time,So it returns empty Blob output. This only occurs in iOS 15 device's , it occurs randomly 40% of the times. Is there any workaround for this, or what is cause of this issue? Thanks in advance
Replies
6
Boosts
2
Views
3.2k
Activity
Oct ’23
Ios16.4 pwa push notifications without sound
In iOS16.4 the push notifications on progressive web apps are working but they didn’t have any sound while they appear. is this a bug or is there any way to enable the sound on push notifications on web apps ?
Replies
3
Boosts
0
Views
1.4k
Activity
Oct ’23
New jsError occurs in iOS17: Invalid character: '\0'
When use jsCore, The error reporting location is where JS communicates with Native, and the stack does not contain any valid information. Anyone konws what's the problem.....
Replies
2
Boosts
2
Views
2.2k
Activity
Oct ’23
Webview Application Crash WebProcessProxy & WebPageProxy
I randomly get this crash in my webview application when loading data. There is no pattern to it, it can happen in all areas where images are being loaded into vram. Here is the error: 2023-09-16 19:57:55.404378+0200 Bluelife[3284:194440] [Process x10d004350 - [PID=3445] WebProcessProxy: :didClose: (web process 0 crash) 2023-09-16 19:57:55.404500+0200 Bluelife3284:194440] [Process] 0x10d004350 - [PID=3445 WebProcessProxy::processDidTerminate0rFailedToLaunch: reason=Crash 2023-09-16 19:57:55.404579+0200 Bluelife[3284:194440] [ProcessSuspension] 0x10c01dfe - ProcessAssertion: Failed to acquire RBS Background assertion 'XPCConnectionTerminationWatchdog' for process because PID 0 is invalid 2023-09-16 19:57:55.410251+0200 Bluelife[3284:194440] [Process] 0x130856218 - [pageProxyID=14, webPageID=15, PID=3445] WebPageProxy: :processDidTerminate: (pid 3445), reason=Crash 2023-09-16 19:57:55.411392+0200 Bluelife[3284:211863] [ProcessSuspension] 0x10c01dfe - ProcessAssertion::acquireSync Failed to acquire RBS assertion 'XPCConnectionTerminationWatchdog' for process with PID=0, error: (null) 2023-09-16 19:57:55.424321+0200 Bluelife[3284:194440] [Loading] 0x130856218 - [pageProxID=14, webPageID=15, PID=3445] WebPageProxy::dispatchProcessDidTerminate: reason=Crash
Replies
1
Boosts
1
Views
1.7k
Activity
Sep ’23
iOS 17.0 Webkit 'display:flex' issue
When rendering 2 'div' components with 'display:flex' placed on top of each other, the preceding one sometimes comes up. The 'position:absolute' has been set and the second 'div' component is being generated after the first one. However, when inspecting the iOS webview in Safari, I enable-disable the 'display:flex' property, everything starts working again. This is possibly a bug in the layout engine. I tried the same process in iOS 16.4 and there are no issues at all.
Replies
3
Boosts
0
Views
2.7k
Activity
Sep ’23
WebKit mic permission
Hello. I'm trying to stop my webview from asking for mic permission every time it runs, as I already handle it out in the application. This is the code I use, but it doesn't seem to run the code for the permission at all (tried printing and debugging, and it doesn't go into it at all). I am using visionOs if that makes a difference. Are there any alternative solutions to this? import SwiftUI import WebKit import AVFAudio struct WebView: UIViewRepresentable { let urlString: String func makeUIView(context: Context) -> WKWebView { let webView = WKWebView() webView.navigationDelegate = context.coordinator if let url = URL(string: urlString) { let request = URLRequest(url: url) webView.load(request) } return webView } func updateUIView(_ uiView: WKWebView, context: Context) {} func makeCoordinator() -> Coordinator { Coordinator() } class Coordinator: NSObject, WKUIDelegate, WKNavigationDelegate { // Handle media capture permissions func webView(_ webView: WKWebView, decideMediaCapturePermissionsFor origin: WKSecurityOrigin, initiatedBy frame: WKFrameInfo, type: WKMediaCaptureType) async -> WKPermissionDecision { return .grant } // Handle URL authentication challenges func webView(_ webView: WKWebView, didReceive challenge: URLAuthenticationChallenge, completionHandler: @escaping (URLSession.AuthChallengeDisposition, URLCredential?) -> Void) { let username = "user" let password = "password" let credential = URLCredential(user: username, password: password, persistence: .forSession) completionHandler(.useCredential, credential) } } } struct AssistantView: View { @Environment(\.dismissWindow) private var dismissWindow var body: some View { WebView(urlString: "https://somelink.com/") .edgesIgnoringSafeArea(.all) .frame(width: 500, height: 800) } }
Replies
1
Boosts
0
Views
1.1k
Activity
Aug ’23
Safari / IOS WKWebView waiting for 250 bytes before rendering content. Delaying execution of external .js
We have observed that safari / IOS WKWebView waits for ~250 renderable bytes before it starts to render HTML as received in the browser. This is different from the behaviour in chrome / Firefox where they start to render the content as soon as the first byte is available. We wanted to know if there’s a way to stop this behaviour, to bring parity across the two browsers. Also is there any official doc / announcement establishing this limit of ~250 characters which we’ve found experimentally. Details of our experiment: We created a simple HTTP Server In python that: Emits a stream of (100) characters Sleeps for 3 seconds Emits some more characters You can find the experiment code towards the end of the post The ideal behaviour (which we observed in chrome) is that the content should be rendered progressively. Implying that the 100 characters before the .sleep() should be rendered immediately. This should be followed by a gap of 3 seconds, and then the rest of the characters are displayed. You can see this behaviour where I reload the page: https://drive.google.com/file/d/1JD_ZbghX3OOz_CpSR2iGn_Se7_2HDRTw/view?usp=sharing The text "Before Sleep" followed by a line of 100 dashes is the content before .sleep() which appears immediately. The text “After Sleep” apears after a time of 3 seconds which is the desired behaviour. In safari however, all of the content appears at once after 3 seconds, instead of being rendered progressively as seen here when I reload the page : https://drive.google.com/file/d/1RiD7eFuwGYL5lGIcU1CF2gcpoSysHJ9C/view?usp=sharing However if we increase the number of characters emitted before the .sleep() to ~250 (256 to be exact) safari behaves similar to chrome and the content appears progressively. You can see this here on page reload : https://drive.google.com/file/d/1JlHFbZPdFuIiaAlkgYCWo61amBIysKL1/view?usp=sharing We found this value of ~250 experimentally via hit and trial. Not only rendering, we also found this delaying the execution of external .js (that is present in a separate .js file embedded via tag). To prove this, I added a simple console.log(performance.now()) at the top of the .js file (outside of any function). In safari with artificially inserted ~260 extra bytes this log was printed at ~1 - 1.5 secs. However without the extra bytes this log came at ~3 - 4 seconds. This gap corresponds to the time taken to make rest of the page ready. Note that embedded .js present in the HTML was not affected by this. Wondering if other’s have faced the same problem and if there's an official doc stating this limit / any workarounds. Python HTTP Server code that we executed for our experiment from http.server import BaseHTTPRequestHandler, HTTPServer import time import sys class handler(BaseHTTPRequestHandler): def do_GET(self): self.send_response(200) self.send_header('Content-type','text/html') self.end_headers() self.flush_headers() # Content before .sleep() message = f' <!DOCTYPE html> \ <html lang="en"> \ <head> \ <meta charset="UTF-8"> \ <title></title> \ </head> \ <body> \ ' self.wfile.write(bytes(message, "utf8")) self.wfile.flush() beforeSleep = 'Before Sleep' self.wfile.write(bytes(beforeSleep, "utf8")) self.wfile.flush() lineBreak = '<br/>' self.wfile.write(bytes(lineBreak, "utf8")) self.wfile.flush() blankChar = "-" fillerString = ""; for x in range(260): fillerString = fillerString + blankChar self.wfile.write(bytes(fillerString, "utf8")) # Sleep for 3 seconds time.sleep(3) self.wfile.write(bytes(lineBreak, "utf8")) self.wfile.flush() # Content after .sleep() which should be rendered progressively afterSleep = "After Sleep" self.wfile.write(bytes(afterSleep, "utf8")) self.wfile.flush() with HTTPServer(('', 8000), handler) as server: server.serve_forever()```
Replies
0
Boosts
0
Views
842
Activity
Aug ’23
How to check origin URL when loading a web archive inside WKWebView
Introduction We load a saved web archive (NSData) into a WKWebView instance using following method: [self.webView loadData: archive MIMEType:@"application/x-webarchive" characterEncodingName:@"" baseURL:baseURL]; We also have some custom scripts injected safely into the web view using following snippet WKUserScript *userScript = [[WKUserScript alloc] initWithSource:<jsfilename> injectionTime:WKUserScriptInjectionTimeAtDocumentStart forMainFrameOnly:onMainFrame]; [webview.configuration.userContentController addUserScript:userScript]; Things work fine till here. Observation When I get the call from Javascript Layer to the native iOS Layer via: -[CustomWebViewController userContentController:didReceiveScriptMessage:] the value message.frameInfo.request.URL.absoluteString is "about:blank" Question Is there any way to get the original baseURL back here? Alternatives Considered: Store the baseUrl in an instance variable and use it here but since we are using this url to determine if the request is coming from valid domains, having a url from this method will be most credible. We are looking a way to piggyback this info (baseURL domain) to our web archive at the time of loading it in webView and extract that from the -[CustomWebViewController userContentController:didReceiveScriptMessage:] method Any help will be much appreciated.
Replies
0
Boosts
0
Views
948
Activity
Aug ’23
Notification requestPermission always returns denied
Hi, I am trying out push notification for IOS 16.4 beta Simulator using Xcode 14.3 beta (14E5197f). Inside my JS code I have the following: Notification.requestPermission((permission) => { console.log(permission); }).catch((error) => { deviceNotSupported(); }); } Unfortunately "permission" always returns "denied". Please kindly assist
Replies
10
Boosts
1
Views
9.2k
Activity
Aug ’23
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?
Replies
1
Boosts
0
Views
2.2k
Activity
Jul ’23
WKWebView document.onvisibilitychange event not always being fired. Need to detect page changes reliability from WKUserScript
I need to prepare an object when the user navigates to a new page in WKWebView and refresh UI. I run a WKUserScript on behalf of the user to do this. I'm using the readystatechange event listener to detect initial page load. I'm also listening to the visibilitychange event to refresh UI if the DOM is already loaded on a "Go back" or "Go Forward" action. document.addEventListener('visibilitychange', () => { //do whatever if the DOM is already loaded and if we are visible. }); document.addEventListener('readystatechange', (event) => { //do whatever when page is loaded }); On certain websites however I noticed that neither of these events are being fired when I navigate -goForward: and -goBack: I'm not sure why. My WKUserScript is in WKContentWorld.defaultClientWorld so it shouldn't be interfering with the javascript of the page. Is there another JS event I'm missing? I could pick up the changed URL on the native code side but it would be nice to keep this all contained within the WKUserScript as this UI is for the "webview" and the native code shouldn't have to be bothered with having to patch in the additional glue. Is there another DOM event I need to listen to? I tried listening to window's pageshow but that didn't work. Also experimented a bit with the window's popstate event but no luck.
Replies
4
Boosts
0
Views
2k
Activity
Jul ’23
How can I prevent WKWebView initialization from hurting app startup time so much?
For many mid and large-size iOS apps, startup time is delayed by 100+ milliseconds due to 1 or more WKWebViews being created. This is usually due to 0-1 WKWebViews being created by first-party code and 1 or more different SDKs each creating their own WKWebView (IIRC for them to use a JS VM). Although SDK providers may not be willing (or able) to defer the creation of these WKWebViews past startup, I'm hopeful that there are still some ways to improve WKWebView creation time, and that I can share those ideas with them. Note that much of the time spent under the hood for WKWebView initialization seems to be on process pool creation and management. My ideas so far are: Defer WKWebView creation. This is an obvious one, but I generally want to look past it because SDKs are often unwilling to defer work like that and because it's going to cause frame drops whenever it does get loaded, even if not at startup. Use a shared WKProcessPool. Many companies wouldn't care all that much about sharing the same process space, so this would be a nice win Create the WKProcessPool or the WKWebViewConfiguration on a background thread (is this even safe to do?) Use some sort of lower-level API to run a JS VM, e.g. through WebKit2 directly, if such a public and stable API exists. Use JavaScriptCore. However, for reasons I can't recall, I believe this was a non-starter. It may have been JavaScriptCore's far slower performance, or the need to render actual web content. What are people's thoughts on these ideas? Does anyone have any other ideas?
Replies
0
Boosts
0
Views
869
Activity
Jul ’23
How to know what's blocked by WKContentRuleList
As we know, we can use WKContentRuleList to block url requests/cookies or perform other actions in WKWebView. Is there any way that we can know what has been blocked by the WKWebView based on that WKContentRuleList?
Replies
2
Boosts
0
Views
1.8k
Activity
Jul ’23
Is there a way to block <script> elements with WKContentRuleList?
Is there a way to block certain embedded inline javascript elements using WKContentRuleList? For example <script> evilJavascriptHere </script> The documentation states that you can specify a url-filter but what about inline scripts?
Replies
0
Boosts
0
Views
702
Activity
Jun ’23
onPointer Events Not working on the ios Safari
onPointer Events not working on safari browser in IOS, when i hold on an element in ios it showing a context menu, but not getting the events.
Replies
0
Boosts
0
Views
807
Activity
Jun ’23
Webauthn with React in Safari
I am creating a react app and am making use of Webauthn to use TouchID or FaceID for user authentication. I have built my app so that when the button is clicked, navigator.credentials.create is the only call made. With attestation set to none, there are no issues however as soon as I set attestation to direct I get an alert saying 'The operation can't be completed' and 'NotAllowedError: This request has been cancelled by the user.' is logged to console. The issue only presents itself on Safari and iOS devices however works perfectly on other browsers like Chrome. Has anyone encountered a similar issue and possibly know how to resolve it? Thanks Shay
Replies
2
Boosts
1
Views
2.1k
Activity
Jun ’23
How add to clipboard image in browser on iPhone?
I'd like to add some image to clipboard from my web browser(Chrome, Safari) on iPhone. For example: I have canvas element with some picture. I get from the canvas element Blob type of data Create "ClipboardItem" with correct type and data Add to ClipboardItem to clipboard using write And on the MacBook, Windows laptops, Android devices, in chrome all correct work, but on iPhones nope (( Help me please, my code example here 👇🏻 canvasEl.toBlob((blob) => { if (!blob) return; navigator.clipboard.write([ new ClipboardItem({ "image/png": new Promise(async (resolve) => { resolve(new Blob([blob!], { type: "image/png" })); }), }), ]); });
Replies
0
Boosts
0
Views
1.1k
Activity
Jun ’23
event.preventDefault() call invalid autocorrect | Safari
Found a problem with Webkit. If in the safari browser, in the contenteditable field, using js, interrupt the keydown event and implement the same functionality programmatically, then the autoreplacement starts to produce incorrect results. As you can see in the image below, the content has been programmatically removed, but the autocorrect outputs incorrect options.
Replies
0
Boosts
0
Views
790
Activity
May ’23
Composition selection bug in contenteditable | Webkit
[IOS 16.4.1] I recently noticed that if there is a contenteditable field on the page in the browser and it is cleared during the touchstart event, then such a selection remains. I did not find any solution to this problem on the Internet. How can I fix this problem?
Replies
0
Boosts
0
Views
749
Activity
May ’23