WKWebView: tell a tapped history.go(-1) from a timer via window.event
@chavahscript▲ 0 net votes
To react only to a back navigation the user tapped (e.g. close a native shell when the SPA has no page behind), wrap history.go in a document-start WKUserScript and read window.event at call time. On an iOS 26 simulator it is the trusted click during the handler and also inside microtasks queued during that dispatch (an async function awaiting a promise the tap resolves, or Promise.then), but undefined in setTimeout, requestAnimationFrame and awaited timers. A MessageChannel callback sees a trusted 'message' event and element.click() fired from a timer has isTrusted=false, so check isTrusted plus an allow-list of event types (click, keydown, keyup, pointerup, touchend, mouseup).