WKWebViewJavascriptBridge profile

WKWebViewJavascriptBridge – elegant iOS interact with JS layers framework (Swift)

Making project address: WKWebViewJavascriptBridge

WKWebViewJavascriptBridge can do for you?

You can use WKWebViewJavascriptBridge write a few lines of code to achieve through hybrid modules, without having to concern at the bottom of the iOS with JS messaging implementation.

Why do you want to open source WKWebViewJavascriptBridge

In fact, when reading the source code of WebView javascriptBridge, I found that it was forced to use the interception of Request in order to be compatible with Mac OS X WebView and iOS UIWebView and WKWebView components Messaging between iOS and JS.

At that time, I thought that WKWebView should be a Bridge level framework for WKWebView, but for various reasons (mainly lazy, laugh), it has not been put into practice.

Until you find the UIWebView cross-domain access holes Later, made up his mind to write WKWebViewJavascriptBridge framework.

As for why use Swift as WKWebViewJavascriptBridge implementation language? Mainly because Swift 3.2 to 4.0 migration changes have been relatively small, it can be considered that Swift gradually tends to be stable (ok, I admit that it is because I have watched Swift more recently and want to improve my Swift level).

Why only WKWebView?

The advantage of WKWebView

As we all know, WKWebView loads web pages faster and more efficiently than UIWebView without too much memory overhead.

At this point in time, most iOS apps are based on iOS 9.0+, this is the era of WKWebView.

UIWebView cross-domain access vulnerability

IOS cross-domain access holes cause is due to the default opens the UIWebView WebKitAllowUniversalAccessFromFileURLs and WebKitAllowFileAccessFromFileURLs options.

In contrast, WKWebView allowFileAccessFromFileURLs and allowUniversalAccessFromFileURLs option to false by default.

For more on UIWebView cross-domain access vulnerabilities, click here to learn more.

features

  • Swift: Supports Swift 3.2 to 4.
  • High performance: Message passing performance is better than traditional implementations (intercepting Requests).
  • High speed: No need to consider Alert Box security timeout.
  • Lightweight: Frame removed automatically generated.hThere are only three files.
  • Non-invasive: No rewriting requiredwebView(this assumes that most iOS apps under the current time node have already migrated from UIWebView to WKWebView, which will have to be done sooner or later, right?) .

About WKWebViewJavascriptBridge support for the Objective – C

About WKWebViewJavascriptBridge support for the Objective – C, I have the following views (applicable to all Swift framework) :

  • If before the project is the Objective – C with Swift, mixed WKWebViewJavascriptBridge can be directly used.
  • If the project did not mix with Swift before and has no plans to do so later, please contact me so I can write an Objective-C version of the implementation.

Write in the last

If you’ve already seen it, please check out the project page anyway!

At the beginning of the project, welcome PR!


Supplement ~ I set up a technical exchange wechat group, want to know more friends in it! If you have any questions about the article or encounter some small problems in your work, you can find me or other friends in the group to communicate and discuss. Looking forward to your joining us

Emmmmm.. Because the number of wechat group is over 100, it is not possible to scan the code into the group, so please scan the qr code above to pay attention to the public number into the group.