marcuswestin/WebViewJavascriptBridge — pull request #44 by peyton (2013-06-06 19:31:01+00:00)
Title: Inject javascript after all other resources load

The -webViewDidFinishLoad method is called after *each* file--html, css, js--is loaded. So right now the bridge javascript is injected every time a new file is loaded, beginning with the initial HTML file. This means there's a chance the bridge javascript is executed before all other javascript is loaded.

The solution is to keep a counter for the number of resources loading, using the -webViewDidStartLoad and -webViewDidFinish/FailLoad methods to keep the counter in sync.

I didn't test the OS X implementation, but it works on iOS.