Skip to content

Conversation

@dcalhoun
Copy link
Member

@dcalhoun dcalhoun commented Jan 30, 2026

What?

Updates the iOS WebView navigation policy to correctly open external URLs in the system browser while allowing embedded content (videos, iframes) to load within the editor.

Why?

Fixes CMM-1172.

The WPCOM upsell button uses window.top.location.href = url (JavaScript navigation), which bypassed the original .linkActivated-only check. This caused the editor WebView to navigate to WordPress.com checkout pages instead of opening them in Safari.

How?

Introduces EditorNavigationPolicy to evaluate navigation requests based on:

Navigation Type Target Frame Result
Any Allowed scheme (file://, gbk-cache-https://, gbk-media-file://) ✅ Allow
Any Dev server host ✅ Allow
Any Subframe (iframe) ✅ Allow
.linkActivated Main frame ❌ Open in Safari
.other Main frame ❌ Open in Safari
.reload, .backForward, .formSubmitted Main frame ✅ Allow

This ensures:

  • Video embeds and iframes load correctly (subframe navigation allowed)
  • User link clicks open in Safari
  • JavaScript-initiated navigation (upsells) opens in Safari
  • Editor resources and dev server work normally

Testing Instructions

Upsell Navigation (the bug fix)

Important

Requires testing with the WordPress app.

  1. Open a WPCOM Simple site with a Free plan
  2. Insert a Video block
  3. Tap the "Upgrade" button
  4. Expected: Safari opens with the checkout page (not rendered inside the editor)

Video Playback (regression test)

  1. Insert a Video block and attach media with a site that allows video uploads.
  2. Tap the play button on the video.
  3. Expected: Video plays inline in the editor

Link Clicks

  1. Create a paragraph with a hyperlink to an external URL
  2. Edit the link to view the link preview popover
  3. Tap the link URL in the popover
  4. Expected: Safari opens the URL

Accessibility Testing Instructions

No UI changes - navigation behavior only.

Mitigate URLs to content outside of the GutenbergKit editor opening in
the WebView. Opening these URLs in the WebView creates an odd
experience, where you browse the at-large web inside the mobile app's
editor. Instead, these URLs should open in the OS browser.
Update EditorNavigationPolicy to evaluate the full WKNavigationAction
instead of just the URL. This allows video embeds and iframes to load
while still blocking upsell navigation that uses window.top.location.

Changes:
- Allow subframe navigation (targetFrame.isMainFrame == false)
- Block .linkActivated navigation to external URLs
- Block .other navigation to main frame external URLs
- Allow other navigation types (reload, back/forward)

This fixes video playback regression introduced in c3bb966.
Extract navigation decision logic into a testable method that accepts
primitive parameters (URL, navigationType, isMainFrame) instead of
WKNavigationAction. This enables unit testing without mocking WebKit.

New tests cover:
- Allowed schemes (file://, gbk-cache-https://, gbk-media-file://)
- Subframe navigation for video/embed support (YouTube, Vimeo, Twitter)
- Link click blocking for external URLs
- JavaScript main frame navigation blocking (upsell buttons)
- Other navigation types (reload, back/forward, form submission)
- Edge cases (nil URL, nil isMainFrame)
- Dev server URL handling
@dcalhoun dcalhoun added the [Type] Bug An existing feature does not function as intended label Jan 30, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

[Type] Bug An existing feature does not function as intended

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants