@webview-bridge/web 1.1.0 → 1.1.2

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.
@@ -218,13 +218,22 @@ var registerWebMethod = (bridge) => {
218
218
  window.webEmitter = emitter2;
219
219
  for (const [funcName, func] of bridgeEntries) {
220
220
  const $func = async (eventId, args) => {
221
- const value = await func(...args);
222
- window.ReactNativeWebView?.postMessage(
223
- JSON.stringify({
224
- type: "webMethodResponse",
225
- body: { funcName, eventId, value }
226
- })
227
- );
221
+ try {
222
+ const value = await func(...args);
223
+ window.ReactNativeWebView?.postMessage(
224
+ JSON.stringify({
225
+ type: "webMethodResponse",
226
+ body: { funcName, eventId, value }
227
+ })
228
+ );
229
+ } catch (e) {
230
+ window.ReactNativeWebView?.postMessage(
231
+ JSON.stringify({
232
+ type: "webMethodError",
233
+ body: { funcName, eventId, error: JSON.stringify(e) }
234
+ })
235
+ );
236
+ }
228
237
  };
229
238
  emitter2.on(funcName, $func);
230
239
  }
@@ -189,13 +189,22 @@ var registerWebMethod = (bridge) => {
189
189
  window.webEmitter = emitter2;
190
190
  for (const [funcName, func] of bridgeEntries) {
191
191
  const $func = async (eventId, args) => {
192
- const value = await func(...args);
193
- window.ReactNativeWebView?.postMessage(
194
- JSON.stringify({
195
- type: "webMethodResponse",
196
- body: { funcName, eventId, value }
197
- })
198
- );
192
+ try {
193
+ const value = await func(...args);
194
+ window.ReactNativeWebView?.postMessage(
195
+ JSON.stringify({
196
+ type: "webMethodResponse",
197
+ body: { funcName, eventId, value }
198
+ })
199
+ );
200
+ } catch (e) {
201
+ window.ReactNativeWebView?.postMessage(
202
+ JSON.stringify({
203
+ type: "webMethodError",
204
+ body: { funcName, eventId, error: JSON.stringify(e) }
205
+ })
206
+ );
207
+ }
199
208
  };
200
209
  emitter2.on(funcName, $func);
201
210
  }
@@ -5,8 +5,8 @@ export type NativeMethod<T> = {
5
5
  isNativeMethodAvailable(method: keyof T): boolean;
6
6
  isNativeMethodAvailable(method: string): boolean;
7
7
  loose: {
8
- [K in keyof T]: (...args: any[]) => any;
8
+ [K in keyof T]: (...args: any[]) => Promise<any>;
9
9
  } & {
10
- [key: string]: (...args: any[]) => any;
10
+ [key: string]: (...args: any[]) => Promise<any>;
11
11
  };
12
12
  } & T;
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@webview-bridge/web",
3
3
  "type": "module",
4
- "version": "1.1.0",
4
+ "version": "1.1.2",
5
5
  "description": "Fully Type-Safe Integration for React Native WebView and Web",
6
6
  "publishConfig": {
7
7
  "access": "public"
@@ -15,9 +15,9 @@
15
15
  "dist",
16
16
  "package.json"
17
17
  ],
18
- "main": "/dist/commonjs/index.cjs",
19
- "module": "/dist/module/index.mjs",
20
- "types": "/dist/typescript/packages/web/src/index.d.ts",
18
+ "main": "dist/commonjs/index.cjs",
19
+ "module": "dist/module/index.mjs",
20
+ "types": "dist/typescript/packages/web/src/index.d.ts",
21
21
  "exports": {
22
22
  ".": {
23
23
  "require": {