Registry / messaging / fetch-native-bridge

fetch-native-bridge

JSON →
library0.1.3jsnpmunverified

A fetch wrapper that bridges HTTP requests from a React Native WebView to the native app, enabling file downloads and other network operations that cannot be handled inside a WebView. Current stable version is 0.1.3, released as a new package with no prior major versions. Key differentiators: provides a drop-in `fetchBridge()` replacement that works identically to `fetch` in browsers, uses a message-passing pattern via `postMessage`/`onMessage`, and offers a `setupFetchHandler()` hook on the native side with optional `onFetch` callback for custom response handling (e.g., saving files to disk). Ships TypeScript types and requires `react-native >=0.70.0` and `react-native-webview >=11.0.0` as peer dependencies. The library does not transfer credentials (cookies, tokens) from the WebView; authentication must be handled natively.

npm install fetch-native-bridge
INSTALL
IMPORT
SIG · FETCH-NATIVE-BRIDG
F
fetch-native-bridge
messagingjavascriptv0.1.3
harness data pending
Install & Compatibility
Where this runs

No compatibility data collected yet for this library.

Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

fetchBridge
import { fetchBridge } from 'fetch-native-bridge'
const fetchBridge = require('fetch-native-bridge')
ESM-only; the package ships TypeScript types so named import is always used.
isReactNativeWebView
import { isReactNativeWebView } from 'fetch-native-bridge'
import isReactNativeWebView from 'fetch-native-bridge'
This is a named export, not default.
setupFetchHandler
import { setupFetchHandler } from 'fetch-native-bridge/native'
import { setupFetchHandler } from 'fetch-native-bridge'
Must import from the /native subpath; it's not exported from the main entry.

Replaces fetch() with fetchBridge() in a React Native WebView; includes timeout and bearer token.

import { fetchBridge } from 'fetch-native-bridge'; const response = await fetchBridge('https://api.example.com/file.pdf', { method: 'GET', headers: { Authorization: `Bearer ${process.env.TOKEN ?? ''}` }, timeout: 60000, }); const blob = await response.blob();
Debug
Known issues
gotchaCredentials (cookies, tokens) are not transferred from the WebView; authentication must be provided natively.
fix
Pass auth tokens as headers in the fetchBridge call or handle authentication in the native onFetch callback.
affects: >=0.0.0
gotchafetchBridge only works inside a React Native WebView; in a normal browser it behaves like fetch but will not bridge to native.
fix
Use isReactNativeWebView() to conditionally call fetchBridge or fallback to fetch.
affects: >=0.0.0
gotchasetupFetchHandler must be imported from 'fetch-native-bridge/native', not from the main entry point.
fix
Use import { setupFetchHandler } from 'fetch-native-bridge/native'.
affects: >=0.0.0
Errors
Common errors & fixes
TypeError: Cannot read properties of undefined (reading 'postMessage')
fetchBridge called outside of React Native WebView environment (no window.ReactNativeWebView).
fix
Ensure the code runs inside a React Native WebView, or use isReactNativeWebView() to guard.
Module not found: Can't resolve 'fetch-native-bridge/native'
Importing from /native in a bundler that doesn't resolve subpath exports (e.g., older Webpack config).
fix
Update bundler to support package.json exports field, or import from correct path.
Uncaught (in promise) TimeoutError: Request timed out after 30000ms
The native side did not respond within the default or specified timeout.
fix
Check that setupFetchHandler is properly set up and the native onMessage handler is registered.
Upgrade
Version history
0.1.3latest on npm
Audit
Dependencies
react-nativerequiredpeer dependency: native module relies on React Native runtime
react-native-webviewrequiredpeer dependency: requires WebView component for message bridging
Agent activity
18 hits · last 30 days
node
14
OpenAI (training)
1
Resources
fetch-native-bridge — npm install fetch-native-bridge · libregistry