Skip to content

feat(webview): add pinch zoom and explicit loads - #233

Merged
houko merged 6 commits into
mainfrom
fix/webview-controls
Nov 16, 2026
Merged

houko merged 6 commits into
mainfrom
fix/webview-controls

Conversation

@houko

@houko houko commented Nov 15, 2026 •

Copy link
Copy Markdown
Collaborator

What changed

Fixes #202.

  • WebView.PinchZoom, off by default, lets a pinch magnify the page: macOS sets WKWebView.allowsMagnification; Windows sets WebView2's IsPinchZoomEnabled (touch screens) and IsZoomControlEnabled, because a precision touchpad's pinch reaches the window as Ctrl+wheel, which also turns off Ctrl+wheel and Ctrl+/- zoom unless PinchZoom is on (WebView2 zoomed on these by default before); Android turns on WebSettings' built-in zoom with its buttons hidden. iOS follows the page's viewport. WebKitGTK and the browser have no switch for this and keep their own handling.
  • Ref.Load(WebSource) loads a source the way a new Source would, even when it equals the current one. It goes through the same Access check: a refused source reaches OnError and sends nothing. It uses the view's Headers. It navigates the view the way a link does and leaves the configured source alone, so the next change of Source/SourceFunc loads again, even to the value Load loaded, and messages still come from the source's origin by default. Every backend routes driver.WebLoad (Apple, Windows, Linux, Android, web).
  • WebError carries the platform's Domain and Code (driver.WebFailure in Event.Data): NSError on Apple, the GError domain name on Linux, COREWEBVIEW2_WEB_ERROR_STATUS (or HRESULT for a refused navigate call) on Windows. Both are empty for access refusals and on Android (roadmap row added).
  • Loads cut short no longer reach OnError: stopped, replaced by a new source, Ref.Load, a reload or history step, replaced by the page navigating elsewhere, or turned into a download. Apple drops NSURLErrorCancelled (-999) and WebKitErrorFrameLoadInterruptedByPolicyChange (102). WebView2 ends all of these as CONNECTION_ABORTED, so Windows tracks NavigationId: it drops the failure of a navigation that is not the last one started or that the app stopped or replaced, and because WebView2 raises the failure before the next NavigationStarting or DownloadStarting, a CONNECTION_ABORTED of the last navigation waits 500 ms and is dropped if either arrives. Windows now reports the URL that failed instead of the page still shown.
  • The gallery's site browser gets a Home button that calls Ref.Load on the docs page it starts at. nsgotest records web command data and exports WebLoad and WebSource.

Verification

  • go build ./.... Vets: windows amd64/386/arm64, linux, android/arm64, js/wasm. go tool nsgo check -target all passed on macOS (Studio).
  • go tool nsgo test ./core (549 passed), ./internal/platform/android (incl. new TestWebCommandsMatchJava), ./internal/platform/apple (54 passed), ./nsgotest, -run TestMedia ./examples/gallery (Home sends WebLoad with the docs URL), -run 'Layer|Skills|Doc' ..
  • Probe app on macOS 27, Windows 11 and Ubuntu 24.04 (WebKitGTK 6) checked the following. Ref.Load of the current source reloads it. A SourceFunc change to the value Load loaded reloads it. An unreachable host reports NSURLErrorDomain/-1003 on macOS, g-resolver-error-quark/0 on Linux and COREWEBVIEW2_WEB_ERROR_STATUS/0 on Windows. StopLoading during a load reports nothing on all three.
  • Windows 11 probe (local HTTP server, scripted): no OnError for Ref.Load or a SourceFunc change while a slow page loads, StopLoading, a link OnDownload saves, Ref.Load of a download URL, or a page that navigates elsewhere while its own navigation loads; an unreachable host still reports its error. The raw event log confirmed WebView2 raises the aborted NavigationCompleted before the replacing NavigationStarting and before DownloadStarting.
  • Windows: Ctrl+wheel over the page left devicePixelRatio at 1 with PinchZoom off and raised it to 1.5 with it on.
  • Android (API 35 emulator): Ref.Load loads a new page and then the same page again.
  • Not device-checked: a real trackpad pinch on macOS (it cannot be synthesized), a touch pinch on Android and Windows, and anything on iOS (the iPhone is unavailable). The iOS change only drops cancellation errors in the shared Apple code, which was checked on macOS.

@github-actions github-actions Bot added size/M enhancement New feature or request documentation Improvements or additions to documentation macOS iOS Windows Linux Web Android core conflict Conflicts with the base branch; resolve it first labels Nov 15, 2026
@houko
houko force-pushed the fix/webview-controls branch from 4bcb9bc to 324544d Compare November 16, 2026 08:35
@github-actions github-actions Bot added conflict Conflicts with the base branch; resolve it first and removed conflict Conflicts with the base branch; resolve it first labels Nov 16, 2026
@houko
houko force-pushed the fix/webview-controls branch from 324544d to ba4d502 Compare November 16, 2026 09:15
@github-actions github-actions Bot added conflict Conflicts with the base branch; resolve it first and removed conflict Conflicts with the base branch; resolve it first labels Nov 16, 2026
…hZoom on Android and Windows touchpads

Android numbered WebLoad 7, WebSendInput's number, while Go writes it as 8 with three strings, so a load desynchronized the batch stream; Protocol.java now matches the driver, which a test holds it to.

