Awesome Open Source
Awesome Open Source


CI Status Version License Platform

WKScriptMessageHandler greatly simplifies the message handler from javascript running in a webpage. WKScript provides a more efficiently way for both sending and receiving messages through WKScriptMessageHandler.


  • [x] Send / Receive Messages
  • [x] Bind Events In JavaScript
  • [x] Callback Event


Native Handle Event

webView.bridge.register({ (parameters, completion) in
    print("print - ", parameters?["message"] ?? "")
}, for: "print")

webView.bridge.register({ (parameters, completion) in
    print("print - ", parameters?["message"] ?? "")
    completion(.success(["key": "value"]))
}, for: "some_event_need_callback")

Native Call JS

webView.evaluateJavaScript("some_method();", completionHandler: { (results, error) in
    print(results ?? "")

webView.bridge.evaluate("some_method()", completion: { (results, error) in
    print(results ?? "")

JS Send Event'print', {message: 'Hello, world'})
// Post Event With Callback'print', {message: 'Hello, world'}, (parameters, error) => { <# Handler Parameters Or Error #>})

JS Register Native Event

var unregisterHandler = window.bridge.on('login', (parameters)=> {console.log('User Did Login')})
// To Remove Listener, call `unregisterHandler()`, Or Remove All Listener'login')

Native Send Event To JS "login", parameters: nil)

You can include wk.bridge.min.js to your own html, or you can inject it to your html using WKUserScript.

You can Download full source-code of wk.bridge.min.js


To run the example project, clone the repo, and run pod install from the Example directory first.


iOS 8.0 +


WKBridge is available through CocoaPods. To install it, simply add the following line to your Podfile:

pod "WKBridge"


[email protected]


WKBridge is available under the MIT license. See the LICENSE file for more info.

Get A Weekly Email With Trending Projects For These Topics
No Spam. Unsubscribe easily at any time.
Swift (95,446
Related Projects