Skip to content

fix(ios): return from safari webview goto once the new page has replaced the old one - #519

Merged
gmegidish merged 1 commit into
mainfrom
fix/webview-wait-after-goto
Oct 17, 2026
Merged

gmegidish merged 1 commit into
mainfrom
fix/webview-wait-after-goto

Conversation

@mobile-kevin

Copy link
Copy Markdown
Collaborator

Bug

webview goto on a Safari tab returned as soon as the navigation was requested. A webview wait issued right after it polled document.readyState on the page being left, found it complete, and returned in ~100ms. webview url then still showed the old page.

Re-verified on current main (9243a76), iPhone 17 Pro simulator, Safari, against a local page that answers after 3s:

goto 117ms  ok
wait 102ms  ok
url  -> http://localhost:18093/slow?name=base        (previous page)

Reproduced 3 out of 3 times.

Android Chrome (CDP) is not affected. Page.navigate only answers once the new document has committed. On a Pixel 5 with https://httpbin.org/delay/3, goto took 3.7–4.3s, wait ~0.5s, and url was the new page every time (3 runs). That code is unchanged.

Root cause

WebKit's inspector protocol has no navigate command, so safariWebViews.WebViewGoto evaluates window.location.href = url in the page and returns. Nothing tied the later wait to that navigation. wait checks "the current document is loaded", and until the new document commits, the current document is still the old one.

Fix

goto now returns only once the new page has replaced the old one, so whatever runs after it (wait, url, eval, ...) sees the new document:

  • In the same evaluation that starts the navigation, the page is marked with a random id (window.__mobilecliGoto). The mark lives only on that document.
  • goto then polls the tab until a document without that mark answers, meaning the navigation has committed. The id is new for every goto, so a reload of the same URL is also detected.
  • A fragment jump (same document, URL changes at once) and a javascript: URL never replace the page, so the script removes the mark right away and goto returns immediately.
  • The polling loop that wait already had is extracted into waitUntil and shared. It has the same per-poll liveness timeout, ends early only for an unknown tab, and its timeout errors are unchanged for wait.
  • If the page is never replaced within 30s, goto fails with navigation to <url> did not replace the page within 30s. Example: an unreachable host, where Safari keeps the old document. Before, this case returned ok and the following wait succeeded against the old page.

Verification

Live on the iPhone 17 Pro simulator (Safari), isolated daemon:

case goto wait url after
page answering after 3s (×3) ~3.2s ~100ms new page ✅
same URL again (reload) 1.7s for a 1.5s page 80ms ✅
cross-site (localhost → 127.0.0.1, process swap) 1.7s 95ms ✅
page that commits fast, finishes loading after 4s 330ms 3.8s ✅ (wait still waits for load)
fragment jump (#a, #top) ~150ms ~90ms ✅
204 No Content 0.5s 90ms ok
javascript:void(0) 105ms – ok
unreachable host error after 30s – old page (was a silent "ok")
  • Unit tests with the fake web inspector: goto polls until the page is replaced, the poll looks for the absence of the mark it left, each goto uses a new mark, goto fails at its timeout when the page is never replaced, and the navigation itself is still never awaited.
  • go test ./... passes. make lint adds no new findings (38, all pre-existing).
  • The existing e2e group webview on safari passes (9/9). I tried an e2e test for "url is new right after goto", but the sample page commits faster than the CLI round-trip, so it passes on main too. I left it out rather than add a test that doesn't discriminate.

Not changed

The embedded-webview agents (Android loadUrl, iOS agents) also return from goto before the new page commits. They are prebuilt agents, and this issue covers the Chrome/Safari tab paths reworked in #488/#489/#490.

Fixes MOB-93

@coderabbitai

coderabbitai Bot commented Oct 14, 2026

Copy link
Copy Markdown

Warning

Review limit reached

  • Run on-demand review

This review includes 2 billable files and costs up to $0.50.

Or wait 49 minutes for your next included review.

Check out review usage here.

View limit details

Limit details: You’ve used all 2 included reviews currently available.

Learn how review limits work.

Review configuration:

⚙️ Run configuration
  • Configuration used: Repository: mobile-next/mobilecli/.coderabbit.yaml
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 38a8cac9-74c5-432d-b6f7-5f9e2ec318a6
📥 Commits

Reviewing files that changed from the base of the PR and between 9243a76 and 4f7e2f7.

📒 Files selected for processing: 2
  • devices/ios_webinspector.go
  • devices/ios_webinspector_test.go

Comment @coderabbitai help to get the list of available commands.

@gmegidish
gmegidish merged commit ead9572 into main Oct 17, 2026
36 of 39 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants