react-native-minimal-webview 1.2.0 → 1.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +35 -31
- package/android/build.gradle +1 -1
- package/android/src/main/java/expo/modules/minimalwebview/Asks.kt +5 -11
- package/android/src/main/java/expo/modules/minimalwebview/Hooks.kt +17 -11
- package/android/src/main/java/expo/modules/minimalwebview/MinimalWebView.kt +83 -125
- package/android/src/main/java/expo/modules/minimalwebview/MinimalWebViewClients.kt +16 -31
- package/android/src/main/java/expo/modules/minimalwebview/MinimalWebViewModule.kt +18 -19
- package/android/src/main/java/expo/modules/minimalwebview/MinimalWebViewNavigation.kt +24 -38
- package/android/src/main/java/expo/modules/minimalwebview/MinimalWebViewScripts.kt +24 -36
- package/android/src/main/java/expo/modules/minimalwebview/NavigationRules.kt +19 -20
- package/android/src/main/java/expo/modules/minimalwebview/PlatformSettings.kt +41 -37
- package/android/src/main/java/expo/modules/minimalwebview/PullToRefresh.kt +14 -18
- package/android/src/main/java/expo/modules/minimalwebview/requests/Downloads.kt +12 -23
- package/android/src/main/java/expo/modules/minimalwebview/requests/FileUpload.kt +0 -1
- package/android/src/main/java/expo/modules/minimalwebview/requests/FullscreenVideo.kt +1 -4
- package/android/src/main/java/expo/modules/minimalwebview/requests/Permissions.kt +34 -24
- package/build/WebView.d.ts +11 -2
- package/build/WebView.d.ts.map +1 -1
- package/build/WebView.js +45 -71
- package/build/WebView.js.map +1 -1
- package/build/bridge/createBridge.d.ts +1 -5
- package/build/bridge/createBridge.d.ts.map +1 -1
- package/build/bridge/createBridge.js +3 -15
- package/build/bridge/createBridge.js.map +1 -1
- package/build/bridge/endpoint.d.ts +1 -2
- package/build/bridge/endpoint.d.ts.map +1 -1
- package/build/bridge/endpoint.js +5 -6
- package/build/bridge/endpoint.js.map +1 -1
- package/build/bridge/matchesOrigin.d.ts +11 -0
- package/build/bridge/matchesOrigin.d.ts.map +1 -0
- package/build/bridge/matchesOrigin.js +26 -0
- package/build/bridge/matchesOrigin.js.map +1 -0
- package/build/bridge/origins.d.ts +2 -13
- package/build/bridge/origins.d.ts.map +1 -1
- package/build/bridge/origins.js +1 -30
- package/build/bridge/origins.js.map +1 -1
- package/build/bridge/pageClient.generated.d.ts +1 -1
- package/build/bridge/pageClient.generated.d.ts.map +1 -1
- package/build/bridge/pageClient.generated.js +2 -2
- package/build/bridge/pageClient.generated.js.map +1 -1
- package/build/bridge/protocol.d.ts +3 -5
- package/build/bridge/protocol.d.ts.map +1 -1
- package/build/bridge/protocol.js +12 -14
- package/build/bridge/protocol.js.map +1 -1
- package/build/index.d.ts +1 -1
- package/build/index.js +1 -1
- package/build/navigationRules.d.ts +0 -5
- package/build/navigationRules.d.ts.map +1 -1
- package/build/navigationRules.js +3 -12
- package/build/navigationRules.js.map +1 -1
- package/build/reactNativeWebViewDefaults.d.ts +0 -4
- package/build/reactNativeWebViewDefaults.d.ts.map +1 -1
- package/build/reactNativeWebViewDefaults.js +0 -4
- package/build/reactNativeWebViewDefaults.js.map +1 -1
- package/build/reactNativeWebViewMessages.d.ts.map +1 -1
- package/build/reactNativeWebViewMessages.js +0 -1
- package/build/reactNativeWebViewMessages.js.map +1 -1
- package/build/refStore.d.ts +0 -2
- package/build/refStore.d.ts.map +1 -1
- package/build/refStore.js +0 -6
- package/build/refStore.js.map +1 -1
- package/build/types.d.ts +55 -39
- package/build/types.d.ts.map +1 -1
- package/ios/Asks.swift +6 -9
- package/ios/DelegateProxy.swift +4 -18
- package/ios/DownloadName.swift +0 -2
- package/ios/Downloads.swift +0 -2
- package/ios/Hooks.swift +4 -6
- package/ios/Loads.swift +37 -19
- package/ios/MinimalWebView+Dialogs.swift +5 -7
- package/ios/MinimalWebView+Navigation.swift +23 -49
- package/ios/MinimalWebView+Scripts.swift +10 -17
- package/ios/MinimalWebView.podspec +1 -2
- package/ios/MinimalWebView.swift +63 -128
- package/ios/MinimalWebViewModule.swift +1 -18
- package/ios/NavigationRules.swift +2 -9
- package/ios/OriginRules.swift +4 -13
- package/ios/PlatformSettings.swift +9 -30
- package/ios/ReadAccess.swift +0 -2
- package/ios/Records.swift +18 -0
- package/ios/Recovery.swift +2 -8
- package/ios/SharedCookies.swift +10 -25
- package/mocks/MinimalWebView.ts +5 -0
- package/package.json +11 -10
- package/src/WebView.tsx +58 -80
- package/src/bridge/createBridge.ts +5 -20
- package/src/bridge/endpoint.ts +6 -9
- package/src/bridge/matchesOrigin.ts +27 -0
- package/src/bridge/origins.ts +2 -30
- package/src/bridge/pageClient.generated.ts +2 -2
- package/src/bridge/pageClient.ts +1 -7
- package/src/bridge/protocol.ts +16 -18
- package/src/index.ts +1 -1
- package/src/navigationRules.ts +6 -12
- package/src/reactNativeWebViewDefaults.ts +0 -4
- package/src/reactNativeWebViewMessages.ts +0 -1
- package/src/refStore.ts +0 -7
- package/src/types.ts +55 -39
package/src/bridge/pageClient.ts
CHANGED
|
@@ -1,6 +1,3 @@
|
|
|
1
|
-
// The page side of the bridge: installs `window.nativeBridge`. It runs in the page, compiled into PAGE_CLIENT by
|
|
2
|
-
// .github/scripts/build-page-client.mts. Page -> native: iOS WKScriptMessageHandler, Android addWebMessageListener;
|
|
3
|
-
// native -> page: `__receive` (iOS callAsyncJavaScript) or the transport's `onmessage` (Android).
|
|
4
1
|
import type { PageBridge } from '../types';
|
|
5
2
|
import { createEndpoint } from './endpoint';
|
|
6
3
|
import type { BridgeMessage as Message } from './protocol';
|
|
@@ -19,7 +16,6 @@ type PageWindow = Window & {
|
|
|
19
16
|
export function installPageClient(w: PageWindow, timeoutMs: number) {
|
|
20
17
|
// Main frame only (Android injects into allowed-origin iframes too, but only the main frame's messages are taken).
|
|
21
18
|
if (w.nativeBridge || w !== w.top) return;
|
|
22
|
-
// This document's token (protocol.ts `doc`).
|
|
23
19
|
const doc = Math.random().toString(36).slice(2, 10);
|
|
24
20
|
|
|
25
21
|
const ios = w.webkit?.messageHandlers?.nativeBridge;
|
|
@@ -43,7 +39,6 @@ export function installPageClient(w: PageWindow, timeoutMs: number) {
|
|
|
43
39
|
emit: endpoint.emit,
|
|
44
40
|
handle: endpoint.handle,
|
|
45
41
|
on: endpoint.on,
|
|
46
|
-
/** iOS's entry point, origin-checked there. */
|
|
47
42
|
__receive: receive,
|
|
48
43
|
});
|
|
49
44
|
if (w.document.readyState === 'loading') {
|
|
@@ -53,8 +48,7 @@ export function installPageClient(w: PageWindow, timeoutMs: number) {
|
|
|
53
48
|
} else {
|
|
54
49
|
send({ kind: 'ready' });
|
|
55
50
|
}
|
|
56
|
-
//
|
|
57
|
-
// answers to this page's calls went to the page shown meanwhile. Fail those calls and announce the page again.
|
|
51
|
+
// A page restored from the back-forward cache does not run its scripts again.
|
|
58
52
|
w.addEventListener('pageshow', (event) => {
|
|
59
53
|
if (!event.persisted) return;
|
|
60
54
|
endpoint.rejectPending('navigated', 'the page was left before the call was answered');
|
package/src/bridge/protocol.ts
CHANGED
|
@@ -1,7 +1,5 @@
|
|
|
1
|
-
// The bridge wire format. The RN side parses with it.
|
|
2
1
|
import type { ErrorCode } from '../types';
|
|
3
2
|
|
|
4
|
-
/** The codes a bridge call rejects with: the page may send only these. */
|
|
5
3
|
const ERROR_CODES = [
|
|
6
4
|
'timeout',
|
|
7
5
|
'not_found',
|
|
@@ -16,20 +14,19 @@ export type BridgeErrorCode = (typeof ERROR_CODES)[number];
|
|
|
16
14
|
* events for the page until then (native can't deliver before the page has posted). A page's own calls and their
|
|
17
15
|
* answers don't wait for it.
|
|
18
16
|
* `call` / `result` / `error`: a request and its answer, matched by `id`.
|
|
19
|
-
* `event`: fire-and-forget
|
|
17
|
+
* `event`: fire-and-forget.
|
|
20
18
|
*
|
|
21
19
|
* `doc` is the page document's random token. Each side puts a token on every message (RN the token of the document it
|
|
22
20
|
* means), and the page drops any message that isn't for it: native delivers to whatever document is current (iOS
|
|
23
21
|
* checks only the origin), so a message posted as a same-origin navigation commits would otherwise reach the new page.
|
|
24
|
-
* It is for correctness, not security: an allowed page can rebind its own client.
|
|
25
|
-
* `send` adds it.
|
|
22
|
+
* It is for correctness, not security: an allowed page can rebind its own client.
|
|
26
23
|
*/
|
|
27
24
|
export type BridgeMessage = { doc?: string } & (
|
|
28
25
|
| { kind: 'ready' }
|
|
29
26
|
| { kind: 'call'; id: string; method: string; params?: unknown }
|
|
30
27
|
| { kind: 'result'; id: string; value?: unknown }
|
|
31
28
|
| { kind: 'error'; id: string; error: { code: BridgeErrorCode; message: string } }
|
|
32
|
-
| { kind: 'event';
|
|
29
|
+
| { kind: 'event'; event: string; params?: unknown }
|
|
33
30
|
);
|
|
34
31
|
|
|
35
32
|
const isObject = (value: unknown): value is Record<string, unknown> =>
|
|
@@ -47,32 +44,33 @@ export function parseBridgeMessage(raw: string): (BridgeMessage & { doc: string
|
|
|
47
44
|
return 'not JSON';
|
|
48
45
|
}
|
|
49
46
|
if (!isObject(value) || typeof value['doc'] !== 'string') return 'missing doc';
|
|
50
|
-
|
|
47
|
+
const problem = kindProblem(value);
|
|
48
|
+
if (problem) return problem;
|
|
49
|
+
const message = value as BridgeMessage & { doc: string };
|
|
50
|
+
return message.kind === 'error' && !ERROR_CODES.includes(message.error.code)
|
|
51
|
+
? { ...message, error: { ...message.error, code: 'handler_error' } }
|
|
52
|
+
: message;
|
|
51
53
|
}
|
|
52
54
|
|
|
55
|
+
const isName = (value: unknown) => typeof value === 'string' && value !== '';
|
|
56
|
+
|
|
53
57
|
function kindProblem(value: Record<string, unknown>): string | null {
|
|
54
58
|
const hasId = typeof value['id'] === 'string';
|
|
55
|
-
const hasMethod = typeof value['method'] === 'string' && value['method'] !== '';
|
|
56
59
|
switch (value['kind']) {
|
|
57
60
|
case 'ready':
|
|
58
61
|
return null;
|
|
59
62
|
case 'event':
|
|
60
|
-
return
|
|
63
|
+
return isName(value['event']) ? null : 'missing event';
|
|
61
64
|
case 'call':
|
|
62
|
-
return hasId &&
|
|
65
|
+
return hasId && isName(value['method']) ? null : 'missing id or method';
|
|
63
66
|
case 'result':
|
|
64
67
|
return hasId ? null : 'missing id';
|
|
65
68
|
case 'error':
|
|
66
|
-
return !hasId ? 'missing id' :
|
|
69
|
+
return !hasId ? 'missing id' : isError(value['error']) ? null : 'malformed error';
|
|
67
70
|
default:
|
|
68
71
|
return 'unknown kind';
|
|
69
72
|
}
|
|
70
73
|
}
|
|
71
74
|
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
if (!isObject(error) || typeof error['code'] !== 'string' || typeof error['message'] !== 'string')
|
|
75
|
-
return false;
|
|
76
|
-
if (!(ERROR_CODES as readonly string[]).includes(error['code'])) error['code'] = 'handler_error';
|
|
77
|
-
return true;
|
|
78
|
-
}
|
|
75
|
+
const isError = (error: unknown) =>
|
|
76
|
+
isObject(error) && typeof error['code'] === 'string' && typeof error['message'] === 'string';
|
package/src/index.ts
CHANGED
|
@@ -14,7 +14,7 @@
|
|
|
14
14
|
* @groupDescription Page requests
|
|
15
15
|
* File pickers, permission prompts and downloads the page starts.
|
|
16
16
|
* @groupDescription Native hooks
|
|
17
|
-
* Turning native hooks on with the `extensions` prop, and what they send to each extension's `onEvent`.
|
|
17
|
+
* Turning native hooks on with the `extensions` prop, and what they send to each extension's `onEvent` and `onAsk`.
|
|
18
18
|
* @groupDescription Platform settings
|
|
19
19
|
* WebKit, UIScrollView and Android WebView settings, set by their platform names through the `ios` and `android` props.
|
|
20
20
|
* @module react-native-minimal-webview
|
package/src/navigationRules.ts
CHANGED
|
@@ -23,7 +23,6 @@ export const defaultNavigationRules: readonly NavigationRule[] = freeze<Navigati
|
|
|
23
23
|
{ mainFrame: true, userInitiated: true, action: 'external' },
|
|
24
24
|
]);
|
|
25
25
|
|
|
26
|
-
/** Each rule field's kind, from its type, so that a field missing here, or not in the type, fails to compile. */
|
|
27
26
|
const RULE_FIELDS = new Map(
|
|
28
27
|
Object.entries({
|
|
29
28
|
scheme: 'list',
|
|
@@ -49,17 +48,14 @@ const ACTIONS: unknown[] = Object.keys({
|
|
|
49
48
|
ask: 0,
|
|
50
49
|
} satisfies Record<NavigationRule['action'], 0>);
|
|
51
50
|
|
|
52
|
-
/** A value as a warning shows it. */
|
|
53
51
|
const shown = (value: unknown) => {
|
|
54
52
|
try {
|
|
55
53
|
return JSON.stringify(value) ?? String(value);
|
|
56
54
|
} catch {
|
|
57
|
-
// A BigInt, a circular value or a throwing toJSON: the message runs in production too, so it must not throw.
|
|
58
55
|
return typeof value === 'bigint' ? String(value) : Object.prototype.toString.call(value);
|
|
59
56
|
}
|
|
60
57
|
};
|
|
61
58
|
|
|
62
|
-
/** What a field of each kind takes, as a warning says it, and the check. */
|
|
63
59
|
const FIELD_KINDS = {
|
|
64
60
|
list: {
|
|
65
61
|
takes: 'an array of strings',
|
|
@@ -70,23 +66,21 @@ const FIELD_KINDS = {
|
|
|
70
66
|
action: { takes: `one of ${shown(ACTIONS)}`, ok: (value: unknown) => ACTIONS.includes(value) },
|
|
71
67
|
};
|
|
72
68
|
|
|
69
|
+
const REQUIRED_FIELDS_UNSET = { action: undefined } satisfies {
|
|
70
|
+
[K in keyof NavigationRule as object extends Pick<NavigationRule, K> ? never : K]: undefined;
|
|
71
|
+
};
|
|
72
|
+
|
|
73
73
|
function ruleProblem(rule: unknown) {
|
|
74
74
|
if (typeof rule !== 'object' || rule === null) return `must be an object, not ${shown(rule)}`;
|
|
75
|
-
|
|
76
|
-
for (const [key, value] of Object.entries({ action: undefined, ...rule })) {
|
|
75
|
+
for (const [key, value] of Object.entries({ ...REQUIRED_FIELDS_UNSET, ...rule })) {
|
|
77
76
|
const kind = RULE_FIELDS.get(key);
|
|
78
77
|
if (!kind) return `unknown key ${shown(key)}`;
|
|
79
|
-
if ((value !== undefined ||
|
|
78
|
+
if ((value !== undefined || key in REQUIRED_FIELDS_UNSET) && !FIELD_KINDS[kind].ok(value))
|
|
80
79
|
return `${key} must be ${FIELD_KINDS[kind].takes}, not ${shown(value)}`;
|
|
81
80
|
}
|
|
82
81
|
return undefined;
|
|
83
82
|
}
|
|
84
83
|
|
|
85
|
-
/**
|
|
86
|
-
* The rules as the core gets them, and a warning for each malformed one. The core skips an unknown key and a
|
|
87
|
-
* non-boolean flag, which would widen a rule (`hosts` would match every host), so a malformed rule becomes a `block`
|
|
88
|
-
* one. The same array when none is malformed.
|
|
89
|
-
*/
|
|
90
84
|
export function checkNavigationRules(given: unknown): {
|
|
91
85
|
checked: NavigationRule[];
|
|
92
86
|
warnings: string[];
|
|
@@ -1,9 +1,5 @@
|
|
|
1
1
|
import type { AndroidSettings, IOSSettings } from './types';
|
|
2
2
|
|
|
3
|
-
/**
|
|
4
|
-
* react-native-webview's defaults, so that an app migrated from it behaves as before. An app sets any back through
|
|
5
|
-
* `ios` or `android`.
|
|
6
|
-
*/
|
|
7
3
|
export const REACT_NATIVE_WEBVIEW_DEFAULTS = {
|
|
8
4
|
ios: { scrollView: { directionalLockEnabled: true } },
|
|
9
5
|
android: {
|
|
@@ -16,7 +16,6 @@ import type { InjectedScript } from './types';
|
|
|
16
16
|
* @group Scripts
|
|
17
17
|
*/
|
|
18
18
|
export const reactNativeWebViewMessages: InjectedScript = {
|
|
19
|
-
// Runs after the bridge's own script, so `window.nativeBridge` already exists where the bridge is installed.
|
|
20
19
|
code: `if (window.nativeBridge) {
|
|
21
20
|
window.ReactNativeWebView = { postMessage: (data) => window.nativeBridge.emit('rnw', String(data)) };
|
|
22
21
|
window.nativeBridge.on('rnw', (data) =>
|
package/src/refStore.ts
CHANGED
|
@@ -10,7 +10,6 @@ import {
|
|
|
10
10
|
|
|
11
11
|
import type { NavigationState, WebViewRef, WebViewRefObject } from './types';
|
|
12
12
|
|
|
13
|
-
/** An empty `url`, so a stale URL never looks valid while no WebView is mounted. */
|
|
14
13
|
const INITIAL_STATE: NavigationState = {
|
|
15
14
|
url: '',
|
|
16
15
|
pendingUrl: null,
|
|
@@ -22,7 +21,6 @@ const INITIAL_STATE: NavigationState = {
|
|
|
22
21
|
outcome: null,
|
|
23
22
|
};
|
|
24
23
|
|
|
25
|
-
/** A mounted WebView's hold on its ref: `handle` passes on the WebView's state, and lets go at unmount. */
|
|
26
24
|
type Adapter = {
|
|
27
25
|
nav: WebViewRefObject;
|
|
28
26
|
attach(handle: WebViewRef, state: NavigationState): void;
|
|
@@ -30,7 +28,6 @@ type Adapter = {
|
|
|
30
28
|
detach(handle: WebViewRef): void;
|
|
31
29
|
};
|
|
32
30
|
|
|
33
|
-
/** The navigation object behind each ref object: created by createWebViewRef, or made on first use for a plain ref. */
|
|
34
31
|
const adapters = new WeakMap<object, Adapter>();
|
|
35
32
|
|
|
36
33
|
function adapterFor(ref: object) {
|
|
@@ -59,7 +56,6 @@ function createAdapter(): Adapter {
|
|
|
59
56
|
};
|
|
60
57
|
return {
|
|
61
58
|
nav,
|
|
62
|
-
// Last attached wins, like a React ref; an earlier instance's later updates and detach are ignored.
|
|
63
59
|
attach(handle, initial) {
|
|
64
60
|
if (__DEV__ && attached) {
|
|
65
61
|
console.warn(
|
|
@@ -93,8 +89,6 @@ export function createWebViewRef(): WebViewRefObject {
|
|
|
93
89
|
}
|
|
94
90
|
|
|
95
91
|
/**
|
|
96
|
-
* Attaches `handle` to `ref`. A callback or plain ref gets it through `useImperativeHandle`; a `createWebViewRef` ref
|
|
97
|
-
* serves it as its own `current`. Any ref object also gets the navigation state through its adapter.
|
|
98
92
|
* Returns a function that records a new state, passes it to the attached ref and returns the previous state.
|
|
99
93
|
*/
|
|
100
94
|
export function useAttach(
|
|
@@ -148,7 +142,6 @@ export function useWebViewState<T>(
|
|
|
148
142
|
return useSyncExternalStore(nav.subscribe, getSnapshot);
|
|
149
143
|
}
|
|
150
144
|
|
|
151
|
-
/** `select` of the current state, run again only for another state: a snapshot is the same value until a change. */
|
|
152
145
|
function selectFrom<T>(getState: () => NavigationState, select: (state: NavigationState) => T) {
|
|
153
146
|
let last: { state: NavigationState; selected: T } | undefined;
|
|
154
147
|
return () => {
|
package/src/types.ts
CHANGED
|
@@ -14,6 +14,7 @@ import type {
|
|
|
14
14
|
/**
|
|
15
15
|
* What the WebView loads: a URL, or an HTML string.
|
|
16
16
|
* @see [Local files example](https://rasmuskard.github.io/react-native-minimal-webview/guides/examples/#local-files)
|
|
17
|
+
* @see [Bundled page folder example](https://rasmuskard.github.io/react-native-minimal-webview/guides/examples/#load-a-bundled-page-folder)
|
|
17
18
|
* @group WebView
|
|
18
19
|
*/
|
|
19
20
|
export type WebViewSource =
|
|
@@ -211,7 +212,7 @@ export type NavigationState = {
|
|
|
211
212
|
* - `failed`: a network or SSL error, or a renderer crash, cut it off.
|
|
212
213
|
* - `cancelled`: it never showed a page (a stop before the response, a download, a 204, a redirect the rules blocked,
|
|
213
214
|
* a load a newer one replaced); a stop after the page arrived is `cancelled` on iOS but `finished` on Android, and
|
|
214
|
-
* a 204 is `finished`
|
|
215
|
+
* a 204 is `finished` below iOS 26.2. On iOS a load replaced before it commits doesn't end: `loading` stays true and
|
|
215
216
|
* the newer load's outcome ends both.
|
|
216
217
|
*
|
|
217
218
|
* On Android with an Android System WebView older than 146, a load that never commits changes nothing here.
|
|
@@ -247,8 +248,8 @@ export type ProcessGoneEvent = {
|
|
|
247
248
|
* the app is not in the background; a `load()`, `reload()` or new `source` meanwhile loads instead.
|
|
248
249
|
*
|
|
249
250
|
* - iOS: in place.
|
|
250
|
-
* - Android: in a new WebView. The history is restored unless the `source` page was on screen. The
|
|
251
|
-
* applied again, but not what `call` set.
|
|
251
|
+
* - Android: in a new WebView. The history is restored, unless the `source` page was on screen and reloads. The
|
|
252
|
+
* props are applied again, but not what `call` set.
|
|
252
253
|
*
|
|
253
254
|
* It is false when:
|
|
254
255
|
*
|
|
@@ -557,8 +558,11 @@ export type Download = {
|
|
|
557
558
|
* - `network`: connecting or reading the response failed, or a redirect was refused.
|
|
558
559
|
* - `http`: the response had an error status (Android only: iOS saves what the server sent).
|
|
559
560
|
* - `data` (the content): a bad `data:` or `blob:` URL, the page not reading its blob, an unsupported scheme, or
|
|
560
|
-
* (Android) a file above 100
|
|
561
|
+
* (Android) a file above 100 MiB or a `blob:` URL the main frame can't read (a cross-origin iframe's, or one already
|
|
561
562
|
* revoked).
|
|
563
|
+
*
|
|
564
|
+
* On Android a disk error while saving, such as a full disk, is `network` for an http(s) download and `data` for a
|
|
565
|
+
* `data:` or `blob:` one.
|
|
562
566
|
* @group Page requests
|
|
563
567
|
*/
|
|
564
568
|
export type DownloadFailure =
|
|
@@ -636,7 +640,9 @@ export type IOSPrivateSettingKeys = {
|
|
|
636
640
|
* `webView.opaque`, is skipped the same way: set it with `call('webView.setOpaque:', [false])`.
|
|
637
641
|
*
|
|
638
642
|
* A root's default keys are the package's, and yours go over them. A key the package doesn't set keeps WebKit's
|
|
639
|
-
* default; a key you remove goes back to the value it had before you first set it.
|
|
643
|
+
* default; a key you remove goes back to the value it had before you first set it. For
|
|
644
|
+
* `webView.underPageBackgroundColor`, which WebKit derives from the page, that value is the color derived then, and it
|
|
645
|
+
* stays: set the key to `null` instead of removing it to go back to WebKit's default.
|
|
640
646
|
*
|
|
641
647
|
* WebKit has no mixed-content setting: it applies its own policy.
|
|
642
648
|
* @ios
|
|
@@ -707,7 +713,8 @@ export type AndroidSettings = {
|
|
|
707
713
|
*
|
|
708
714
|
* - On: `javaScriptEnabled`, `domStorageEnabled`, `supportMultipleWindows`, `builtInZoomControls`,
|
|
709
715
|
* `useWideViewPort`, `loadWithOverviewMode` and, with Android System WebView 146 and newer,
|
|
710
|
-
* `backForwardCacheEnabled`.
|
|
716
|
+
* `backForwardCacheEnabled`. Older ones refuse `backForwardCacheEnabled: true`, in this prop and in `call`:
|
|
717
|
+
* a page restored from the cache there reports no load end.
|
|
711
718
|
* - Off: `allowFileAccess`, `allowContentAccess`, `displayZoomControls` and `downloadFaviconsEnabled`.
|
|
712
719
|
* - `mixedContentMode`: `MIXED_CONTENT_NEVER_ALLOW`.
|
|
713
720
|
*
|
|
@@ -741,7 +748,8 @@ export type HookEvent<N extends string = string, P = Record<string, unknown>> =
|
|
|
741
748
|
*
|
|
742
749
|
* A package with a native hook exports a function that returns one, so that an app turns the hook on by putting it in
|
|
743
750
|
* `extensions`.
|
|
744
|
-
* @typeParam E - The hook's events, to type `onEvent`: a union of {@link HookEvent}s, which nothing checks
|
|
751
|
+
* @typeParam E - The hook's events, to type `onEvent` and `onAsk`: a union of {@link HookEvent}s, which nothing checks
|
|
752
|
+
* at runtime.
|
|
745
753
|
* @see [Native hooks guide](https://rasmuskard.github.io/react-native-minimal-webview/guides/native-hooks/)
|
|
746
754
|
* @group Native hooks
|
|
747
755
|
*/
|
|
@@ -761,14 +769,19 @@ export type HookExtension<E extends HookEvent = HookEvent> = {
|
|
|
761
769
|
*/
|
|
762
770
|
options?: unknown;
|
|
763
771
|
/**
|
|
764
|
-
* Each of the hook's events: it goes to the extension with the hook's key, and one no extension owns is dropped.
|
|
765
|
-
*
|
|
766
|
-
*
|
|
767
|
-
* no timeout, but one still open when the page goes away is answered null.
|
|
772
|
+
* Each of the hook's events: it goes to the extension with the hook's key, and one no extension owns is dropped. An
|
|
773
|
+
* `ask` goes to {@link HookExtension.onAsk} instead when the extension has one; without it, an `ask` comes here with
|
|
774
|
+
* `signal` set, and the return value is the answer as `onAsk` describes. `signal` is undefined for an `emit`.
|
|
768
775
|
*
|
|
769
|
-
* The latest `onEvent` always
|
|
776
|
+
* The latest `onEvent` and `onAsk` always take the events: a render with new handlers sends the core nothing.
|
|
770
777
|
*/
|
|
771
778
|
onEvent?(event: E, signal?: AbortSignal): unknown;
|
|
779
|
+
/**
|
|
780
|
+
* Each of the hook's asks, in place of {@link HookExtension.onEvent}. The return value (a promise is awaited) is the
|
|
781
|
+
* answer, and `undefined`, or a value JSON can't encode, answers null. `signal` aborts when the core stops waiting
|
|
782
|
+
* for the answer: an ask has no timeout, but one still open when the page goes away is answered null.
|
|
783
|
+
*/
|
|
784
|
+
onAsk?(event: E, signal: AbortSignal): unknown;
|
|
772
785
|
};
|
|
773
786
|
|
|
774
787
|
/**
|
|
@@ -827,35 +840,33 @@ export type ErrorCode =
|
|
|
827
840
|
export type CodedError = Error & { code: ErrorCode };
|
|
828
841
|
|
|
829
842
|
/**
|
|
830
|
-
*
|
|
843
|
+
* The props of `<WebView>`, of which only `source` is required.
|
|
831
844
|
*
|
|
832
|
-
*
|
|
833
|
-
*
|
|
845
|
+
* React Native's `ViewProps` (`style`, `testID`, `nativeID`, the accessibility props, layout and touch events) go to
|
|
846
|
+
* the native view.
|
|
834
847
|
*
|
|
835
848
|
* Every `on…` callback is read when its event or request comes, so adding, changing or removing one applies to the
|
|
836
|
-
* next
|
|
837
|
-
*
|
|
838
|
-
* One that answers a request and throws (or rejects) is logged with `console.error` and gives the refusing answer:
|
|
849
|
+
* next. A request without its callback gets the default its prop describes; one whose callback throws or rejects is
|
|
850
|
+
* logged with `console.error` and gets the refusing answer:
|
|
839
851
|
*
|
|
840
852
|
* - `onNavigationRequest`: `block`
|
|
841
853
|
* - `onOpenExternal`: null (the core opens nothing)
|
|
842
854
|
* - `onFileRequest`: cancel
|
|
843
855
|
* - `onPermissionRequest`: deny
|
|
844
|
-
* - an extension's `onEvent`: null
|
|
856
|
+
* - an extension's `onAsk` or `onEvent`: null
|
|
845
857
|
*
|
|
846
858
|
* The `signal` such a callback gets aborts when the core stops waiting for its answer (the page moved on, crashed or
|
|
847
859
|
* unmounted), and a late answer is dropped.
|
|
848
860
|
*
|
|
849
|
-
* JS dialogs (`alert`, `confirm`, `prompt`) and HTTP auth have no prop
|
|
861
|
+
* JS dialogs (`alert`, `confirm`, `prompt`) and HTTP auth have no prop: `dialogs` and `basicAuthCredential` of
|
|
862
|
+
* `@react-native-minimal-webview/extensions` take them over, or a native hook does. Without one:
|
|
850
863
|
*
|
|
851
864
|
* - iOS dialogs: a `UIAlertController` titled with the frame's host, or `JavaScript` for a frame without one
|
|
852
865
|
* (`data:`, sandboxed, `file:`). One shows at a time; one that comes while another shows is cancelled.
|
|
853
|
-
* - Android dialogs: WebView's own.
|
|
866
|
+
* - Android dialogs: WebView's own. One still on screen when its WebView unmounts stays there, and a WebView older
|
|
867
|
+
* than 149 then gets no touches until the app restarts. The `dialogs` extension shows no native dialog.
|
|
854
868
|
* - HTTP auth: cancelled on Android. On iOS WebKit's default handling applies, so without a stored credential the
|
|
855
869
|
* site's 401 page shows.
|
|
856
|
-
*
|
|
857
|
-
* `dialogs` and `basicAuthCredential` of `@react-native-minimal-webview/extensions` take them over, or a native hook
|
|
858
|
-
* does.
|
|
859
870
|
* @sortStrategy source-order
|
|
860
871
|
* @group WebView
|
|
861
872
|
*/
|
|
@@ -974,8 +985,9 @@ export interface WebViewProps extends Omit<ViewProps, 'children'> {
|
|
|
974
985
|
* A false, null or undefined entry is left out, so `on && extension(…)` switches one on and off; see
|
|
975
986
|
* {@link HookExtension.options} for what off means. A hook attaches when its key first appears, and a later change of
|
|
976
987
|
* its `options` reaches it live, without recreating the WebView. A key turned on after the WebView was created
|
|
977
|
-
* attaches its hook then, unless the hook
|
|
978
|
-
*
|
|
988
|
+
* attaches its hook then, unless the hook attaches only to a WebView mounted with its key on, and a warning says so.
|
|
989
|
+
* The [guide's Lifecycle table](https://rasmuskard.github.io/react-native-minimal-webview/guides/native-hooks/#lifecycle)
|
|
990
|
+
* says which hooks do.
|
|
979
991
|
* @see [Native hooks guide](https://rasmuskard.github.io/react-native-minimal-webview/guides/native-hooks/)
|
|
980
992
|
*/
|
|
981
993
|
extensions?: readonly (HookExtension | false | null | undefined)[];
|
|
@@ -995,8 +1007,9 @@ export interface WebViewProps extends Omit<ViewProps, 'children'> {
|
|
|
995
1007
|
* for it;
|
|
996
1008
|
* - the WebView into `HTTPCookieStorage` on every cookie change, deletions included, as it happens.
|
|
997
1009
|
*
|
|
998
|
-
* Android needs nothing: `CookieManager` is shared app-wide,
|
|
999
|
-
* WebView on another `android.webView.profile` has that profile's cookies
|
|
1010
|
+
* Android needs nothing: `CookieManager` is shared app-wide, React Native's `fetch` uses it too, and it is flushed
|
|
1011
|
+
* when the app goes to the background. A WebView on another `android.webView.profile` has that profile's cookies
|
|
1012
|
+
* instead.
|
|
1000
1013
|
* @default `false`
|
|
1001
1014
|
* @ios
|
|
1002
1015
|
* @see [Cookies example](https://rasmuskard.github.io/react-native-minimal-webview/guides/examples/#cookies)
|
|
@@ -1092,13 +1105,17 @@ export interface WebViewProps extends Omit<ViewProps, 'children'> {
|
|
|
1092
1105
|
* with an Android System WebView older than 146, an SSL error on a back/forward load isn't reported.
|
|
1093
1106
|
*
|
|
1094
1107
|
* A renderer crash isn't reported here: it makes the cut-off load's `outcome` `failed` and calls `onProcessGone`.
|
|
1108
|
+
*
|
|
1109
|
+
* On Android it also gets a `network` error with code `-1` when no WebView can be made, because Android System
|
|
1110
|
+
* WebView is missing, disabled or updating; {@link WebViewRef.reload | reload()} tries again.
|
|
1095
1111
|
* @see [Loading and error screens example](https://rasmuskard.github.io/react-native-minimal-webview/guides/examples/#loading-and-error-screens)
|
|
1096
1112
|
*/
|
|
1097
1113
|
onError?: (event: LoadErrorEvent) => void;
|
|
1098
1114
|
/**
|
|
1099
1115
|
* The renderer died; see {@link ProcessGoneEvent} for the recovery.
|
|
1100
1116
|
*
|
|
1101
|
-
* Android's WebViews share one renderer, so each of them reports its death.
|
|
1117
|
+
* Android's WebViews share one renderer, so each of them reports its death. On Android it comes before the
|
|
1118
|
+
* {@link WebViewProps.onLoadEnd | onLoadEnd} that fails a load the crash cut off after it committed.
|
|
1102
1119
|
*/
|
|
1103
1120
|
onProcessGone?: (event: ProcessGoneEvent) => void;
|
|
1104
1121
|
/** {@link NavigationState.loading | loading} went true. */
|
|
@@ -1190,13 +1207,14 @@ export type WebViewRef = {
|
|
|
1190
1207
|
*/
|
|
1191
1208
|
get(key: string): Promise<unknown>;
|
|
1192
1209
|
/**
|
|
1193
|
-
* Calls a platform method, `root.method`, and resolves with its result through JSON.
|
|
1194
|
-
* when the call arrives: a navigation doesn't reject it.
|
|
1210
|
+
* Calls a platform method, `root.method`, with `args`, and resolves with its result through JSON.
|
|
1195
1211
|
*
|
|
1196
|
-
* The roots are those of {@link WebViewRef.get | get}. On
|
|
1197
|
-
*
|
|
1212
|
+
* The roots are those of {@link WebViewRef.get | get}. On iOS `method` is an Objective-C selector; on Android a
|
|
1213
|
+
* public method of the root's object. Leave a trailing completion handler (iOS) or `ValueCallback` (Android) out of
|
|
1214
|
+
* `args`: the call resolves with what it reports, or on iOS rejects with its error.
|
|
1198
1215
|
*
|
|
1199
|
-
*
|
|
1216
|
+
* It acts on the WebView as it is when the call arrives: a navigation doesn't reject it. Rejects with a
|
|
1217
|
+
* {@link CodedError}: `not_found`, `unavailable` or `native_error`.
|
|
1200
1218
|
*
|
|
1201
1219
|
* The core owns, and so rejects:
|
|
1202
1220
|
*
|
|
@@ -1208,11 +1226,9 @@ export type WebViewRef = {
|
|
|
1208
1226
|
* `resumeTimers`, `evaluateJavascript` and remote debugging
|
|
1209
1227
|
* ({@link AndroidWebView.setWebContentsDebuggingEnabled}).
|
|
1210
1228
|
*
|
|
1211
|
-
*
|
|
1212
|
-
*
|
|
1213
|
-
*
|
|
1214
|
-
* Android, a method that takes `args` as they are wins over one that also takes a callback, and a `null` in the
|
|
1215
|
-
* callback's place passes none.
|
|
1229
|
+
* On iOS, a selector whose completion handler isn't in this package's SDK headers, or reports something other than
|
|
1230
|
+
* an object, an error or an integer, rejects with `native_error`. On Android, a method that takes `args` as they are
|
|
1231
|
+
* wins over one that also takes a callback, and a `null` in the callback's place passes none.
|
|
1216
1232
|
*
|
|
1217
1233
|
* One mistake the signature can't catch crashes the app: on iOS an object argument of the wrong class, and on Android
|
|
1218
1234
|
* a `null` listener or callback other than the trailing `ValueCallback`, once WebView calls it. For a method that
|