
WebViewJavascriptBridge
A small library for passing messages between native iOS/macOS code and JavaScript in a web view.
- Stars
- 14.3k
- Forks
- 2.9k
- Licence
- MIT
- Language
- Objective-C
- Last update
- 2.3 years ago
- Type
- Library
No commits in over a year — check for forks or alternatives before adopting.
What it is
WebViewJavascriptBridge is an Objective-C library for iOS and OS X apps that lets native code and JavaScript running inside a web view send messages to each other. You register named handlers on one side and call them from the other, optionally getting a response back. It is aimed at app developers who embed web content in a native app and need the two to communicate.
- Have a native Objective-C method called from a JavaScript button inside a web view
- Have JavaScript request the current page URL or screen height from native code and receive a response
- Send a message from native code to a JavaScript handler, for example to show an alert in the page
Great for
- iOS developers who show web pages or web-based screens inside a native app
- OS X developers embedding a WebView who need native-to-JavaScript calls
- Teams maintaining an existing app that already uses UIWebView or WebView and needs a simple message bridge
Not ideal for
- Developers building a fully web-based app with no native code, since the bridge only links native and JavaScript
- Projects that need Android or other non-Apple platforms, since the description covers only iOS and OS X
- Beginners with no Objective-C or Xcode experience, since setup requires editing native and JavaScript code
How to get it
- 1
Install with a package manager
You'll need: Xcode · CocoaPods
Add to your podfile, then install
pod 'WebViewJavascriptBridge', '~> 6.0'Install pods
pod install - 2
Run it
- Import WebViewJavascriptBridge.h and declare a bridge property
- Create the bridge with bridgeForWebView: passing your web view
- Register an Objective-C handler with registerHandler:handler:
- Paste the setupWebViewJavascriptBridge snippet into your JavaScript and register a JS handler
- 3
Get the most out of it
- Open the Example Apps folder to see working iOS and OS X projects before writing your own code
- Use setWebViewDelegate: to respond to web view lifecycle events
- Pass a responseCallback when calling handlers if you need a return value
Downloads
Strengths
- Simple API: register a handler, then call it from the other side, with an optional response callback
- Installable with CocoaPods or by copying the folder into a project
- Released under the MIT license, which permits commercial use
Trade-offs
- The README covers older web view types (UIWebView, WebView) alongside WKWebView and includes a migration note, so the docs may need careful reading for current projects
- The README warns that a disabled alert safety timeout will hang the app if JavaScript alert, confirm, or prompt is called
- Manual installation requires adjusting compiler flags if the project does not use ARC
How it compares
| Project | Stars | Type | Level | Updated | Best for |
|---|---|---|---|---|---|
| WebViewJavascriptBridge (this) | 14.3k | Library | intermediate | 2.3 years ago | iOS developers who show web pages or web-based screens inside a native app |
| react-native | 127k | Framework | intermediate | 4 days ago | Web developers who already know React and want to build mobile apps |
Stats synced from GitHub. The assessment above was drafted with AI from the project's README on 2026-10-29 and may miss recent changes — check the README before relying on a command. MIT licence: free to use, modify and distribute, including commercially, as long as you keep the copyright notice.