marcuswestin/WebViewJavascriptBridge is a Objective-C project with 14.3k stars. An iOS/OSX bridge for sending messages between Obj-C and JavaScript in UIWebViews/WebViews
Snapshot summary built from the project's own GitHub metadata — there's no written TopGit review yet. The page will update automatically when a full review is published.
WHY NO REVIEW YET
TopGit writes full reviews for the most-starred, most-requested repositories. This page is a snapshot until then — see the READ ME tab for the original README in full.
An iOS/OSX bridge for sending messages between Obj-C and JavaScript in WKWebViews, UIWebViews & WebViews.
Migration Guide
When upgrading from v5.0.x to 6.0.x you will have to update the setupWebViewJavascriptBridge javascript snippet. See https://github.com/marcuswestin/WebViewJavascriptBridge#usage part 4).
Who uses WebViewJavascriptBridge?
WebViewJavascriptBridge is used by a range of companies and projects. This is a small and incomplete sample list:
Facebook Messenger
Facebook Paper
Yardsale
EverTrue
Game Insight
Sush.io
Imbed
CareZone
Hemlig
Altralogica
鼎盛中华
FRIL
留白·WHITE
BrowZine
... & many more!
Installation (iOS & OSX)
Installation with CocoaPods
Add this to your podfile and run pod install to install:
pod 'WebViewJavascriptBridge', '~> 6.0'
Manual installation
Drag the WebViewJavascriptBridge folder into your project.
In the dialog that appears, uncheck "Copy items into destination group's folder" and select "Create groups for any folders".
Examples
See the Example Apps/ folder. Open either the iOS or OSX project and hit run to see it in action.
To use a WebViewJavascriptBridge in your own project:
Usage
Import the header file and declare an ivar property:
#import "WebViewJavascriptBridge.h"
...
@property WebViewJavascriptBridge* bridge;
Instantiate WebViewJavascriptBridge with a WKWebView, UIWebView (iOS) or WebView (OSX):
Copy and paste setupWebViewJavascriptBridge into your JS:
function setupWebViewJavascriptBridge(callback) {
if (window.WebViewJavascriptBridge) { return callback(WebViewJavascriptBridge); }
if (window.WVJBCallbacks) { return window.WVJBCallbacks.push(callback); }
window.WVJBCallbacks = [callback];
var WVJBIframe = document.createElement('iframe');
WVJBIframe.style.display = 'none';
WVJBIframe.src = 'https://__bridge_loaded__';
document.documentElement.appendChild(WVJBIframe);
setTimeout(function() { document.documentElement.removeChild(WVJBIframe) }, 0)
}
Finally, call setupWebViewJavascriptBridge and then use the bridge to register handlers and call ObjC handlers:
setupWebViewJavascriptBridge(function(bridge) {
/* Initialize your app here */
bridge.registerHandler('JS Echo', function(data, responseCallback) {
console.log("JS Echo called with:", data)
responseCallback(data)
})
bridge.callHandler('ObjC Echo', {'key':'value'}, function responseCallback(responseData) {
console.log("JS received response:", responseData)
})
})
Automatic reference counting (ARC)
This library relies on ARC, so if you use ARC in you project, all works fine.
But if your project have no ARC support, be sure to do next steps:
In your Xcode project open project settings -> 'Build Phases'
Expand 'Compile Sources' header and find all *.m files which are belongs to this library. Make attention on the 'Compiler Flags' in front of each source file in this list
For each file add '-fobjc-arc' flag
Now all WVJB files will be compiled with ARC support.
Call the javascript handler called handlerName. If a responseCallback block is given the javascript handler can respond.
Example:
[self.bridge callHandler:@"showAlert" data:@"Hi from ObjC to JS!"];
[self.bridge callHandler:@"getCurrentPageUrl" data:nil responseCallback:^(id responseData) {
NSLog(@"Current UIWebView page URL is: %@", responseData);
}];
[bridge setWebViewDelegate:(id)webViewDelegate]
Optionally, set a WKNavigationDelegate/UIWebViewDelegate if you need to respond to the web view's lifecycle events.
[bridge disableJavscriptAlertBoxSafetyTimeout]
UNSAFE. Speed up bridge message passing by disabling the setTimeout safety check. It is only safe to disable this safety check if you do not call any of the javascript popup box functions (alert, confirm, and prompt). If you call any of these functions from the bridged javascript code, the app will hang.
Register a handler called handlerName. The ObjC can then call this handler with [bridge callHandler:"handlerName" data:@"Foo"] and [bridge callHandler:"handlerName" data:@"Foo" responseCallback:^(id responseData) { ... }]
How active is development on marcuswestin/WebViewJavascriptBridge?
The most recent commit recorded on marcuswestin/WebViewJavascriptBridge was 2.3 years ago, based on the GitHub push timestamp. The repository has 2.9k forks — one of the better signals of community interest.
How many stars does marcuswestin/WebViewJavascriptBridge have?
marcuswestin/WebViewJavascriptBridge has 14.3k GitHub stars — refresh the page for the live number, or check github.com/marcuswestin/WebViewJavascriptBridge. TopGit mirrors GitHub's count but does not claim minute-by-minute accuracy.
Is marcuswestin/WebViewJavascriptBridge open source?
Yes — marcuswestin/WebViewJavascriptBridge ships under the MIT license, which makes its source code freely readable (and, depending on license terms, forkable and reusable). Source: github.com/marcuswestin/WebViewJavascriptBridge.
What is marcuswestin/WebViewJavascriptBridge?
marcuswestin/WebViewJavascriptBridge (marcuswestin/WebViewJavascriptBridge) is a Objective-C project on GitHub. From the project's own README: An iOS/OSX bridge for sending messages between Obj-C and JavaScript in UIWebViews/WebViews
What language is marcuswestin/WebViewJavascriptBridge written in?
marcuswestin/WebViewJavascriptBridge is written primarily in Objective-C. GitHub's language field is based on the largest share of bytes in the default branch.
What license does marcuswestin/WebViewJavascriptBridge use?
marcuswestin/WebViewJavascriptBridge is released under the MIT license. Always verify the LICENSE file directly on GitHub for the authoritative terms — license strings can be edited out of sync with a project's actual stance.
Where do I read more about marcuswestin/WebViewJavascriptBridge?
This TopGit page is a snapshot — the READ ME tab shows the project's own README content (links stripped, images preserved). The GitHub repository at github.com/marcuswestin/WebViewJavascriptBridge is the definitive source.
Read full README in the tab above.
Still deciding about WebViewJavascriptBridge?
One click hands the question to an AI along with this page — see what it says about WebViewJavascriptBridge.