react-native-minimal-webview 1.0.0 → 1.0.1
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 +38 -18
- package/android/build.gradle +1 -1
- package/android/consumer-rules.pro +1 -1
- package/android/src/main/java/expo/modules/minimalwebview/DocumentEnd.kt +3 -3
- package/android/src/main/java/expo/modules/minimalwebview/Hooks.kt +33 -42
- package/android/src/main/java/expo/modules/minimalwebview/MinimalWebView.kt +7 -10
- package/android/src/main/java/expo/modules/minimalwebview/MinimalWebViewClients.kt +5 -6
- package/android/src/main/java/expo/modules/minimalwebview/MinimalWebViewModule.kt +4 -4
- package/android/src/main/java/expo/modules/minimalwebview/MinimalWebViewScripts.kt +14 -8
- package/android/src/main/java/expo/modules/minimalwebview/PlatformSettings.kt +13 -16
- package/android/src/main/java/expo/modules/minimalwebview/PullToRefresh.kt +1 -1
- package/android/src/main/java/expo/modules/minimalwebview/requests/Downloads.kt +6 -5
- package/android/src/main/java/expo/modules/minimalwebview/requests/FileUpload.kt +1 -1
- package/android/src/main/java/expo/modules/minimalwebview/requests/FullscreenVideo.kt +1 -1
- package/android/src/main/java/expo/modules/minimalwebview/requests/Permissions.kt +3 -3
- package/build/WebView.d.ts +6 -9
- package/build/WebView.d.ts.map +1 -1
- package/build/WebView.js +23 -18
- package/build/WebView.js.map +1 -1
- package/build/bridge/createBridge.d.ts +3 -3
- package/build/bridge/createBridge.d.ts.map +1 -1
- package/build/bridge/createBridge.js +5 -3
- package/build/bridge/createBridge.js.map +1 -1
- package/build/bridge/endpoint.d.ts +0 -2
- package/build/bridge/endpoint.d.ts.map +1 -1
- package/build/bridge/endpoint.js +8 -3
- package/build/bridge/endpoint.js.map +1 -1
- package/build/bridge/origins.d.ts.map +1 -1
- package/build/bridge/origins.js +0 -1
- 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 +1 -1
- package/build/bridge/pageClient.generated.js.map +1 -1
- package/build/defaultNavigationRules.d.ts +4 -5
- package/build/defaultNavigationRules.d.ts.map +1 -1
- package/build/defaultNavigationRules.js +4 -5
- package/build/defaultNavigationRules.js.map +1 -1
- package/build/index.d.ts +1 -1
- package/build/index.js +1 -1
- package/build/platform.generated.d.ts +14 -15
- package/build/platform.generated.d.ts.map +1 -1
- package/build/platform.generated.js +5 -3
- package/build/platform.generated.js.map +1 -1
- package/build/reactNativeWebViewDefaults.d.ts +2 -2
- package/build/reactNativeWebViewDefaults.js +2 -2
- package/build/reactNativeWebViewMessages.d.ts +8 -14
- package/build/reactNativeWebViewMessages.d.ts.map +1 -1
- package/build/reactNativeWebViewMessages.js +8 -14
- package/build/reactNativeWebViewMessages.js.map +1 -1
- package/build/refStore.d.ts +11 -10
- package/build/refStore.d.ts.map +1 -1
- package/build/refStore.js +7 -5
- package/build/refStore.js.map +1 -1
- package/build/types.d.ts +328 -282
- package/build/types.d.ts.map +1 -1
- package/ios/DelegateProxy.swift +2 -6
- package/ios/DocumentEnd.swift +7 -8
- package/ios/DownloadName.swift +1 -3
- package/ios/Hooks.swift +23 -21
- package/ios/MRWExceptions.h +1 -1
- package/ios/MRWInvoke.h +25 -10
- package/ios/MinimalWebView+Dialogs.swift +4 -7
- package/ios/MinimalWebView+Navigation.swift +25 -26
- package/ios/MinimalWebView+Scripts.swift +3 -3
- package/ios/MinimalWebView.swift +12 -11
- package/ios/NavigationRules.swift +1 -1
- package/ios/OriginRules.swift +3 -2
- package/ios/PlatformSettings.swift +14 -9
- package/ios/Recovery.swift +3 -3
- package/package.json +9 -4
- package/src/WebView.tsx +22 -19
- package/src/bridge/createBridge.ts +5 -3
- package/src/bridge/endpoint.ts +7 -3
- package/src/bridge/origins.ts +0 -1
- package/src/bridge/pageClient.generated.ts +1 -1
- package/src/bridge/pageClient.ts +1 -2
- package/src/defaultNavigationRules.ts +4 -5
- package/src/index.ts +1 -1
- package/src/platform.generated.ts +14 -15
- package/src/reactNativeWebViewDefaults.ts +2 -2
- package/src/reactNativeWebViewMessages.ts +8 -14
- package/src/refStore.ts +12 -11
- package/src/types.ts +328 -282
package/src/types.ts
CHANGED
|
@@ -13,6 +13,7 @@ import type {
|
|
|
13
13
|
|
|
14
14
|
/**
|
|
15
15
|
* What the WebView loads: a URL, or an HTML string.
|
|
16
|
+
* @see [Local files example](https://rasmuskard.github.io/react-native-minimal-webview/guides/examples/#local-files)
|
|
16
17
|
* @group WebView
|
|
17
18
|
*/
|
|
18
19
|
export type WebViewSource =
|
|
@@ -20,22 +21,24 @@ export type WebViewSource =
|
|
|
20
21
|
/**
|
|
21
22
|
* The URL to load.
|
|
22
23
|
*
|
|
23
|
-
* A `file://` URL
|
|
24
|
-
*
|
|
24
|
+
* A `file://` URL:
|
|
25
|
+
*
|
|
26
|
+
* - iOS: reads only within `readAccessRoot`.
|
|
27
|
+
* - Android: needs `android.settings.allowFileAccess`, which lets a `file:` page read any file the app can.
|
|
25
28
|
*/
|
|
26
29
|
uri: string;
|
|
27
|
-
/**
|
|
30
|
+
/**
|
|
31
|
+
* Sent when the core loads the `source`: its first load, and a reload (`reload()` or pull-to-refresh) or crash
|
|
32
|
+
* recovery that loads the `source` again. The page's later navigations don't send them.
|
|
33
|
+
*/
|
|
28
34
|
headers?: Record<string, string>;
|
|
29
35
|
/**
|
|
30
36
|
* Makes the request a POST with this form-urlencoded body.
|
|
31
37
|
*
|
|
32
|
-
* Its `Content-Type` is `application/x-www-form-urlencoded` unless iOS `headers` set one; Android
|
|
33
|
-
* `headers
|
|
38
|
+
* Its `Content-Type` is `application/x-www-form-urlencoded` unless iOS `headers` set one; Android ignores
|
|
39
|
+
* `headers` for a POST.
|
|
40
|
+
*
|
|
34
41
|
* `reload()` sends the POST again; {@link ProcessGoneEvent.recovered | crash recovery} doesn't.
|
|
35
|
-
* @example
|
|
36
|
-
* ```ts
|
|
37
|
-
* const source: WebViewSource = { uri: 'https://example.com/form', body: 'a=1&b=2' };
|
|
38
|
-
* ```
|
|
39
42
|
*/
|
|
40
43
|
body?: string;
|
|
41
44
|
/**
|
|
@@ -46,7 +49,6 @@ export type WebViewSource =
|
|
|
46
49
|
readAccessRoot?: string;
|
|
47
50
|
}
|
|
48
51
|
| {
|
|
49
|
-
/** The page's HTML. */
|
|
50
52
|
html: string;
|
|
51
53
|
/** The page's URL: its relative URLs resolve against it, and it has this origin. Without it, `about:blank`. */
|
|
52
54
|
baseUrl?: string;
|
|
@@ -67,15 +69,7 @@ export type NavigationAction = 'allow' | 'block' | 'external';
|
|
|
67
69
|
*
|
|
68
70
|
* Every field it sets must match; for a list, one matching entry is enough. A field left out matches anything; a flag
|
|
69
71
|
* set to `false` matches only the requests without it.
|
|
70
|
-
* @example
|
|
71
|
-
* ```ts
|
|
72
|
-
* const navigationRules: NavigationRule[] = [
|
|
73
|
-
* { query: ['gad_source', 'utm_term=google'], action: 'block' }, // gad_source with any value, utm_term only =google
|
|
74
|
-
* { scheme: ['tel', 'mailto'], action: 'external' },
|
|
75
|
-
* { host: ['*.example.com'], path: ['/checkout'], action: 'external' }, // shop.example.com/checkouts too
|
|
76
|
-
* { host: ['example.com', '*.example.com'], action: 'allow' }, // *.example.com alone skips example.com
|
|
77
|
-
* ];
|
|
78
|
-
* ```
|
|
72
|
+
* @see [Navigation rules example](https://rasmuskard.github.io/react-native-minimal-webview/guides/examples/#navigation-rules)
|
|
79
73
|
* @group Navigation
|
|
80
74
|
*/
|
|
81
75
|
export type NavigationRule = {
|
|
@@ -84,11 +78,12 @@ export type NavigationRule = {
|
|
|
84
78
|
/**
|
|
85
79
|
* Hosts: exact, or a `*.` suffix wildcard that matches subdomains only, not the domain itself.
|
|
86
80
|
*
|
|
87
|
-
* Case, port, userinfo and a trailing dot are ignored.
|
|
81
|
+
* Case, port, userinfo and a trailing dot are ignored. An internationalized domain matches only in its ASCII form:
|
|
82
|
+
* `xn--mnchen-3ya.de`, not `münchen.de`.
|
|
88
83
|
*/
|
|
89
84
|
host?: string[];
|
|
90
85
|
/**
|
|
91
|
-
*
|
|
86
|
+
* Prefixes of the percent-encoded URL path, not whole segments.
|
|
92
87
|
*
|
|
93
88
|
* A URL without an authority (`myapp:/open`) has the path `/`.
|
|
94
89
|
*/
|
|
@@ -110,12 +105,12 @@ export type NavigationRule = {
|
|
|
110
105
|
* An allowed one loads in place: there is never a second WebView, so no `window.opener` (a native hook that takes
|
|
111
106
|
* `createWebViewWith` on iOS or `onCreateWindow` on Android owns real popups).
|
|
112
107
|
*
|
|
113
|
-
*
|
|
114
|
-
* `javascript:` one's script, with the page's origin)
|
|
115
|
-
* the URL the page sends it to within 5 s,
|
|
116
|
-
*
|
|
117
|
-
*
|
|
118
|
-
*
|
|
108
|
+
* - Always blocked: one to `data:`, `blob:`, `javascript:`, `file:` or an `about:` URL other than `about:blank` (on
|
|
109
|
+
* Android, WebView may still run a `javascript:` one's script, with the page's origin).
|
|
110
|
+
* - Opened with no URL (`window.open('')`) or to `about:blank`: decided by the URL the page sends it to within 5 s,
|
|
111
|
+
* and dropped otherwise.
|
|
112
|
+
* - Opened without a user gesture: reaches the rules only with `javaScriptCanOpenWindowsAutomatically` on
|
|
113
|
+
* (`ios.preferences`, `android.settings`; off by default); otherwise WebKit or WebView drops it unreported.
|
|
119
114
|
*/
|
|
120
115
|
newWindow?: boolean;
|
|
121
116
|
/**
|
|
@@ -125,11 +120,13 @@ export type NavigationRule = {
|
|
|
125
120
|
* a tap that doesn't scroll, a click or a key press gives the page for up to 5 s. Any navigation the page starts in
|
|
126
121
|
* that time is true: a `location.href` change or `window.open` from a click handler, a timer's, a link a script
|
|
127
122
|
* clicks.
|
|
128
|
-
* - iOS: only a link activation (`<a>`, `<area>`, `target=_blank` too) within 1 s after a tap on the WebView
|
|
129
|
-
* scrolls and zooms nothing.
|
|
130
|
-
*
|
|
131
|
-
*
|
|
132
|
-
*
|
|
123
|
+
* - iOS: true only for a link activation (`<a>`, `<area>`, `target=_blank` too) within 1 s after a tap on the WebView
|
|
124
|
+
* that scrolls and zooms nothing. A link a script clicks within that second is true too.
|
|
125
|
+
* - False: a `location.href` change or `window.open`, from a click handler too, a link activated from a
|
|
126
|
+
* hardware keyboard, and a form submission, a tapped one and its redirect included.
|
|
127
|
+
* - A tapped link's redirect is true only within that second.
|
|
128
|
+
* - VoiceOver and Switch Control activate a link without a touch: while either runs, every link activation is
|
|
129
|
+
* true, a script's too.
|
|
133
130
|
*
|
|
134
131
|
* A redirect of a load the core starts itself (an allowed new window, and on Android an allowed `ask`) is never
|
|
135
132
|
* user-initiated.
|
|
@@ -176,7 +173,7 @@ export type NavigationEvent = NavigationRequest & {
|
|
|
176
173
|
};
|
|
177
174
|
|
|
178
175
|
/**
|
|
179
|
-
* A WebView's navigation state, as
|
|
176
|
+
* A WebView's navigation state, as the core reports it: from `useWebViewState` and `onNavigationStateChange`.
|
|
180
177
|
*
|
|
181
178
|
* While no WebView is mounted it is the initial state: `url` and `title` empty, `pendingUrl` and `outcome` null,
|
|
182
179
|
* `loading`, `canGoBack` and `canGoForward` false, `progress` 0.
|
|
@@ -193,10 +190,16 @@ export type NavigationState = {
|
|
|
193
190
|
/**
|
|
194
191
|
* A main-frame load in progress, which may still fail or be blocked.
|
|
195
192
|
*
|
|
196
|
-
* Iframes never change it. Always null on Android with
|
|
193
|
+
* Iframes never change it. Always null on Android with an Android System WebView older than 146.
|
|
197
194
|
*/
|
|
198
195
|
pendingUrl: string | null;
|
|
199
196
|
title: string;
|
|
197
|
+
/**
|
|
198
|
+
* A main-frame load is in progress.
|
|
199
|
+
*
|
|
200
|
+
* On Android with an Android System WebView older than 146, it goes true only when the load commits (its response
|
|
201
|
+
* arrives), and a load that never commits doesn't change it.
|
|
202
|
+
*/
|
|
200
203
|
loading: boolean;
|
|
201
204
|
/** From 0 to 1. */
|
|
202
205
|
progress: number;
|
|
@@ -205,13 +208,14 @@ export type NavigationState = {
|
|
|
205
208
|
/**
|
|
206
209
|
* How the last main-frame load ended; null while one is loading, and before the first.
|
|
207
210
|
*
|
|
211
|
+
* - `finished`: the page arrived, an HTTP error status (404) included: the site's page shows, and `onError` gets an
|
|
212
|
+
* `http` error.
|
|
208
213
|
* - `failed`: a network or SSL error, or a renderer crash, cut it off.
|
|
209
214
|
* - `cancelled`: it never showed a page (a stop before the response, a download, a 204, a redirect the rules blocked,
|
|
210
215
|
* a load a newer one replaced); a stop after the page arrived is `cancelled` on iOS but `finished` on Android, and
|
|
211
216
|
* a 204 is `finished` on iOS 17.
|
|
212
217
|
*
|
|
213
|
-
*
|
|
214
|
-
* with a WebView older than 146, a load that never commits changes nothing here.
|
|
218
|
+
* On Android with an Android System WebView older than 146, a load that never commits changes nothing here.
|
|
215
219
|
*/
|
|
216
220
|
outcome: 'finished' | 'failed' | 'cancelled' | null;
|
|
217
221
|
};
|
|
@@ -240,29 +244,35 @@ export type ProcessGoneEvent = {
|
|
|
240
244
|
*/
|
|
241
245
|
cause: 'crash' | 'memory' | 'unknown';
|
|
242
246
|
/**
|
|
243
|
-
* Whether the core reloads the page
|
|
244
|
-
* with the history restored unless the `source` page was on screen, and with the props applied but not what `call`
|
|
245
|
-
* set.
|
|
247
|
+
* Whether the core reloads the page after the crash.
|
|
246
248
|
*
|
|
247
|
-
*
|
|
248
|
-
*
|
|
249
|
-
*
|
|
249
|
+
* - iOS: in place.
|
|
250
|
+
* - Android: in a new WebView, once the view's window is visible. The history is restored unless the `source` page
|
|
251
|
+
* was on screen. The props are applied again, but not what `call` set.
|
|
252
|
+
*
|
|
253
|
+
* It is false when:
|
|
254
|
+
*
|
|
255
|
+
* - a POST `source` is on screen: as in a browser, it isn't sent again unasked;
|
|
256
|
+
* - more than 3 crashes happened in 60 s (counted for the whole app on Android), until the next
|
|
257
|
+
* {@link WebViewRef.reload | reload()} (on iOS also a `source` change).
|
|
258
|
+
*
|
|
259
|
+
* While false the view is blank. Leave `reload()` to the user, as a retry button: called from `onProcessGone` it
|
|
260
|
+
* sends the POST again, or starts the crash loop over.
|
|
261
|
+
* @see [Loading and error screens example](https://rasmuskard.github.io/react-native-minimal-webview/guides/examples/#loading-and-error-screens)
|
|
250
262
|
*/
|
|
251
263
|
recovered: boolean;
|
|
252
264
|
};
|
|
253
265
|
|
|
254
266
|
/**
|
|
255
267
|
* Runs at document start, before any page script and before the DOM is parsed.
|
|
256
|
-
* @example
|
|
257
|
-
* ```ts
|
|
258
|
-
* const script: InjectedScript = {
|
|
259
|
-
* code: "addEventListener('DOMContentLoaded', () => document.body.classList.add('in-app'));",
|
|
260
|
-
* origins: ['https://example.com'],
|
|
261
|
-
* };
|
|
262
|
-
* ```
|
|
268
|
+
* @see [Scripts example](https://rasmuskard.github.io/react-native-minimal-webview/guides/examples/#scripts)
|
|
263
269
|
* @group Scripts
|
|
264
270
|
*/
|
|
265
271
|
export type InjectedScript = {
|
|
272
|
+
/**
|
|
273
|
+
* JavaScript source, run as statements; {@link InjectedScript.origins | origins} decides how its top-level names
|
|
274
|
+
* are scoped.
|
|
275
|
+
*/
|
|
266
276
|
code: string;
|
|
267
277
|
/**
|
|
268
278
|
* Runs it in every frame, iframes included.
|
|
@@ -270,10 +280,11 @@ export type InjectedScript = {
|
|
|
270
280
|
*/
|
|
271
281
|
allFrames?: boolean;
|
|
272
282
|
/**
|
|
273
|
-
* The origins whose frames run it, in the syntax of {@link BridgeOptions.allowedOrigins}.
|
|
274
|
-
*
|
|
275
|
-
*
|
|
276
|
-
*
|
|
283
|
+
* The origins whose frames run it, in the syntax of {@link BridgeOptions.allowedOrigins}.
|
|
284
|
+
*
|
|
285
|
+
* - Each frame is matched by its own `location.origin`, so a listed page's iframes from other origins don't run it.
|
|
286
|
+
* about:blank and srcdoc frames have their parent's origin.
|
|
287
|
+
* - `'*'` matches every origin, opaque ones (`data:`, sandboxed frames) and `file:` included. `[]` matches none.
|
|
277
288
|
*
|
|
278
289
|
* Without `'*'` in the list, the code runs inside a function: its top-level `let`, `const`, `class`, `function` and
|
|
279
290
|
* `var` stay local to it, so put what the page should see on `window`. An invalid rule throws when the WebView
|
|
@@ -306,20 +317,20 @@ export type BridgeHandler<Params = unknown, Result = unknown> = (
|
|
|
306
317
|
* What crosses a bridge, for `createBridge<Schema>`: the methods each side handles, which the other side calls, and the
|
|
307
318
|
* events.
|
|
308
319
|
*
|
|
309
|
-
* With a schema
|
|
310
|
-
*
|
|
311
|
-
* `
|
|
312
|
-
*
|
|
313
|
-
*
|
|
314
|
-
*
|
|
315
|
-
*
|
|
316
|
-
* type
|
|
317
|
-
*
|
|
318
|
-
*
|
|
319
|
-
*
|
|
320
|
-
*
|
|
321
|
-
*
|
|
322
|
-
*
|
|
320
|
+
* With a schema:
|
|
321
|
+
*
|
|
322
|
+
* - `handle` takes only the `reactNative` methods and `call` only the `page` ones. `emit` and `on` take only the
|
|
323
|
+
* schema's events. Another name doesn't compile.
|
|
324
|
+
* - `params` or a payload is required where its type doesn't allow `undefined`.
|
|
325
|
+
* - A method's `params` and `result` are left out when it has none.
|
|
326
|
+
* - Every key is required: `{}` for a side that handles nothing.
|
|
327
|
+
* - The method and event maps are `type`s or written inline, not `interfaces`: an interface has no index signature, so
|
|
328
|
+
* it doesn't satisfy `Record`.
|
|
329
|
+
*
|
|
330
|
+
* Params, results and payloads cross as JSON: a `Date` arrives as its ISO string, a `Map` or `Set` as `{}`, `NaN`
|
|
331
|
+
* as `null`, and `undefined` properties and functions are left out. A handler's result that JSON can't encode (a
|
|
332
|
+
* cycle, a `BigInt`) rejects the call with `handler_error`.
|
|
333
|
+
* @see [Bridge example](https://rasmuskard.github.io/react-native-minimal-webview/guides/examples/#the-bridge)
|
|
323
334
|
* @group Bridge
|
|
324
335
|
*/
|
|
325
336
|
export type BridgeSchema = {
|
|
@@ -333,12 +344,10 @@ export type BridgeSchema = {
|
|
|
333
344
|
|
|
334
345
|
type ParamsOf<Method> = 'params' extends keyof Method ? Method['params' & keyof Method] : undefined;
|
|
335
346
|
type ResultOf<Method> = 'result' extends keyof Method ? Method['result' & keyof Method] : unknown;
|
|
336
|
-
/** `call`'s arguments after the method: `params`, required unless they can be `undefined`, then the options. */
|
|
337
347
|
type CallArgs<Method> =
|
|
338
348
|
undefined extends ParamsOf<Method>
|
|
339
349
|
? [params?: ParamsOf<Method>, options?: { timeoutMs?: number }]
|
|
340
350
|
: [params: ParamsOf<Method>, options?: { timeoutMs?: number }];
|
|
341
|
-
/** `emit`'s argument after the event: the payload, required unless it can be `undefined`. */
|
|
342
351
|
type PayloadArg<Payload> = undefined extends Payload ? [payload?: Payload] : [payload: Payload];
|
|
343
352
|
|
|
344
353
|
/**
|
|
@@ -347,12 +356,15 @@ type PayloadArg<Payload> = undefined extends Payload ? [payload?: Payload] : [pa
|
|
|
347
356
|
* Attach it with the `bridge` prop. Handlers and listeners belong to the bridge, not to a WebView: they stay across
|
|
348
357
|
* unmounts. Messages have no size limit.
|
|
349
358
|
*
|
|
350
|
-
*
|
|
351
|
-
*
|
|
352
|
-
*
|
|
359
|
+
* Each call or event the bridge sends:
|
|
360
|
+
*
|
|
361
|
+
* - waits for the page's `DOMContentLoaded`, so the handlers and listeners of the page's synchronous and deferred
|
|
362
|
+
* scripts are in place;
|
|
363
|
+
* - never reaches a later page, even one on the same origin;
|
|
364
|
+
* - waits the same way while no WebView is mounted with the bridge. A call's timeout runs meanwhile, and only the
|
|
365
|
+
* latest 1000 are kept: an older call rejects with `unavailable`.
|
|
353
366
|
*
|
|
354
|
-
*
|
|
355
|
-
* meanwhile, and only the latest 1000 are kept: an older call rejects with `unavailable`.
|
|
367
|
+
* The page's own calls don't wait: one made before React Native has registered its method rejects with `not_found`.
|
|
356
368
|
* Unmounting rejects the calls in flight with `navigated`.
|
|
357
369
|
*
|
|
358
370
|
* The page's `window.nativeBridge` has the same four methods, from its side: {@link PageBridge}.
|
|
@@ -373,7 +385,7 @@ export type Bridge<Schema extends BridgeSchema = BridgeSchema> = {
|
|
|
373
385
|
* Calls a method of the schema's `page`, which the page registered with `nativeBridge.handle`.
|
|
374
386
|
*
|
|
375
387
|
* Rejects with a {@link CodedError}: `timeout`, `not_found`, `handler_error`, `navigated` or `unavailable`.
|
|
376
|
-
* `timeoutMs` overrides the bridge's for this call
|
|
388
|
+
* `timeoutMs` overrides the bridge's for this call; a negative or `NaN` one rejects with a plain `RangeError`.
|
|
377
389
|
*/
|
|
378
390
|
call<M extends keyof Schema['page'] & string>(
|
|
379
391
|
method: M,
|
|
@@ -406,35 +418,33 @@ export type Bridge<Schema extends BridgeSchema = BridgeSchema> = {
|
|
|
406
418
|
* from the page's side.
|
|
407
419
|
*
|
|
408
420
|
* `handle` takes the schema's `page` methods, and its handler gets the params only (no sender), `call` takes the
|
|
409
|
-
* `reactNative` ones, and `emit` and `on` take the `events`.
|
|
410
|
-
* `not_found`, `handler_error`, or `navigated` when the page comes back from the back-forward cache. Its timeout
|
|
411
|
-
* defaults to the bridge's `timeoutMs`, and a `timeoutMs` that isn't 0 or more rejects with a plain `RangeError`.
|
|
421
|
+
* `reactNative` ones, and `emit` and `on` take the `events`.
|
|
412
422
|
*
|
|
413
423
|
* `window.nativeBridge` exists only in the main frame of a page on one of the bridge's `allowedOrigins`, so a page
|
|
414
424
|
* declares it optional. The page's project needs this package as a dev dependency for the type, which is a type-only
|
|
415
425
|
* import and costs nothing at runtime, and must share or copy the schema type.
|
|
416
|
-
* @example
|
|
417
|
-
* ```ts
|
|
418
|
-
* import type { PageBridge } from 'react-native-minimal-webview';
|
|
419
|
-
*
|
|
420
|
-
* declare global {
|
|
421
|
-
* interface Window {
|
|
422
|
-
* nativeBridge?: PageBridge<ShopBridge>;
|
|
423
|
-
* }
|
|
424
|
-
* }
|
|
425
|
-
* ```
|
|
426
|
-
* @see [Bridge example](https://rasmuskard.github.io/react-native-minimal-webview/guides/examples/#in-the-page)
|
|
426
|
+
* @see [In the page example](https://rasmuskard.github.io/react-native-minimal-webview/guides/examples/#in-the-page)
|
|
427
427
|
* @group Bridge
|
|
428
428
|
*/
|
|
429
429
|
export type PageBridge<Schema extends BridgeSchema = BridgeSchema> = {
|
|
430
|
-
/**
|
|
430
|
+
/**
|
|
431
|
+
* Answers `bridge.call(method, params)` from React Native, for a method of the schema's `page`.
|
|
432
|
+
*
|
|
433
|
+
* One handler per method: a later one replaces it. Returns an unsubscribe function, which removes only this handler.
|
|
434
|
+
*/
|
|
431
435
|
handle<M extends keyof Schema['page'] & string>(
|
|
432
436
|
method: M,
|
|
433
437
|
handler: (
|
|
434
438
|
params: ParamsOf<Schema['page'][M]>
|
|
435
439
|
) => ResultOf<Schema['page'][M]> | Promise<ResultOf<Schema['page'][M]>>
|
|
436
440
|
): () => void;
|
|
437
|
-
/**
|
|
441
|
+
/**
|
|
442
|
+
* Calls a method of the schema's `reactNative`, which React Native registered with `bridge.handle`.
|
|
443
|
+
*
|
|
444
|
+
* Rejects with a {@link CodedError}: `timeout`, `not_found`, `handler_error`, or `navigated` when the page comes back
|
|
445
|
+
* from the back-forward cache. `timeoutMs` in the options overrides the bridge's for this call; a negative or `NaN`
|
|
446
|
+
* one rejects with a plain `RangeError`.
|
|
447
|
+
*/
|
|
438
448
|
call<M extends keyof Schema['reactNative'] & string>(
|
|
439
449
|
method: M,
|
|
440
450
|
...args: CallArgs<Schema['reactNative'][M]>
|
|
@@ -457,15 +467,17 @@ export type PageBridge<Schema extends BridgeSchema = BridgeSchema> = {
|
|
|
457
467
|
*/
|
|
458
468
|
export type BridgeOptions = {
|
|
459
469
|
/**
|
|
460
|
-
* The origins whose pages get `window.nativeBridge`, main frame only
|
|
461
|
-
*
|
|
470
|
+
* The origins whose pages get `window.nativeBridge`, main frame only.
|
|
471
|
+
*
|
|
472
|
+
* Each is one of:
|
|
473
|
+
*
|
|
474
|
+
* - an origin, `https://example.com`;
|
|
475
|
+
* - a wildcard for subdomains only, not the domain itself, `https://*.example.com`;
|
|
476
|
+
* - an IP literal, `http://[::1]:8080`;
|
|
477
|
+
* - `'*'`, any origin, opaque ones too.
|
|
462
478
|
*
|
|
463
|
-
*
|
|
464
|
-
* means 80 or 443.
|
|
465
|
-
* @example
|
|
466
|
-
* ```ts
|
|
467
|
-
* createBridge({ allowedOrigins: ['https://example.com', 'https://*.example.com', 'http://[::1]:8080'] });
|
|
468
|
-
* ```
|
|
479
|
+
* Except `'*'`, a rule is http or https, with an optional port, no path and an ASCII (punycode) host. Case is
|
|
480
|
+
* ignored, and a missing port means 80 or 443.
|
|
469
481
|
*/
|
|
470
482
|
allowedOrigins: string[];
|
|
471
483
|
/**
|
|
@@ -482,7 +494,7 @@ export type BridgeOptions = {
|
|
|
482
494
|
* @group Page requests
|
|
483
495
|
*/
|
|
484
496
|
export type FileRequest = {
|
|
485
|
-
/** Its `accept` list
|
|
497
|
+
/** Its `accept` list, lowercased and without invalid entries: MIME types and extensions (`.pdf`). */
|
|
486
498
|
accept: string[];
|
|
487
499
|
/** Its `multiple` attribute. */
|
|
488
500
|
multiple: boolean;
|
|
@@ -495,14 +507,13 @@ export type FileRequest = {
|
|
|
495
507
|
*
|
|
496
508
|
* `geolocation` and `protectedMedia` (the device id DRM playback needs, Widevine) are Android only: on iOS, location
|
|
497
509
|
* always shows WebKit's own prompt, and FairPlay asks nothing.
|
|
510
|
+
*
|
|
511
|
+
* Android never grants another resource (MIDI sysex): a request for only those is denied without asking.
|
|
498
512
|
* @group Page requests
|
|
499
513
|
*/
|
|
500
514
|
export type PermissionResource = 'camera' | 'microphone' | 'geolocation' | 'protectedMedia';
|
|
501
515
|
/**
|
|
502
516
|
* A page's permission request, for `onPermissionRequest`.
|
|
503
|
-
*
|
|
504
|
-
* Only the main frame asks (on Android, which doesn't name the frame, any frame of the top page's origin); other
|
|
505
|
-
* frames, and a page with an opaque origin (`data:`, a sandboxed frame), are denied without asking.
|
|
506
517
|
* @group Page requests
|
|
507
518
|
*/
|
|
508
519
|
export type PermissionRequest = {
|
|
@@ -517,10 +528,13 @@ export type PermissionRequest = {
|
|
|
517
528
|
*/
|
|
518
529
|
export type Download = {
|
|
519
530
|
ok: true;
|
|
520
|
-
/**
|
|
531
|
+
/**
|
|
532
|
+
* A `file://` in the app's cache (iOS: the temporary directory), which the core never deletes but the OS may: move
|
|
533
|
+
* a file the app keeps.
|
|
534
|
+
*/
|
|
521
535
|
uri: string;
|
|
522
536
|
/**
|
|
523
|
-
* A plain file name
|
|
537
|
+
* A plain file name without a path. The page chose it, like the content and `mimeType`, so don't open the file as
|
|
524
538
|
* trusted.
|
|
525
539
|
*/
|
|
526
540
|
filename: string;
|
|
@@ -534,7 +548,7 @@ export type Download = {
|
|
|
534
548
|
*
|
|
535
549
|
* - `network`: connecting or reading the response failed, or a redirect was refused.
|
|
536
550
|
* - `http`: the response had an error status (Android only: iOS saves what the server sent).
|
|
537
|
-
* - `data
|
|
551
|
+
* - `data` (the content): a bad `data:` or `blob:` URL, the page not reading its blob, an unsupported scheme, or
|
|
538
552
|
* (Android) a file above 100 MB or a `blob:` URL the main frame can't read (a cross-origin iframe's, or one already
|
|
539
553
|
* revoked).
|
|
540
554
|
* @group Page requests
|
|
@@ -544,6 +558,7 @@ export type DownloadFailure =
|
|
|
544
558
|
/** Tells it from a {@link Download}. */
|
|
545
559
|
ok: false;
|
|
546
560
|
kind: 'network' | 'data';
|
|
561
|
+
/** Empty on iOS when the download failed before its response came. */
|
|
547
562
|
filename: string;
|
|
548
563
|
/** As in {@link Download}. */
|
|
549
564
|
url: string | null;
|
|
@@ -558,7 +573,7 @@ export type DownloadFailure =
|
|
|
558
573
|
export type DownloadResult = Download | DownloadFailure;
|
|
559
574
|
|
|
560
575
|
/**
|
|
561
|
-
*
|
|
576
|
+
* A value for a platform setting. It must fit the property's or setter's type.
|
|
562
577
|
* @group Platform settings
|
|
563
578
|
*/
|
|
564
579
|
export type SettingValue =
|
|
@@ -598,57 +613,60 @@ export type IOSPrivateSettingKeys = {
|
|
|
598
613
|
/**
|
|
599
614
|
* WebKit settings by Objective-C property name.
|
|
600
615
|
*
|
|
601
|
-
* Any public property works, including
|
|
602
|
-
*
|
|
603
|
-
*
|
|
604
|
-
*
|
|
616
|
+
* Any public property works, including a newer SDK's (under a root's `other`). Keys the SDK headers list appear in
|
|
617
|
+
* autocomplete, with their `@since`, as do the {@link IOSPrivateSettingKeys}.
|
|
618
|
+
*
|
|
619
|
+
* A value must fit the property's type:
|
|
620
|
+
*
|
|
621
|
+
* - An enum or option set: its raw value, from {@link IOSConstants}.
|
|
622
|
+
* - A struct: an object.
|
|
623
|
+
* - A `UIColor`: `#rrggbb` or `#rrggbbaa`.
|
|
624
|
+
* - An `NSURL`: a string.
|
|
625
|
+
* - `websiteDataStore`: `'default'` or `'nonPersistent'`.
|
|
605
626
|
*
|
|
606
627
|
* A key that doesn't fit, a private (`_`) one, or one the device's iOS lacks (its `@since` is newer) is skipped with a
|
|
607
|
-
* warning; nothing here can crash the app.
|
|
608
|
-
* `webView.opaque
|
|
628
|
+
* warning; nothing here can crash the app. A property UIKit declares without runtime metadata, such as
|
|
629
|
+
* `webView.opaque`, is skipped the same way: set it with `call('webView.setOpaque:', [false])`.
|
|
609
630
|
*
|
|
610
|
-
* A root's default keys are the package's, and yours go over them
|
|
611
|
-
* default
|
|
612
|
-
* {@link WebViewRef.get | get} and {@link WebViewRef.call | call} take these roots, plus `websiteDataStore` and
|
|
613
|
-
* `httpCookieStore`.
|
|
631
|
+
* A root's default keys are the package's, and yours go over them. A key the package doesn't set keeps WebKit's
|
|
632
|
+
* default; a key you remove goes back to the value it had before you first set it.
|
|
614
633
|
*
|
|
615
634
|
* WebKit has no mixed-content setting: it applies its own policy.
|
|
616
|
-
* @example
|
|
617
|
-
* ```tsx
|
|
618
|
-
* <WebView
|
|
619
|
-
* source={{ uri: 'https://example.com' }}
|
|
620
|
-
* ios={{
|
|
621
|
-
* configuration: { dataDetectorTypes: IOSConstants.DataDetectorTypes.link },
|
|
622
|
-
* scrollView: { bounces: false, contentInset: { top: 0, left: 0, bottom: 80, right: 0 } },
|
|
623
|
-
* }}
|
|
624
|
-
* />
|
|
625
|
-
* ```
|
|
626
635
|
* @ios
|
|
627
|
-
* @see [
|
|
636
|
+
* @see [Use a platform API](https://rasmuskard.github.io/react-native-minimal-webview/guides/platform-apis/)
|
|
628
637
|
* @group Platform settings
|
|
629
638
|
*/
|
|
630
639
|
export type IOSSettings = {
|
|
631
640
|
/**
|
|
632
|
-
* `WKWebViewConfiguration
|
|
633
|
-
*
|
|
641
|
+
* [`WKWebViewConfiguration`](https://developer.apple.com/documentation/webkit/wkwebviewconfiguration): read once,
|
|
642
|
+
* when the WKWebView is created; a change recreates the WebView (the page reloads and the navigation state starts
|
|
643
|
+
* over). It is compared by value, so an inline object with the same keys and values is no change. It is a copy, so
|
|
644
|
+
* `call` on it changes nothing.
|
|
634
645
|
* @default `{ allowsInlineMediaPlayback: true }`
|
|
635
646
|
*/
|
|
636
647
|
configuration?: SettingsRoot<
|
|
637
648
|
IOSSettingKeys['configuration'] & IOSPrivateSettingKeys['configuration']
|
|
638
649
|
>;
|
|
639
|
-
/**
|
|
650
|
+
/**
|
|
651
|
+
* [`WKPreferences`](https://developer.apple.com/documentation/webkit/wkpreferences) (`configuration.preferences`),
|
|
652
|
+
* live.
|
|
653
|
+
*/
|
|
640
654
|
preferences?: SettingsRoot<IOSSettingKeys['preferences'] & IOSPrivateSettingKeys['preferences']>;
|
|
641
|
-
/**
|
|
655
|
+
/**
|
|
656
|
+
* [`WKWebpagePreferences`](https://developer.apple.com/documentation/webkit/wkwebpagepreferences)
|
|
657
|
+
* (`configuration.defaultWebpagePreferences`), live from the next navigation.
|
|
658
|
+
*/
|
|
642
659
|
webpagePreferences?: SettingsRoot<IOSSettingKeys['webpagePreferences']>;
|
|
643
660
|
/**
|
|
644
|
-
* The `WKWebView
|
|
661
|
+
* The [`WKWebView`](https://developer.apple.com/documentation/webkit/wkwebview), live.
|
|
645
662
|
* @default `{ inspectable: __DEV__ }`
|
|
663
|
+
* @see [Debugging the page example](https://rasmuskard.github.io/react-native-minimal-webview/guides/examples/#debugging-the-page)
|
|
646
664
|
*/
|
|
647
665
|
webView?: SettingsRoot<IOSSettingKeys['webView']>;
|
|
648
666
|
/**
|
|
649
|
-
*
|
|
667
|
+
* The WKWebView's [`UIScrollView`](https://developer.apple.com/documentation/uikit/uiscrollview), live.
|
|
650
668
|
*
|
|
651
|
-
* `directionalLockEnabled` is on by default
|
|
669
|
+
* `directionalLockEnabled` is on by default.
|
|
652
670
|
*/
|
|
653
671
|
scrollView?: SettingsRoot<IOSSettingKeys['scrollView']>;
|
|
654
672
|
};
|
|
@@ -656,47 +674,43 @@ export type IOSSettings = {
|
|
|
656
674
|
/**
|
|
657
675
|
* Android settings by setter name without `set`.
|
|
658
676
|
*
|
|
659
|
-
* Any public setter works, including
|
|
660
|
-
*
|
|
677
|
+
* Any public setter works, including a newer SDK's or androidx.webkit's (under a root's `other`). Keys the SDK lists
|
|
678
|
+
* appear in autocomplete, with their `@since`; the constants are in {@link AndroidConstants}. An `int` setter takes a
|
|
661
679
|
* number up to `0xFFFFFFFF`, truncated, so an ARGB color such as `0xFF202020` works.
|
|
662
680
|
*
|
|
663
681
|
* A key with no public setter for the value's type, or one this device's WebView lacks, is skipped with a warning;
|
|
664
|
-
* nothing here can crash the app.
|
|
665
|
-
*
|
|
666
|
-
*
|
|
667
|
-
*
|
|
682
|
+
* nothing here can crash the app. Each key is set on the current WebView as soon as it changes, and again on a new one
|
|
683
|
+
* after a renderer crash.
|
|
684
|
+
*
|
|
685
|
+
* A root's default keys are the package's, and yours go over them. A key the package doesn't set, such as
|
|
686
|
+
* `overScrollMode`, keeps the platform's default.
|
|
668
687
|
*
|
|
669
|
-
*
|
|
670
|
-
* `
|
|
671
|
-
* without `get` or `is`.
|
|
672
|
-
* @example
|
|
673
|
-
* ```tsx
|
|
674
|
-
* <WebView
|
|
675
|
-
* source={{ uri: 'https://example.com' }}
|
|
676
|
-
* android={{
|
|
677
|
-
* settings: { textZoom: 120, cacheMode: AndroidConstants.WebSettings.LOAD_NO_CACHE },
|
|
678
|
-
* webView: { overScrollMode: 2 },
|
|
679
|
-
* }}
|
|
680
|
-
* />
|
|
681
|
-
* ```
|
|
688
|
+
* A key you remove goes back to the value it had before you first set it. One with no getter, such as
|
|
689
|
+
* `geolocationEnabled`, keeps its value until the WebView is recreated, with a warning.
|
|
682
690
|
* @android
|
|
683
|
-
* @see [
|
|
691
|
+
* @see [Use a platform API](https://rasmuskard.github.io/react-native-minimal-webview/guides/platform-apis/)
|
|
684
692
|
* @group Platform settings
|
|
685
693
|
*/
|
|
686
694
|
export type AndroidSettings = {
|
|
687
695
|
/**
|
|
688
|
-
* `WebSettings` setters, then static
|
|
696
|
+
* [`WebSettings`](https://developer.android.com/reference/android/webkit/WebSettings) setters, then static
|
|
697
|
+
* [`WebSettingsCompat`](https://developer.android.com/reference/androidx/webkit/WebSettingsCompat) ones.
|
|
689
698
|
*
|
|
690
|
-
* Each new WebView starts with
|
|
691
|
-
*
|
|
692
|
-
*
|
|
693
|
-
*
|
|
694
|
-
*
|
|
699
|
+
* Each new WebView starts with:
|
|
700
|
+
*
|
|
701
|
+
* - On: `javaScriptEnabled`, `domStorageEnabled`, `supportMultipleWindows`, `builtInZoomControls`,
|
|
702
|
+
* `useWideViewPort`, `loadWithOverviewMode` and, with Android System WebView 146 and newer,
|
|
703
|
+
* `backForwardCacheEnabled`.
|
|
704
|
+
* - Off: `allowFileAccess`, `allowContentAccess`, `displayZoomControls` and `downloadFaviconsEnabled`.
|
|
705
|
+
* - `mixedContentMode`: `MIXED_CONTENT_NEVER_ALLOW`.
|
|
706
|
+
*
|
|
707
|
+
* `userAgentString: null` is WebView's default user agent.
|
|
695
708
|
*/
|
|
696
709
|
settings?: SettingsRoot<AndroidSettingKeys['settings']>;
|
|
697
710
|
/**
|
|
698
|
-
* `WebView` setters (static and inherited `View`
|
|
699
|
-
* `
|
|
711
|
+
* [`WebView`](https://developer.android.com/reference/android/webkit/WebView) setters (static and inherited `View`
|
|
712
|
+
* ones too), then [`WebViewCompat`](https://developer.android.com/reference/androidx/webkit/WebViewCompat) ones,
|
|
713
|
+
* then `CookieManager`'s `acceptThirdPartyCookies`.
|
|
700
714
|
*
|
|
701
715
|
* `acceptThirdPartyCookies` is on by default, as react-native-webview has it. `webContentsDebuggingEnabled` is
|
|
702
716
|
* refused: it is process-wide, set with {@link AndroidWebView.setWebContentsDebuggingEnabled}.
|
|
@@ -708,10 +722,6 @@ export type AndroidSettings = {
|
|
|
708
722
|
* An event a native hook sent with `emit` or `ask`.
|
|
709
723
|
* @typeParam N - The event's name, to type one hook's events.
|
|
710
724
|
* @typeParam P - Its payload.
|
|
711
|
-
* @example
|
|
712
|
-
* ```ts
|
|
713
|
-
* type PageLoaded = HookEvent<'pageLoaded', { count: number }>;
|
|
714
|
-
* ```
|
|
715
725
|
* @group Native hooks
|
|
716
726
|
*/
|
|
717
727
|
export type HookEvent<N extends string = string, P = Record<string, unknown>> = {
|
|
@@ -746,12 +756,12 @@ export type HookExtension<E extends HookEvent = HookEvent> = {
|
|
|
746
756
|
*/
|
|
747
757
|
options?: unknown;
|
|
748
758
|
/**
|
|
749
|
-
* Each of the hook's events: it goes to the extension with the hook's key
|
|
750
|
-
*
|
|
751
|
-
*
|
|
752
|
-
*
|
|
759
|
+
* Each of the hook's events: it goes to the extension with the hook's key, and one no extension owns is dropped. For
|
|
760
|
+
* an `ask`, the return value (a promise is awaited) is the answer, and `undefined`, or a value JSON can't encode,
|
|
761
|
+
* answers null. `signal` is set only for an `ask`, and aborts when the core stops waiting for the answer: an ask has
|
|
762
|
+
* no timeout, but one still open when the page goes away is answered null.
|
|
753
763
|
*
|
|
754
|
-
* The latest `onEvent` always takes the events: a render with new handlers sends
|
|
764
|
+
* The latest `onEvent` always takes the events: a render with new handlers sends the core nothing.
|
|
755
765
|
*/
|
|
756
766
|
onEvent?(event: E, signal?: AbortSignal): unknown;
|
|
757
767
|
};
|
|
@@ -767,20 +777,31 @@ export type FullscreenChangeEvent = { active: boolean };
|
|
|
767
777
|
* Why a ref method or a bridge call rejected. Each code means the same on every method that rejects with it.
|
|
768
778
|
*
|
|
769
779
|
* - `timeout`: a bridge call got no answer in time.
|
|
770
|
-
* - `not_found`: nothing by that name answers
|
|
771
|
-
*
|
|
772
|
-
*
|
|
780
|
+
* - `not_found`: nothing by that name answers.
|
|
781
|
+
* - A bridge call: no handler for the method.
|
|
782
|
+
* - A `hook` call: no attached hook `name` that is on and handles `method`.
|
|
783
|
+
* - `get` and `call`: a malformed path, or no such root, key, method or selector, including one this OS or WebView
|
|
784
|
+
* version lacks. On Android a method that takes these arguments doesn't exist; on iOS a private `_` key of `get`
|
|
785
|
+
* is not found.
|
|
773
786
|
* - `handler_error`: the handler of a bridge call, on either side, or of a `hook` call failed; the `message` is its
|
|
774
787
|
* error's.
|
|
775
|
-
* - `script_error`: `evaluate`'s script threw, rejected or didn't parse
|
|
776
|
-
*
|
|
777
|
-
*
|
|
778
|
-
*
|
|
788
|
+
* - `script_error`: `evaluate`'s script threw, rejected or didn't parse, or, on Android, didn't run because the page
|
|
789
|
+
* loaded before the core was ready for it.
|
|
790
|
+
* - `native_error`: the platform refused or failed the call.
|
|
791
|
+
* - A member the core owns, or a private selector for an iOS `call`.
|
|
792
|
+
* - A key `get` can't read.
|
|
793
|
+
* - Wrong arguments (iOS).
|
|
794
|
+
* - A completion handler `call` can't await.
|
|
795
|
+
* - A native exception or `NSError`.
|
|
796
|
+
* - A result JSON can't carry (`NaN`).
|
|
779
797
|
* - `navigated`: the page or the WebView went away while the call was pending (a navigation, a crash, an unmount), so
|
|
780
798
|
* it may have run: retry only what is safe to repeat.
|
|
781
|
-
* - `unavailable`: the call didn't run
|
|
782
|
-
*
|
|
783
|
-
*
|
|
799
|
+
* - `unavailable`: the call didn't run.
|
|
800
|
+
* - The WebView is gone or not mounted yet.
|
|
801
|
+
* - The WebView is being rebuilt after its renderer died (Android).
|
|
802
|
+
* - The bridge's queue was full and dropped the call.
|
|
803
|
+
* - The WebView lacks the feature: the method's API reference entry names the Android System WebView it needs, or
|
|
804
|
+
* a compat method this WebView doesn't support.
|
|
784
805
|
*
|
|
785
806
|
* A programming error, such as an argument of the wrong type, can reject with a plain `TypeError` instead.
|
|
786
807
|
* @group WebView
|
|
@@ -807,25 +828,34 @@ export type CodedError = Error & { code: ErrorCode };
|
|
|
807
828
|
* events) go to the native view.
|
|
808
829
|
*
|
|
809
830
|
* Every `on…` callback is read when its event or request comes, so adding, changing or removing one applies to the
|
|
810
|
-
* next, and a request without one gets the default described on its prop.
|
|
811
|
-
*
|
|
812
|
-
*
|
|
813
|
-
*
|
|
831
|
+
* next, and a request without one gets the default described on its prop.
|
|
832
|
+
*
|
|
833
|
+
* One that answers a request and throws (or rejects) is logged with `console.error` and gives the refusing answer:
|
|
834
|
+
*
|
|
835
|
+
* - `onNavigationRequest`: `block`
|
|
836
|
+
* - `onOpenExternal`: null (the core opens nothing)
|
|
837
|
+
* - `onFileRequest`: cancel
|
|
838
|
+
* - `onPermissionRequest`: deny
|
|
839
|
+
* - an extension's `onEvent`: null
|
|
814
840
|
*
|
|
815
|
-
* The `signal` such a callback gets aborts when
|
|
841
|
+
* The `signal` such a callback gets aborts when the core stops waiting for its answer (the page moved on, crashed or
|
|
816
842
|
* unmounted), and a late answer is dropped.
|
|
817
843
|
*
|
|
818
|
-
* JS dialogs (`alert`, `confirm`, `prompt`) and HTTP auth have no prop.
|
|
819
|
-
*
|
|
820
|
-
*
|
|
821
|
-
*
|
|
822
|
-
*
|
|
844
|
+
* JS dialogs (`alert`, `confirm`, `prompt`) and HTTP auth have no prop.
|
|
845
|
+
*
|
|
846
|
+
* - iOS dialogs: a `UIAlertController` titled with the frame's host, or `JavaScript` for a frame without one
|
|
847
|
+
* (`data:`, sandboxed, `file:`). One shows at a time; one that comes while another shows is cancelled.
|
|
848
|
+
* - Android dialogs: WebView's own.
|
|
849
|
+
* - HTTP auth: cancelled on Android. On iOS WebKit's default handling applies, so without a stored credential the
|
|
850
|
+
* site's 401 page shows.
|
|
851
|
+
*
|
|
852
|
+
* `dialogs` and `basicAuthCredential` of `@react-native-minimal-webview/extensions` take them over, or a native hook
|
|
853
|
+
* does.
|
|
854
|
+
* @sortStrategy source-order
|
|
823
855
|
* @group WebView
|
|
824
856
|
*/
|
|
825
857
|
export interface WebViewProps extends Omit<ViewProps, 'children'> {
|
|
826
858
|
/**
|
|
827
|
-
* What to load.
|
|
828
|
-
*
|
|
829
859
|
* A new `source` loads at once, unless it equals the loaded one field by field: that loads nothing, even after the
|
|
830
860
|
* page navigated away.
|
|
831
861
|
*/
|
|
@@ -854,8 +884,9 @@ export interface WebViewProps extends Omit<ViewProps, 'children'> {
|
|
|
854
884
|
* Scripts to run at document start, before the page's own, in the frames picked by each script's `allFrames` and
|
|
855
885
|
* `origins`.
|
|
856
886
|
*
|
|
857
|
-
* A change applies from the next navigation. On Android with
|
|
858
|
-
* so, once per process).
|
|
887
|
+
* A change applies from the next navigation. On Android with an Android System WebView older than 101 they don't run
|
|
888
|
+
* (a warning says so, once per process).
|
|
889
|
+
* @see [Scripts example](https://rasmuskard.github.io/react-native-minimal-webview/guides/examples/#scripts)
|
|
859
890
|
*/
|
|
860
891
|
injectedScripts?: InjectedScript[];
|
|
861
892
|
/**
|
|
@@ -863,37 +894,28 @@ export interface WebViewProps extends Omit<ViewProps, 'children'> {
|
|
|
863
894
|
* and with no match the navigation is blocked.
|
|
864
895
|
*
|
|
865
896
|
* Unset, the rules are {@link defaultNavigationRules}; `[]` is no rules, so every navigation they decide is blocked.
|
|
897
|
+
* A change applies from the next navigation.
|
|
866
898
|
*
|
|
867
|
-
*
|
|
868
|
-
* that isn't a boolean) or no valid `action`, blocks every navigation that reaches it, whatever it was meant to match
|
|
869
|
-
* or do: native would otherwise skip the key or flag and match more than intended, and so could allow more than a
|
|
870
|
-
* correct rule would. In development a warning names the rule's index and the problem, once. The rules before it
|
|
871
|
-
* decide as usual; one that isn't an array is `[]`.
|
|
872
|
-
*
|
|
873
|
-
* `about:`, `data:` and `javascript:` always load in place. A `blob:` URL is decided as the origin it carries:
|
|
874
|
-
* `blob:https://example.com/…` as `https://example.com/`, and one with an opaque origin (`blob:null/…`, made by a
|
|
875
|
-
* `data:` or sandboxed frame, or a page from an html `source` without `baseUrl`) is blocked, a download of it too.
|
|
899
|
+
* These skip the rules:
|
|
876
900
|
*
|
|
877
|
-
*
|
|
878
|
-
* a redirect of a reload or back/forward
|
|
879
|
-
*
|
|
901
|
+
* - the `source` load, reloads and back/forward; a redirect of the `source` load goes to the rules, and on Android so
|
|
902
|
+
* does a redirect of a reload or back/forward;
|
|
903
|
+
* - a form POST, on either platform, an iframe's to the main frame (`target=_top`) included: it loads in place; one
|
|
904
|
+
* to a new window loads in place on iOS and isn't shown on Android (the request may still reach the server);
|
|
905
|
+
* - `about:`, `data:` and `javascript:`, which load in place, except as a new window
|
|
906
|
+
* ({@link NavigationRule.newWindow}).
|
|
880
907
|
*
|
|
881
|
-
*
|
|
882
|
-
*
|
|
883
|
-
*
|
|
908
|
+
* A `blob:` URL is decided as the origin it carries: `blob:https://example.com/…` as `https://example.com/`, and one
|
|
909
|
+
* with an opaque origin (`blob:null/…`, made by a `data:` or sandboxed frame, or a page from an html `source`
|
|
910
|
+
* without `baseUrl`) is blocked, a download of it too.
|
|
884
911
|
*
|
|
885
|
-
* A
|
|
912
|
+
* A malformed rule, one with an unknown key, a field of the wrong type (a list that isn't an array of strings, a flag
|
|
913
|
+
* that isn't a boolean) or no valid `action`, blocks every navigation that reaches it, whatever it was meant to match
|
|
914
|
+
* or do. In development a warning names the rule's index and the problem, once. The rules before it decide as usual;
|
|
915
|
+
* one that isn't an array is `[]`.
|
|
886
916
|
*
|
|
887
917
|
* A native hook can take these decisions, defaults included: see `WebViewContext.clients` (Android) and
|
|
888
918
|
* `navigationDelegates` (iOS).
|
|
889
|
-
* @example
|
|
890
|
-
* ```tsx
|
|
891
|
-
* <WebView
|
|
892
|
-
* source={{ uri: 'https://example.com' }}
|
|
893
|
-
* // myapp: opens externally even without a user gesture; everything else as by default
|
|
894
|
-
* navigationRules={[{ scheme: ['myapp'], action: 'external' }, ...defaultNavigationRules]}
|
|
895
|
-
* />
|
|
896
|
-
* ```
|
|
897
919
|
* @see [Navigation rules example](https://rasmuskard.github.io/react-native-minimal-webview/guides/examples/#navigation-rules)
|
|
898
920
|
*/
|
|
899
921
|
navigationRules?: readonly NavigationRule[];
|
|
@@ -903,6 +925,7 @@ export interface WebViewProps extends Omit<ViewProps, 'children'> {
|
|
|
903
925
|
* A late, missing or other answer is `block`, as is one still pending when another page commits; `signal` aborts at
|
|
904
926
|
* the timeout and at that commit. Without this prop, `ask` is `block`. Until the next commit, a URL it allowed isn't
|
|
905
927
|
* asked again on a redirect back to it (Android), or when the same kind of frame loads it again (iOS).
|
|
928
|
+
* @see [Navigation rules example](https://rasmuskard.github.io/react-native-minimal-webview/guides/examples/#navigation-rules)
|
|
906
929
|
*/
|
|
907
930
|
onNavigationRequest?: (
|
|
908
931
|
request: NavigationRequest,
|
|
@@ -916,7 +939,10 @@ export interface WebViewProps extends Omit<ViewProps, 'children'> {
|
|
|
916
939
|
* nothing opens it.
|
|
917
940
|
*
|
|
918
941
|
* Without this prop, the system browser or app for the URL opens it, without asking `canOpenURL` first, so no
|
|
919
|
-
* `LSApplicationQueriesSchemes` (iOS) or `<queries>` (Android) entries are needed.
|
|
942
|
+
* `LSApplicationQueriesSchemes` (iOS) or `<queries>` (Android) entries are needed. An Android `intent:` URL opens
|
|
943
|
+
* only as a browsable intent, without its explicit component or selector; when no app handles it, an http(s)
|
|
944
|
+
* `S.browser_fallback_url` goes through the rules (main frame, no user gesture), and the `intent:` itself is
|
|
945
|
+
* reported as `block`.
|
|
920
946
|
*/
|
|
921
947
|
onOpenExternal?: (
|
|
922
948
|
request: NavigationRequest,
|
|
@@ -925,55 +951,61 @@ export interface WebViewProps extends Omit<ViewProps, 'children'> {
|
|
|
925
951
|
/**
|
|
926
952
|
* The bridge to the page, from `createBridge`, of any schema.
|
|
927
953
|
*
|
|
928
|
-
* Read when the WebView is created: another bridge recreates it
|
|
929
|
-
* over
|
|
930
|
-
* bridge replaces its own
|
|
954
|
+
* Read when the WebView is created: another bridge recreates it, so the page reloads and the navigation state starts
|
|
955
|
+
* over. Make the bridge once, at module scope or with `useMemo`. In development, a WebView warns the first time
|
|
956
|
+
* another bridge replaces its own.
|
|
931
957
|
*
|
|
932
|
-
*
|
|
933
|
-
*
|
|
958
|
+
* A bridge serves one mounted WebView at a time: attaching it to a second throws.
|
|
959
|
+
*
|
|
960
|
+
* On Android with an Android System WebView older than 101 there is no bridge: calls reject with `unavailable`, and a
|
|
961
|
+
* warning says so, once per process.
|
|
934
962
|
*/
|
|
935
963
|
bridge?: Pick<Bridge, typeof CONNECTION>;
|
|
936
964
|
/**
|
|
937
|
-
* The native hooks to turn on, as {@link HookExtension}s
|
|
938
|
-
* returns one.
|
|
965
|
+
* The native hooks to turn on, as {@link HookExtension}s.
|
|
939
966
|
*
|
|
940
967
|
* A false, null or undefined entry is left out, so `on && extension(…)` switches one on and off; see
|
|
941
968
|
* {@link HookExtension.options} for what off means. A hook attaches when its key first appears, and a later change of
|
|
942
969
|
* its `options` reaches it live, without recreating the WebView. A key turned on after the WebView was created
|
|
943
970
|
* attaches its hook then, unless the hook has a `configure` step or its own WebView class (`webViewClass`,
|
|
944
|
-
* `webViewFactory`): that one attaches only
|
|
971
|
+
* `webViewFactory`): that one attaches only to a WebView mounted with its key on, and a warning says so.
|
|
945
972
|
* @see [Native hooks guide](https://rasmuskard.github.io/react-native-minimal-webview/guides/native-hooks/)
|
|
946
973
|
*/
|
|
947
974
|
extensions?: readonly (HookExtension | false | null | undefined)[];
|
|
948
975
|
/**
|
|
949
976
|
* Pull down at the top of the page to reload: `UIRefreshControl` on iOS, `SwipeRefreshLayout` on Android, where a
|
|
950
|
-
* pull inside a scrolled inner scroller (`overflow: auto`) scrolls it instead.
|
|
977
|
+
* pull inside a scrolled inner scroller (`overflow: auto` or `scroll`) scrolls it instead.
|
|
951
978
|
*
|
|
952
|
-
* It reloads as {@link WebViewRef.reload | reload()} does, a POST `source` included
|
|
979
|
+
* It reloads as {@link WebViewRef.reload | reload()} does, a POST `source` included, but leaves the
|
|
980
|
+
* {@link ProcessGoneEvent.recovered | crash recovery} limit in place. A change applies at once.
|
|
953
981
|
* @default `false`
|
|
954
982
|
*/
|
|
955
983
|
pullToRefresh?: boolean;
|
|
956
984
|
/**
|
|
957
|
-
*
|
|
958
|
-
*
|
|
985
|
+
* Syncs cookies between `HTTPCookieStorage`, which holds the cookies of native requests, and the WebView:
|
|
986
|
+
*
|
|
987
|
+
* - `HTTPCookieStorage` into the WebView before each `source` load, which waits for it;
|
|
988
|
+
* - the WebView into `HTTPCookieStorage` on every cookie change, deletions included, as it happens.
|
|
959
989
|
*
|
|
960
990
|
* Android needs nothing: `CookieManager` is shared app-wide, and flushed when the app goes to the background. A
|
|
961
991
|
* WebView on another `android.webView.profile` has that profile's cookies instead.
|
|
962
992
|
* @default `false`
|
|
963
993
|
* @ios
|
|
994
|
+
* @see [Cookies example](https://rasmuskard.github.io/react-native-minimal-webview/guides/examples/#cookies)
|
|
964
995
|
*/
|
|
965
996
|
sharedCookies?: boolean;
|
|
966
997
|
/**
|
|
967
998
|
* Answers `<input type="file">` with `file://` or `content://` URIs, or null to cancel.
|
|
968
999
|
*
|
|
969
|
-
*
|
|
970
|
-
* one is open is cancelled, and if the chooser's activity died without returning a result, so is every request until
|
|
971
|
-
* the app restarts.
|
|
1000
|
+
* Until the answer settles, the page's next file request waits.
|
|
972
1001
|
*
|
|
973
|
-
*
|
|
1002
|
+
* Without it, the system file chooser opens and ignores `capture`. It handles one request at a time for the whole
|
|
1003
|
+
* app: a request while one is open is cancelled. If the chooser's activity died without returning a result, every
|
|
1004
|
+
* request is cancelled until the app restarts.
|
|
974
1005
|
*
|
|
975
|
-
*
|
|
1006
|
+
* iOS always shows WebKit's picker, whose camera option needs `NSCameraUsageDescription`.
|
|
976
1007
|
* @android
|
|
1008
|
+
* @see [File inputs example](https://rasmuskard.github.io/react-native-minimal-webview/guides/examples/#file-inputs)
|
|
977
1009
|
*/
|
|
978
1010
|
onFileRequest?: (
|
|
979
1011
|
request: FileRequest,
|
|
@@ -983,22 +1015,30 @@ export interface WebViewProps extends Omit<ViewProps, 'children'> {
|
|
|
983
1015
|
* The page entered or left fullscreen (`active`).
|
|
984
1016
|
*
|
|
985
1017
|
* Fullscreen works without it: the page's view covers the window, the system bars hide and back exits. iOS shows
|
|
986
|
-
* WebKit's own fullscreen, not reported
|
|
1018
|
+
* WebKit's own fullscreen, not reported; there an element other than a video goes fullscreen only with
|
|
1019
|
+
* `ios.preferences.elementFullscreenEnabled`.
|
|
987
1020
|
* @android
|
|
1021
|
+
* @see [Fullscreen video example](https://rasmuskard.github.io/react-native-minimal-webview/guides/examples/#fullscreen-video)
|
|
988
1022
|
*/
|
|
989
1023
|
onFullscreenChange?: (event: FullscreenChangeEvent) => void;
|
|
990
1024
|
/**
|
|
991
|
-
*
|
|
1025
|
+
* Answers a page's camera, microphone and, on Android, location and protected media (DRM) requests.
|
|
992
1026
|
*
|
|
993
|
-
*
|
|
994
|
-
*
|
|
1027
|
+
* Only the main frame asks (on Android, which doesn't name the frame, any frame of the top page's origin); other
|
|
1028
|
+
* frames, and a page with an opaque origin (`data:`, a sandboxed frame), are denied without asking, with or without
|
|
1029
|
+
* this prop.
|
|
995
1030
|
*
|
|
996
|
-
*
|
|
997
|
-
*
|
|
998
|
-
*
|
|
1031
|
+
* Answer true to grant; anything else denies. Ask the OS first (expo-camera, expo-location): without OS permission
|
|
1032
|
+
* the page's request fails anyway. On iOS, true also skips WebKit's own prompt. Android keeps a location answer
|
|
1033
|
+
* until the page changes.
|
|
999
1034
|
*
|
|
1000
|
-
*
|
|
1001
|
-
*
|
|
1035
|
+
* Without this prop, Android denies and iOS shows WebKit's prompt. iOS needs `NSCameraUsageDescription` and
|
|
1036
|
+
* `NSMicrophoneUsageDescription` (`NSLocationWhenInUseUsageDescription` for location), Android the `CAMERA` and
|
|
1037
|
+
* `RECORD_AUDIO` manifest permissions (`ACCESS_COARSE_LOCATION` or `ACCESS_FINE_LOCATION` for location).
|
|
1038
|
+
*
|
|
1039
|
+
* `signal` also aborts when Android withdraws the request. Until the answer settles, the page's next request of the
|
|
1040
|
+
* same kind waits.
|
|
1041
|
+
* @see [Permissions example](https://rasmuskard.github.io/react-native-minimal-webview/guides/examples/#permissions)
|
|
1002
1042
|
*/
|
|
1003
1043
|
onPermissionRequest?: (
|
|
1004
1044
|
request: PermissionRequest,
|
|
@@ -1007,10 +1047,10 @@ export interface WebViewProps extends Omit<ViewProps, 'children'> {
|
|
|
1007
1047
|
/**
|
|
1008
1048
|
* A download finished ({@link Download}) or failed ({@link DownloadFailure}).
|
|
1009
1049
|
*
|
|
1010
|
-
* With this prop the core saves the file
|
|
1011
|
-
* host's cookies (whatever their SameSite) and the page's user agent
|
|
1012
|
-
*
|
|
1013
|
-
*
|
|
1050
|
+
* With this prop the core saves the file. iOS downloads it in the page's session. Android fetches it again with the
|
|
1051
|
+
* host's cookies (whatever their SameSite) and the page's user agent, without the POST body, `source` headers or
|
|
1052
|
+
* HTTP auth, so a download that needs them can fail, or save the server's login page as the file. The fetch also
|
|
1053
|
+
* fails on a redirect off https, and for `blob:` on an Android System WebView older than 83.
|
|
1014
1054
|
*
|
|
1015
1055
|
* Without this prop, an http(s) download opens externally (`onOpenExternal` or the system browser, without the page's
|
|
1016
1056
|
* session), and a `data:` or `blob:` one is dropped. A PDF is a download on Android; iOS shows it inline.
|
|
@@ -1019,12 +1059,14 @@ export interface WebViewProps extends Omit<ViewProps, 'children'> {
|
|
|
1019
1059
|
*
|
|
1020
1060
|
* On Android a native hook's `WebViewContext.onDownloadStart` is offered each download first, and one it takes
|
|
1021
1061
|
* reaches neither this prop nor the external fallback.
|
|
1062
|
+
* @see [Downloads example](https://rasmuskard.github.io/react-native-minimal-webview/guides/examples/#downloads)
|
|
1022
1063
|
*/
|
|
1023
1064
|
onDownload?: (result: DownloadResult) => void;
|
|
1024
1065
|
/**
|
|
1025
1066
|
* Every navigation the rules, or their defaults, decided.
|
|
1026
1067
|
*
|
|
1027
|
-
* Not reported: the `source` load, reloads, back/forward, and a navigation a native hook decides.
|
|
1068
|
+
* Not reported: the `source` load, reloads, back/forward, a form POST, and a navigation a native hook decides.
|
|
1069
|
+
* @see [Navigation rules example](https://rasmuskard.github.io/react-native-minimal-webview/guides/examples/#navigation-rules)
|
|
1028
1070
|
*/
|
|
1029
1071
|
onNavigation?: (event: NavigationEvent) => void;
|
|
1030
1072
|
/**
|
|
@@ -1038,9 +1080,10 @@ export interface WebViewProps extends Omit<ViewProps, 'children'> {
|
|
|
1038
1080
|
* A main-frame load failed, or got an HTTP error status.
|
|
1039
1081
|
*
|
|
1040
1082
|
* After a failed load iOS keeps the page before it on screen, and Android shows WebView's own error page. On Android
|
|
1041
|
-
* with
|
|
1083
|
+
* with an Android System WebView older than 146, an SSL error on a back/forward load isn't reported.
|
|
1042
1084
|
*
|
|
1043
1085
|
* A renderer crash isn't reported here: it makes the cut-off load's `outcome` `failed` and calls `onProcessGone`.
|
|
1086
|
+
* @see [Loading and error screens example](https://rasmuskard.github.io/react-native-minimal-webview/guides/examples/#loading-and-error-screens)
|
|
1044
1087
|
*/
|
|
1045
1088
|
onError?: (event: LoadErrorEvent) => void;
|
|
1046
1089
|
/**
|
|
@@ -1052,7 +1095,8 @@ export interface WebViewProps extends Omit<ViewProps, 'children'> {
|
|
|
1052
1095
|
/**
|
|
1053
1096
|
* `loading` went true.
|
|
1054
1097
|
*
|
|
1055
|
-
* On Android with
|
|
1098
|
+
* On Android with an Android System WebView older than 146, that is when the page commits (its response arrives),
|
|
1099
|
+
* not when the load starts, and a load that never commits fires neither this nor `onLoadEnd`.
|
|
1056
1100
|
*/
|
|
1057
1101
|
onLoadStart?: (state: NavigationState) => void;
|
|
1058
1102
|
/** `loading` went false: `state.outcome` says how the load ended. */
|
|
@@ -1069,11 +1113,14 @@ export interface WebViewProps extends Omit<ViewProps, 'children'> {
|
|
|
1069
1113
|
/**
|
|
1070
1114
|
* The methods a WebView's `ref` gets: navigation, scripts, and platform and hook calls.
|
|
1071
1115
|
*
|
|
1072
|
-
* A handle kept after its WebView unmounted is safe to call
|
|
1073
|
-
*
|
|
1116
|
+
* A handle kept after its WebView unmounted is safe to call. `evaluate`, `get`, `call` and `hook` are the methods that
|
|
1117
|
+
* return a promise:
|
|
1074
1118
|
*
|
|
1075
|
-
*
|
|
1076
|
-
*
|
|
1119
|
+
* - After an unmount: the navigation methods do nothing and the four promise methods reject with `unavailable`.
|
|
1120
|
+
* - Pending when the WebView unmounts: the four reject with `navigated`.
|
|
1121
|
+
* - Just mounted: the four wait up to about a second for the view (on Android, a call from the parent's first effect
|
|
1122
|
+
* can come before the view exists), then reject with `unavailable`. In the background they don't wait.
|
|
1123
|
+
* @sortStrategy source-order
|
|
1077
1124
|
* @group WebView
|
|
1078
1125
|
*/
|
|
1079
1126
|
export type WebViewRef = {
|
|
@@ -1099,43 +1146,45 @@ export type WebViewRef = {
|
|
|
1099
1146
|
* Runs an expression (not statements) in the page's main frame and awaits it.
|
|
1100
1147
|
*
|
|
1101
1148
|
* Resolves with its value through JSON: `null` for what JSON can't encode (a function, `NaN`, a cycle), a `Date` as
|
|
1102
|
-
* its ISO string. The value is the page's, so treat it as page data.
|
|
1103
|
-
*
|
|
1104
|
-
*
|
|
1149
|
+
* its ISO string. The value is the page's, so treat it as page data.
|
|
1150
|
+
*
|
|
1151
|
+
* Rejects with a {@link CodedError}: `script_error`, `navigated` or `unavailable`. There is no timeout: a page can
|
|
1152
|
+
* hold a call until it navigates. On Android with an Android System WebView older than 83 it rejects with
|
|
1153
|
+
* `unavailable`.
|
|
1154
|
+
* @see [Scripts example](https://rasmuskard.github.io/react-native-minimal-webview/guides/examples/#scripts)
|
|
1105
1155
|
*/
|
|
1106
1156
|
evaluate(script: string): Promise<unknown>;
|
|
1107
1157
|
/**
|
|
1108
1158
|
* Reads a platform setting, `root.key`, and resolves with its value through JSON, as {@link WebViewRef.call | call}
|
|
1109
1159
|
* converts results.
|
|
1110
1160
|
*
|
|
1111
|
-
* The roots
|
|
1161
|
+
* The roots are those of {@link IOSSettings} and {@link AndroidSettings}, plus on iOS `websiteDataStore` and
|
|
1162
|
+
* `httpCookieStore`, and on Android `cookieManager` and `webStorage` (the WebView profile's: `webView.profile`, the
|
|
1163
|
+
* default one unless set). A key is the property's name on iOS, and on Android the getter's name without `get` or
|
|
1164
|
+
* `is`.
|
|
1112
1165
|
*
|
|
1113
1166
|
* It reads the WebView as it is when the call arrives: a navigation doesn't reject it. Rejects with a
|
|
1114
|
-
* {@link CodedError}: `not_found`, `unavailable`
|
|
1115
|
-
* @example
|
|
1116
|
-
* ```ts
|
|
1117
|
-
* const bounces = await ref.current?.get('scrollView.bounces'); // iOS
|
|
1118
|
-
* const textZoom = await ref.current?.get('settings.textZoom'); // Android
|
|
1119
|
-
* ```
|
|
1167
|
+
* {@link CodedError}: `not_found`, `unavailable` or `native_error`.
|
|
1168
|
+
* @see [Reading and calling example](https://rasmuskard.github.io/react-native-minimal-webview/guides/examples/#reading-and-calling)
|
|
1120
1169
|
*/
|
|
1121
1170
|
get(key: string): Promise<unknown>;
|
|
1122
1171
|
/**
|
|
1123
1172
|
* Calls a platform method, `root.method`, and resolves with its result through JSON. It acts on the WebView as it is
|
|
1124
1173
|
* when the call arrives: a navigation doesn't reject it.
|
|
1125
1174
|
*
|
|
1126
|
-
* The roots are those of {@link
|
|
1127
|
-
*
|
|
1175
|
+
* The roots are those of {@link WebViewRef.get | get}. On Android `method` is a public method of the root's object;
|
|
1176
|
+
* on iOS an Objective-C selector.
|
|
1128
1177
|
*
|
|
1129
|
-
* Rejects with a {@link CodedError}: `not_found`, `unavailable`
|
|
1178
|
+
* Rejects with a {@link CodedError}: `not_found`, `unavailable` or `native_error`.
|
|
1130
1179
|
*
|
|
1131
1180
|
* The core owns, and so rejects:
|
|
1132
1181
|
*
|
|
1133
1182
|
* - iOS: every selector that loads, navigates (`setInteractionState:` too), runs a script, starts a download or sets
|
|
1134
1183
|
* a delegate, and private (`_`), KVC, `willChange…`, `didChange…`, `performSelector`, `init…`, `copy…`,
|
|
1135
1184
|
* `mutable…`, `new…` and reference-counting selectors.
|
|
1136
|
-
* - Android: the loads, navigations, clients, JavaScript interfaces, web message listeners,
|
|
1137
|
-
*
|
|
1138
|
-
* `
|
|
1185
|
+
* - Android: the loads, navigations, clients, JavaScript interfaces, web message listeners, document-start scripts,
|
|
1186
|
+
* the download, touch, scroll-change and navigation listeners, `destroy`, `removeAllViews`, `pauseTimers`,
|
|
1187
|
+
* `resumeTimers`, `evaluateJavascript` and remote debugging
|
|
1139
1188
|
* ({@link AndroidWebView.setWebContentsDebuggingEnabled}).
|
|
1140
1189
|
*
|
|
1141
1190
|
* A trailing completion handler (iOS) or `ValueCallback` (Android) is left out of `args`: the call resolves with what
|
|
@@ -1151,17 +1200,14 @@ export type WebViewRef = {
|
|
|
1151
1200
|
* @param args The method's arguments: booleans, numbers, strings and `null`. On iOS also the structs as objects, and
|
|
1152
1201
|
* `{ set: [...] }`, `{ date: seconds }`, `{ data: base64 }` or `{ cookie: properties }` for an `NSSet`, `NSDate`,
|
|
1153
1202
|
* `NSData` or `NSHTTPCookie`; any other string stays an `NSString`. A cookie's properties are `NSHTTPCookie`'s keys:
|
|
1154
|
-
* `Name`, `Value
|
|
1203
|
+
* `Name`, `Value` and `Path` are required, and `Domain` unless `OriginURL` is given; `Max-Age` (seconds, as a string), `Secure`, `HttpOnly` and
|
|
1155
1204
|
* `SameSite` are some of the optional ones. A tag that can't make its object (`{ data }` that isn't base64, a
|
|
1156
1205
|
* `{ cookie }` without a required key) rejects with `native_error`.
|
|
1157
1206
|
* @returns The result: primitives, strings, and collections of them; on iOS also the structs as objects, an `NSURL`
|
|
1158
1207
|
* as a string, an `NSDate` as seconds, `NSData` as base64, a `UIImage` as a base64 PNG and an `NSHTTPCookie` as its
|
|
1159
1208
|
* properties (`Expires` in seconds). Any other object is `null`.
|
|
1160
|
-
* @
|
|
1161
|
-
*
|
|
1162
|
-
* await ref.current?.call('webView.clearCache', [true]); // Android
|
|
1163
|
-
* await ref.current?.call('scrollView.setContentOffset:animated:', [{ x: 0, y: 100 }, true]); // iOS
|
|
1164
|
-
* ```
|
|
1209
|
+
* @see [Call a method](https://rasmuskard.github.io/react-native-minimal-webview/guides/platform-apis/#4-call-a-method)
|
|
1210
|
+
* @see [Reading and calling example](https://rasmuskard.github.io/react-native-minimal-webview/guides/examples/#reading-and-calling)
|
|
1165
1211
|
*/
|
|
1166
1212
|
call(method: string, args?: unknown[]): Promise<unknown>;
|
|
1167
1213
|
/**
|
|
@@ -1169,8 +1215,8 @@ export type WebViewRef = {
|
|
|
1169
1215
|
* its reply; both cross as JSON.
|
|
1170
1216
|
*
|
|
1171
1217
|
* The reply converts as {@link WebViewRef.call | call}'s results do. Rejects with a {@link CodedError}:
|
|
1172
|
-
* `not_found`, `unavailable
|
|
1173
|
-
*
|
|
1218
|
+
* `not_found`, `unavailable`, `handler_error` when the handler fails the call (`reply.fail(message)`, or a throw on
|
|
1219
|
+
* Android), or `native_error` for a non-finite number in the reply. A navigation or a crash doesn't settle a call
|
|
1174
1220
|
* whose handler hasn't replied; only an unmount does.
|
|
1175
1221
|
*/
|
|
1176
1222
|
hook(name: string, method: string, args?: unknown[]): Promise<unknown>;
|