Search by

pushinbr / pam-native-webview

DavidWilliamBalbino

Optional hardened native WebView for PAM Native.

Package info

github.com/push-in/pam-native-webview

Language:Kotlin

Type:pam-native-plugin

pkg:composer/pushinbr/pam-native-webview

Statistics

Installs: 251

Dependents: 0

Suggesters: 1

Stars: 0

Open Issues: 0

v0.2.0 2026-11-19 00:22 UTC

This package is auto-updated.

Last update: 2026-11-19 00:22:12 UTC


README

pam-native-webview: Optional hardened native WebView for PAM Native, with host allowlists and page messages.

Optional hardened native WebView for PAM Native.
Extracted from the PAM Native 1.46 core: WKWebView on iOS and Android WebView behind one PHP element, with host allowlists, injected scripts and page-to-PHP messages.

Packagist Latest release PHP 8.5 License

Install · Quick example · Platforms · API · Docs · Issues

Install

Inside a PAM Native project (PAM Native 1.46 or later):

pam composer require pushinbr/pam-native-webview
pam doctor --fix

pam composer runs Composer on PAM's verified PHP runtime. Rebuild the native host after adding the package.

New to PAM? Create a project with pam init my-app --template native (see the PAM Native overview).

Quick example

use Pam\Native\WebView\WebView;
use Pam\Native\WebView\WebViewErrorCode;

$view = WebView::make('https://example.com/app')
    ->allowedHosts(['example.com', 'cdn.example.com'])
    ->onMessage(function (string $message, string $url): void {
        // Posted by the page with window.PamNative.postMessage(text).
        // Check $url before trusting the message.
    })
    ->onError(function (string $message, WebViewErrorCode $code): void {
        // ProcessGone: remount the view (new key) or show a failure.
    });

WebView::make() accepts an https, http or file URL or an inline HTML string (up to 1 MiB). JavaScript, DOM storage and inline media are on by default; turn them off with javaScriptEnabled(false), domStorageEnabled(false) and allowsInlineMedia(false). Pages written for react-native-webview can keep calling window.ReactNativeWebView.postMessage(text). The host answers a page by changing injectedJavaScript(): a page that already loaded runs each new script once.

Platform support

Platform Support Notes
Android API 24+ Platform WebView; no permissions declared
iOS 15.0+ WebKit, UIKit; Swift compilation and device QA still pending
PAM Native 1.46.0 to < 2.0.0 From pam-native.plugin.json; PHP 8.5+

API

Method Effect
make(string $source) URL (https, http, file) or inline HTML, 1 byte to 1 MiB
javaScriptEnabled(bool), domStorageEnabled(bool), allowsInlineMedia(bool) Default true
userAgent(?string) Custom user agent; null restores the default
injectedJavaScript(string) Script run on every load (at most 1 MiB)
allowedHosts(list<string>) Navigation host allowlist (see Errors)
scrollEnabled(bool), overScrollMode(ScrollOverScrollMode) scrollEnabled(false) stops scrolling, bounce and over-scroll (full-screen pages such as games)
onLoad(Closure), onError(Closure(string $message, WebViewErrorCode $code)), onMessage(Closure(string $message, string $url)) Native events; one-argument onError handlers keep working

Errors

onError reports main-frame failures with a WebViewErrorCode:

Code When Native
Load The main-frame load failed (no connection, DNS, TLS) Android onReceivedError, iOS didFailProvisionalNavigation
Timeout The first page did not finish within 30 seconds Both
Blocked The page being loaded, or a redirect while it loads, is outside allowedHosts, or allowedHosts changed to exclude the current page Both
ProcessGone The web content process died Android onRenderProcessGone (8.0+), iOS webViewWebContentProcessDidTerminate

A link, target=_blank or script redirect outside allowedHosts on a page that already finished loading is only cancelled: the page stays and onError is not called (react-native-webview onShouldStartLoadWithRequest returning false). Open such links yourself if needed.

ProcessGone: on Android the renderer crashed or the system killed it (memory pressure while the page is open or in the background). Android would otherwise kill the whole app; the plugin keeps the app running, hides that WebView and destroys it once it leaves the screen, since a WebView whose renderer died can never be used again. On iOS the WebContent process was terminated and the page is blank. On both, remount the web view with a new key to load again, or show a failure. Native sides older than 0.2.0 send no code, which reads as Load.

Core extraction (1.46)

This capability moved out of the PAM Native core in 1.46. The core keeps deprecated PHP aliases through 1.46; they are removed in 1.47. Native wire contracts are retained, so existing pages keep working; migrate imports to Pam\Native\WebView\WebView.

Docs

Part of the PAM ecosystem

PAM

PAM runs PHP natively on servers, desktops and phones. This repository is one piece of it.

PAM PAM Desktop PAM Native Ecosystem
the runtime and CLI native desktop apps in PHP native Android and iOS apps in PHP every official package and plugin

Docs: push-in.github.io/pam-docs · Issues

Apache License 2.0 · Made in Brazil by Pushin