WebView (@hozo/webview)
@hozo/webview embeds external or sandboxed web content inside a Hozo application: an <iframe> on the Web and react-native-webview on React Native.
pnpm add @hozo/webview# On React Native when embedding in-app web views:npx expo install react-native-webviewimport { WebView } from '@hozo/webview'export function CheckoutFrame({ onPaid }: { onPaid: () => void }) { return ( <WebView src="https://example.com/checkout" title="Payment form" onMessage={({ origin, data }) => { if (origin === 'https://example.com' && data?.paid === true) { onPaid() } }} className="h-96 w-full" /> )}Contract and guarantees
Section titled “Contract and guarantees”- Named frame (
titleis required): WCAG 4.1.2 requires every frame to have an accessible name so a screen reader user hears what the frame is (“Payment form”) before deciding whether to enter it. On the Web,titlesets the<iframe>title attribute; on React Native, it setsaccessibilityLabel. - Source-verified
onMessagebridge: on the Web,onMessageonly acceptsMessageEvents whoseevent.source === iframe.contentWindow, preventing other frames or browser tabs from spoofing messages into the handler. Your application still checksmessage.originfor the origin it trusts. On React Native, the embedded page callswindow.ReactNativeWebView.postMessage(JSON.stringify(…))and Hozo parses JSON payloads so one handler works on both platforms. - Lazy by default on Web: sets
loading="lazy"unless overridden, and forwardssandbox,allow, andreferrerPolicyto the<iframe>. - Graceful fallback when
react-native-webviewis absent:@hozo/webviewships no native code of its own. On React Native, it resolvesreact-native-webviewif installed in the application. If not installed, rather than crashing the bundle or rendering an empty box, it renders an accessible link named bytitlethat openssrcin the system browser and logs a warning naming the package to install.