Backends no longer overwrite their config's Source with the loaded one: a later change of another setting reloaded the configured source on Apple, Linux and Windows. Each loads Ref.Load's source with the load the source uses, keeping the configured one, so the next source, script or header change loads it again and messages keep coming by default from its origin. The web keeps the page shown when only frame settings change.

A Load Access refuses now reports OnError and sends nothing, where it sent an empty source that showed about:blank on Windows and a blank frame on the web.

PinchZoom turns on Android's built-in zoom with its buttons hidden, and on Windows also sets IsZoomControlEnabled, as a precision touchpad's pinch reaches the window as Ctrl with the wheel. The gallery's Home loads the docs page the browser starts at rather than go.dev, and nsgotest exports WebLoad.
…iled

WebView2 ends a navigation StopLoading cuts short with CONNECTION_ABORTED, which reached OnError, and reported every failure at the page still shown, which for a load that never committed is the one before it. The view now drops the failure of a navigation it stopped and reports the URL NavigationStarting gave. Checked on Windows 11: a stopped load reports nothing and an unreachable host reports its own URL.
…o a download

WebView2 ends a navigation as CONNECTION_ABORTED when StopLoading stops it, when a new source, Ref.Load, Reload or a history step replaces it, when the page navigates elsewhere, and when its response becomes a download. Only the StopLoading case was dropped, so typing an address while a page loaded, or clicking a link OnDownload saves, reached OnError.

The backend now tracks NavigationId: a failure of a navigation that is not the last one started, or that the app cut short, is dropped. WebView2 raises the failure before the next NavigationStarting or DownloadStarting, so a CONNECTION_ABORTED of the last navigation waits half a second and is dropped if either arrives.
… cancellations

0.1.0 has shipped, so the change gets its Unreleased entries, including the Windows Ctrl+wheel zoom that now follows PinchZoom.
@houko
houko force-pushed the fix/webview-controls branch from ba4d502 to 1134c74 Compare November 16, 2026 09:30
@houko

houko commented Nov 16, 2026

Copy link
Copy Markdown
Collaborator Author

Reviewed.

Read the full diff against main and #202's Acceptance. Ref.Load goes through the same Access check as Source (a refused source reaches OnError and sends nothing), every backend routes driver.WebLoad and keeps its configured source, Android's WEB_LOAD (8) matches the driver and its Java reads the three strings Go writes, Apple drops NSURLErrorCancelled and WebKit 102, and Windows tracks NavigationId with the cut marker and the 500 ms hold for CONNECTION_ABORTED. No unrelated changes or attribution; no hard-wrapped comments in the PR's own code.

Rebased onto v0.1.0 (main 7c8423a). The only conflicts were classes.dex and classes.jar, rebuilt with build.sh at both commits that change Java; a rebuild at the head reproduces them byte for byte. Since 0.1.0 has shipped, I added the PR's two Unreleased entries to CHANGELOG.md in a separate commit, including the Windows Ctrl+wheel zoom default that now follows PinchZoom.

Builds and tests:

  • Ubuntu host: go build ./..., windows/amd64 go build ./..., vets for windows amd64/386/arm64, linux, android/arm64 and js/wasm, and a Windows build of the gallery all passed. go tool nsgo test: core 553 passed, nsgotest 43, internal/driver 119, internal/platform/android 10 (2 skipped), tsx 147, gallery TestMedia, and -run 'Layer|Skills|Doc' . 29.
  • macOS host: darwin vets (apple, macos), ios vets (ios, apple), internal/platform/apple 54 passed (TestAppleWebCancellation included), go tool nsgo check -target all passed.

Device checks, using a probe app with a local HTTP server that ran a scripted sequence and logged OnLoadStart, OnLoad, OnError and OnDownload:

  • Windows 11 (WebView2): no OnError for Ref.Load or a SourceFunc change while a slow page loaded, StopLoading, Ref.Load of an attachment, a link the page clicked that OnDownload saved, a page that navigated to a slow page and then elsewhere 0.5 s later, GoBack during a slow load, or Reload during a slow load. Downloads started and finished. Ref.Load of the current source loaded it again (load start and load). An unreachable host reported COREWEBVIEW2_WEB_ERROR_STATUS/0 at its own URL. A server that closes the connection reported status 8 at once and, on WebView2's retry, status 9 after the hold, so a CONNECTION_ABORTED nothing explains still reaches OnError.
  • macOS 27 (WKWebView): the same sequence gave no OnError for any cut-short load, NSURLErrorDomain/-1003 for the unreachable host and NSURLErrorDomain/-1005 for the closed connection; Ref.Load of the current source reloaded it.

Not checked here: Linux and Android devices (WebKitGTK already dropped its cancellation errors; Android's protocol is covered by TestWebCommandsMatchJava), real pinch gestures, and iOS, whose only change is the shared Apple cancellation filter checked on macOS.

@houko
houko marked this pull request as ready for review November 16, 2026 09:31
@github-actions github-actions Bot removed the conflict Conflicts with the base branch; resolve it first label Nov 16, 2026
@houko
houko merged commit cb2b514 into main Nov 16, 2026
7 checks passed
@houko
houko deleted the fix/webview-controls branch November 16, 2026 09:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Android core documentation Improvements or additions to documentation enhancement New feature or request iOS Linux macOS size/M Web Windows

Projects

None yet

Development

Successfully merging this pull request may close these issues.

WebView: no pinch-to-zoom on macOS, no Ref command to load a URL, and Apple reports cancelled loads as errors (WebError has no code)

1 participant