The new WKJSScriptingBuffer API allows Swift to define data buffers and make them available to JS code running in a WKWebView.
Is there any API for passing an ArrayBuffer of data from a WKWebView to Swift code? Currently the usual workaround is to convert the buffer to a base64 string, but that is slow and can lead to exhausting memory depending on the size of the buffer.
On the web, window.postMessage() has an argument that allows transferring ownership of ArrayBuffers to the receiver, but the webkit.messageHandlers.<name>.postMessage() API doesn't seem to support that.
Is there any API for passing an ArrayBuffer of data from a WKWebView to Swift code?
Not at this time.
On the web, window.postMessage() has an argument that allows transferring ownership of ArrayBuffers to the receiver, but the webkit.messageHandlers.<name>.postMessage() API doesn't seem to support that.
Shared array buffers on the web have very specific semantics built up around them with regards to transferability and serializability.
Unfortunately there's no obvious analog to that mechanism while bridging to native.
In each SDK release we tend to improve the JavaScript -> native scripting bridge, and it's likely that our work is not done here.