Skip to content

Forward Error To Webview #98

@stefan-tuertscher

Description

@stefan-tuertscher

In React Native, if a function throws an error, the error is not passed, but the function rejects NativeMethodError in webview.

import { createWebView, bridge } from "@webview-bridge/react-native";
import InAppBrowser from "react-native-inappbrowser-reborn";

// Register functions in the bridge object in your React Native code
export const appBridge = bridge({
  async openInAppBrowser(url: string) {
    if (await InAppBrowser.isAvailable()) {
      await InAppBrowser.open(url);
    } else {
       throw new Error("InAppBrowser is not available")
    }
  },
  // ... Add more functions as needed
});

// Export the bridge type to be used in the web application
export type AppBridge = typeof appBridge;

Currently

import { linkBridge } from "@webview-bridge/web";
import type { AppBridge } from ""; // Import the type 'appBridge' declared in native

...

bridge.openInAppBrowser("http://localhost:5173").catch((err) => console.log(message)); // "{ name: 'NativeMethodError' }"

Expected

import { linkBridge } from "@webview-bridge/web";
import type { AppBridge } from ""; // Import the type 'appBridge' declared in native

...

bridge.openInAppBrowser("http://localhost:5173").catch((err) => console.log(message)); // "Error: InAppBrowser is not available"

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions