WebKit JS

RSS for tag

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

WebKit JS Documentation

Posts under WebKit JS tag

49 Posts
Sort by:
Post not yet marked as solved
4 Replies
2.1k Views
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
Posted
by
Post not yet marked as solved
2 Replies
1.4k Views
Hello I have a webrtc-based web app that is loaded inside a WKWebView. The web app gets loaded just fine in our iOS App running WKWebView on an iPad with iOS 15.1. We are using the exact same app, built for Mac Catalyst. However, on the Mac version, the web app gets loaded but the RTCPeerConnection object is undefined.. Meaning that our web app assumes that WebRTC is not available in that browser. Isn't the native app supposed to work the exact same on iOS and MacOS? Is the Mac version of WKWebView more limited than its iOS counterpart ? Is there any resource that states exactly what is supported in WKWebview in each platform? Thanks
Posted
by
Post not yet marked as solved
1 Replies
1.6k Views
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
Posted
by
Post not yet marked as solved
9 Replies
5.4k Views
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
Posted
by
Post not yet marked as solved
1 Replies
1.1k Views
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?
Posted
by
Post not yet marked as solved
0 Replies
512 Views
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.
Posted
by
Post not yet marked as solved
0 Replies
787 Views
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" })); }), }), ]); });
Posted
by
Post not yet marked as solved
0 Replies
476 Views
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?
Posted
by
Post not yet marked as solved
4 Replies
941 Views
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.
Post not yet marked as solved
0 Replies
474 Views
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.
Posted
by
Post not yet marked as solved
1 Replies
541 Views
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) } }
Posted
by
Post not yet marked as solved
0 Replies
481 Views
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()```
Posted
by
Post not yet marked as solved
3 Replies
868 Views
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.
Posted
by
Post not yet marked as solved
1 Replies
796 Views
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
Posted
by
Post not yet marked as solved
10 Replies
2.9k Views
Hi guys, I'm a XR Developer, lately making a lot of web ar apps, I'm having an issue with iOS 17 at least on my iphone 14 Pro where the sound comes out of the call speaker, resulting very very low volume, sometimes I'm not sure how if I lock the phone and move it when I unlock it and go back to the webapp the sound it normal, loud and coming out of the media speakers. How I used to do this is my "start button" I unmute a play and pause it, and with this I used to be able to play later sounds of videos on the browser. Did something change with the last iOS 17 update? Is there a workaround for this? In the end what I want is be able to play sounds and videos on the web browser... This is a tag of a project that was working fine before the 17 update: And this is what I do on the start button: video.muted = false; video.play(); video.pause(); Help would be appreciated since I'm in the middle of deployment, thanks in advance
Posted
by