{"id":13462718,"url":"https://github.com/Lision/WKWebViewJavascriptBridge","last_synced_at":"2025-03-25T05:32:11.608Z","repository":{"id":40605828,"uuid":"118234791","full_name":"Lision/WKWebViewJavascriptBridge","owner":"Lision","description":"🌉 A Bridge for Sending Messages between Swift and JavaScript in WKWebViews.","archived":false,"fork":false,"pushed_at":"2023-02-21T03:37:10.000Z","size":481,"stargazers_count":1301,"open_issues_count":7,"forks_count":144,"subscribers_count":29,"default_branch":"master","last_synced_at":"2025-03-18T00:43:44.712Z","etag":null,"topics":["bridge","hybrid","javascript","js","jsbridge","swift","webkit","webviewjavascriptbridge","wkwebview","wkwebviewjavascriptbridge"],"latest_commit_sha":null,"homepage":null,"language":"Swift","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Lision.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null}},"created_at":"2018-01-20T11:01:43.000Z","updated_at":"2025-03-17T08:58:01.000Z","dependencies_parsed_at":"2024-01-16T05:11:11.923Z","dependency_job_id":"df704e58-9ab9-4083-a80a-5f461bc27717","html_url":"https://github.com/Lision/WKWebViewJavascriptBridge","commit_stats":{"total_commits":51,"total_committers":6,"mean_commits":8.5,"dds":0.0980392156862745,"last_synced_commit":"51cdc110657e5ad469df712ca79632761d3fe11d"},"previous_names":[],"tags_count":7,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Lision%2FWKWebViewJavascriptBridge","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Lision%2FWKWebViewJavascriptBridge/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Lision%2FWKWebViewJavascriptBridge/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Lision%2FWKWebViewJavascriptBridge/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Lision","download_url":"https://codeload.github.com/Lision/WKWebViewJavascriptBridge/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":245383119,"owners_count":20606265,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["bridge","hybrid","javascript","js","jsbridge","swift","webkit","webviewjavascriptbridge","wkwebview","wkwebviewjavascriptbridge"],"created_at":"2024-07-31T13:00:19.484Z","updated_at":"2025-03-25T05:32:11.588Z","avatar_url":"https://github.com/Lision.png","language":"Swift","readme":"![](Rources/WKWebViewJavascriptBridge.jpg)\n\n[![language](https://img.shields.io/badge/Language-Swift-FFA08F.svg)](https://github.com/apple/swift)\u0026nbsp;\n[![Carthage compatible](https://img.shields.io/badge/Carthage-compatible-FE95AE.svg?style=flat)](https://github.com/Carthage/Carthage)\u0026nbsp;\n[![License MIT](https://img.shields.io/badge/license-MIT-FC89CD.svg?style=flat)](https://raw.githubusercontent.com/Lision/WKWebViewJavascriptBridge/master/LICENSE)\u0026nbsp;\n[![Support](https://img.shields.io/badge/support-iOS%209%2B%20-FB7DEC.svg?style=flat)](https://www.apple.com/nl/ios/)\u0026nbsp;\n[![CocoaPods](https://img.shields.io/cocoapods/p/WKWebViewJavascriptBridge.svg?style=flat)](http://cocoadocs.org/docsets/WKWebViewJavascriptBridge)\u0026nbsp;\n[![Build Status](https://api.travis-ci.org/Lision/WKWebViewJavascriptBridge.svg?branch=master)](https://travis-ci.org/Lision/WKWebViewJavascriptBridge)\u0026nbsp;\n[![CocoaPods](https://img.shields.io/cocoapods/v/WKWebViewJavascriptBridge.svg?style=flat)](http://cocoapods.org/pods/WKWebViewJavascriptBridge)\n\n\u003e [中文介绍](https://github.com/Lision/WKWebViewJavascriptBridge/blob/master/README_ZH-CN.md)\n\n\u003e This project is inspired by [WebViewJavascriptBridge](https://github.com/marcuswestin/WebViewJavascriptBridge)!\n\n# What Can WKWebViewJavascriptBridge Do?\n\nYou can write hybrid modules in just a few lines of code by using WKWebViewJavascriptBridge without the need to be concerned with the underlying messaging implementation.\n\n![](Rources/WKWebViewJavascriptBridgeDemo.gif)\n\n# Why Only Support WKWebView?\n\n### Advantages of WKWebView\n\nIt is well known that **WKWebView loads web pages faster and more efficiently than UIWebView**, and also **doesn't have as much memory overhead** for you.\n\nUnder the current timeline, most iOS apps only support iOS 9.0+.\n\n### UIWebView Cross-Domain Access Vulnerability\n\nThe reason for the iOS platform cross-domain access vulnerability is due to UIWebView turning on the WebKitAllowUniversalAccessFromFileURLs and WebKitAllowFileAccessFromFileURLs options.\n\n**WKWebView default allowFileAccessFromFileURLs and allowUniversalAccessFromFileURLs option is false.**\n\n# Features\n\n- **Swift Support:** Swift 3.2 ~ 5 Support.\n- **High Performance:** The messaging performance is higher than intercept requests.\n- **High Speed:** No need to consider alert box safety timeout.\n- **Lightweight:** This framework contains only 3 files.\n- **Non-intrusive:** There is no need to make the webview class inherit from other base class.\n\n# Usage\n\n### 1. Instantiate WKWebViewJavascriptBridge with a WKWebView: \n\n``` swift\nbridge = WKWebViewJavascriptBridge(webView: webView)\n```\n\n### 2. Register a Handler in Native, and Call a JS Handler: \n\n``` swift\nbridge.register(handlerName: \"testiOSCallback\") { (parameters, callback) in\n    print(\"testiOSCallback called: \\(String(describing: parameters))\")\n    callback?(\"Response from testiOSCallback\")\n}\n\nbridge.call(handlerName: \"testJavascriptHandler\", data: [\"foo\": \"before ready\"], callback: nil)\n```\n\n### 3. Copy and Paste setupWKWebViewJavascriptBridge into Your JS: \n\n``` js\nfunction setupWKWebViewJavascriptBridge(callback) {\n    if (window.WKWebViewJavascriptBridge) { return callback(WKWebViewJavascriptBridge); }\n    if (window.WKWVJBCallbacks) { return window.WKWVJBCallbacks.push(callback); }\n    window.WKWVJBCallbacks = [callback];\n    window.webkit.messageHandlers.iOS_Native_InjectJavascript.postMessage(null)\n}\n```\n\n### 4. Finally, Call setupWKWebViewJavascriptBridge and then Use The Bridge to Register Handlers and Call Native Handlers:\n\n``` js\nsetupWKWebViewJavascriptBridge(function(bridge) {\n\n\t/* Initialize your app here */\n\n\tbridge.registerHandler('testJavascriptHandler', function(data, responseCallback) {\n\t\tconsole.log('iOS called testJavascriptHandler with', data)\n\t\tresponseCallback({ 'Javascript Says':'Right back atcha!' })\n\t})\n\n\tbridge.callHandler('testiOSCallback', {'foo': 'bar'}, function(response) {\n\t\tconsole.log('JS got response', response)\n\t})\n})\n```\n\n# Installation\n\n### Cocoapods\n\n1. Add `pod 'WKWebViewJavascriptBridge', '~\u003e 1.2.0'` to your Podfile.\n2. Run `pod install` or `pod update`.\n3. Add `import WKWebViewJavascriptBridge`.\n\n### Carthage\n\n1. Add `github \"Lision/WKWebViewJavascriptBridge\" ~\u003e 1.2.0` to your Cartfile.\n2. Run `carthage update --platform ios`.\n3. Add the `WKWebViewJavascriptBridge` framework to your project.\n\n### Manually\n\nEither clone the repo and manually add the Files in [WKWebViewJavascriptBridge](https://github.com/Lision/WKWebViewJavascriptBridge/tree/master/WKWebViewJavascriptBridge).\n\n# Requirements\n\nThis framework requires `iOS 9.0+` and `Xcode 9.0+`.\n\n# Contact\n\n- Email: lisionmail@gmail.com\n- Sina: [@Lision](https://weibo.com/5071795354/profile)\n- Twitter: [@Lision](https://twitter.com/LisionChat)\n\n# License\n\n[![](https://camo.githubusercontent.com/5e085da09b057cc65da38f334ab63f0c2705f46a/68747470733a2f2f75706c6f61642e77696b696d656469612e6f72672f77696b6970656469612f636f6d6d6f6e732f7468756d622f662f66382f4c6963656e73655f69636f6e2d6d69742d38387833312d322e7376672f31323870782d4c6963656e73655f69636f6e2d6d69742d38387833312d322e7376672e706e67)](https://raw.githubusercontent.com/Lision/WKWebViewJavascriptBridge/master/LICENSE)\n\nWKWebViewJavascriptBridge is provided under the MIT license. See LICENSE file for details.\n","funding_links":[],"categories":["Swift","OOM-Leaks-Crash","wkwebviewjavascriptbridge","WKWebView"],"sub_categories":["WebView-ProgressBar"],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FLision%2FWKWebViewJavascriptBridge","html_url":"https://awesome.ecosyste.ms/projects/github.com%2FLision%2FWKWebViewJavascriptBridge","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FLision%2FWKWebViewJavascriptBridge/lists"}