On macOS 10 however, the process is a little more involved. A method will be appended to window
that allows the response to be delivered there instead. It's not exactly this, but you can visualize the flow
as being something along the lines of:
// add the window method window["_0123456"] = (response) => { // decrypt `response` and deliver the result to the caller here // then remove the temporary method deletewindow['_0123456'] };
// later in swift, the following JavaScript snippet will be executed (() => { window['_0123456']({ ciphertext: [12, 13, 4], tag: [3, 5, 67, 56] }) })()
Example
On macOS 11+, this will just call through to
window.webkit.messageHandlers.x.postMessage
Eg: for a
foo
message defined in Swift that accepted the payload{"bar": "baz"}
, the following would occur:Example
On macOS 10 however, the process is a little more involved. A method will be appended to
window
that allows the response to be delivered there instead. It's not exactly this, but you can visualize the flow as being something along the lines of: