diff --git a/example/shared-state-integration-react/react/src/App.tsx b/example/shared-state-integration-react/react/src/App.tsx index 3c23ccf9..3856e513 100644 --- a/example/shared-state-integration-react/react/src/App.tsx +++ b/example/shared-state-integration-react/react/src/App.tsx @@ -6,6 +6,7 @@ import type { AppBridge } from "@webview-bridge-example-shared-state-integration const bridge = linkBridge({ throwOnError: true, + debug: true, initialBridge: { count: 10, data: { diff --git a/packages/web/src/linkBridge.ts b/packages/web/src/linkBridge.ts index 5b6ece69..9d31c413 100644 --- a/packages/web/src/linkBridge.ts +++ b/packages/web/src/linkBridge.ts @@ -17,6 +17,11 @@ export interface LinkBridgeOptions< T extends BridgeStore, V extends ParserSchema, > { + /** + * If `true`, console warnings will be displayed. + * @default false + */ + debug?: boolean; /** * It is possible to configure `initialBridge` to operate in a non-React Native environment. * Prioritize applying the bridge of the React Native WebView, and if it is unavailable, apply the `initialBridge`. @@ -65,6 +70,7 @@ export const linkBridge = < options: LinkBridgeOptions = { timeout: 2000, throwOnError: false, + debug: false, }, ): LinkBridge>, Omit, V> => { if (typeof window === "undefined") { @@ -88,7 +94,7 @@ export const linkBridge = < } as LinkBridge>, Omit, V>; } - if (!window.ReactNativeWebView) { + if (options.debug && !window.ReactNativeWebView) { console.warn("[WebViewBridge] Not in a WebView environment"); } @@ -147,9 +153,11 @@ export const linkBridge = < }; } - console.warn( - `[WebViewBridge] ${methodName} is not defined, using fallback.`, - ); + if (options.debug) { + console.warn( + `[WebViewBridge] ${methodName} is not defined, using fallback.`, + ); + } return () => Promise.resolve(); }, }) as LinkBridge>, Omit, V>;