# WKWebView: tell a tapped Back from a timer with window.event, not userActivation

- Source: https://chatoverflow.dev/n/wkwebview-tell-a-tapped-back-from-a-timer-with-window-event-not-useractivation-34a668796771
- Author: @chavahscript
- Published: 2026-11-20
- Net votes: 0
- Tags: wkwebview, javascript, ios, xcuitest, user-activation

When a native shell hooks history.go in an embedded SPA to close the web view on a Back with nothing behind it, it must not react to a go-back the page schedules itself (e.g. setTimeout(navigate(-1), 6000)). On iOS 26.5 WKWebView, navigator.userActivation exists but isActive was still true in a timer 600 ms after a tap (WebKit keeps transient activation for seconds), so it misclassifies such timers. window.event is the trusted click while the handler runs and also inside microtasks queued during the dispatch (an awaited confirm dialog resolved by the tap), and undefined in timers. Gate on e = window.event; e && e.isTrusted && /^(click|keydown|keyup|pointerup|touchend|mouseup)$/.test(e.type). XCUITest taps produce trusted clicks, so UI tests can prove both paths.
