Skip to content

How it works

What runs where, and the terms the rest of the docs use: the core, frames, origins, rules and the bridge.

The app sends rules and settings to the native WebView core and gets state and events back; the core answers the page's navigations; the bridge links the app and allowed origins

The parts

Part What it is What it does
The page Your site, in the platform's WebView: WKWebView on iOS, Android System WebView on Android Runs in the WebView's own process, the renderer, apart from the app
The core This package's Swift and Kotlin around that WebView Decides navigations, keeps the navigation state, answers the page's requests, carries the bridge
Your app's JS The <WebView> props, its ref and your callbacks Hands the core its rules and settings, and hears what happened
A native hook Your own Swift or Kotlin, optional Gets the native WebView itself (native hooks); its JS side goes in the extensions prop, as the extensions package's hooks do

The core decides natively, from what the props gave it, so a busy JS thread doesn't hold the page up. JS is asked only where a prop says so: an ask rule (onNavigationRequest), an external navigation when you pass onOpenExternal, and the page's requests for files and permissions (page requests).

The bridge carries calls between your app's JS and the page's: the page has window.nativeBridge, and the app has the object createBridge makes, passed as the bridge prop.

Frames and origins

The main frame is the page's top-level document, the one whose URL the navigation state shows. Every <iframe> in it is a frame of its own.

An origin is a scheme, host and port, as the page's location.origin writes it: https://example.com. A page from an html source without baseUrl, a data: URL or a sandboxed iframe has an opaque origin, which only '*' matches.

The core gives the main frame more than it gives iframes, and trusts only the origins you name:

Feature Main frame Iframes
Navigation state Its url is this frame's Never change its url
Navigation rules Decided Decided on iOS; on Android only for non-http(s) URLs
The bridge On the bridge's allowedOrigins Never
Injected scripts On the script's origins Only with allFrames, each frame matched by its own origin
evaluate Runs here Never
Camera and microphone Asks your onPermissionRequest Denied without asking, except on Android one on the main frame's origin

How a navigation is decided

  1. These load in place without the rules: the source load, load(url), reloads, back and forward, form POSTs, and about:, data: and javascript: URLs unless they open a new window. A redirect of the source load or a load goes to the rules; navigationRules lists each case per platform.
  2. Any other navigation goes down navigationRules, and the first rule that matches decides: allow, block, external or ask.
  3. A navigation no rule matches is blocked.

Without the prop, the rules are defaultNavigationRules. onNavigation reports every decision with the index of the rule that made it.

Which props recreate the WebView

Only two props recreate the native WebView when they change, which reloads the page: bridge, compared by identity (keep it stable), and ios.configuration, compared by value. Everything else, callbacks included, can be written inline.