title: How to debug javascript code inside a WKWebView
body: <p>I'm having some trouble with running a webapp in a WKWebView (specifically: some buttons are not responding). I used <a href="http://www.kinderas.com/technology/2014/6/7/getting-started-with-wkwebview-using-swift-in-ios-8" rel="noreferrer">this tutorial</a> as a guide and did succeed in having the webview display my webapp. So now <strong>I want to debug the javascript code.</strong></p>
  
  <p>I know the webapp works, since I've tried it in both an android webview as well as countless browsers (including safari on the iPad simulator I'm using). After some quick googling, I found out <a href="https://stackoverflow.com/questions/2767902/what-are-some-methods-to-debug-javascript-inside-of-a-uiwebview">how to debug javascript inside a UIWebView using Safari</a>. Sadly This doesn't seem to work with the new WKWebView.</p>
  
  <p>When I navigate to <code>Develop-&gt;iPad Simulator</code> I'm told that there are 'No Inspectable Applications'. I've tried the very same thing with a simple app with a UIWebView and debugging through safari works perfectly there.</p>
  
  <p><strong>Is there a way to debug javascript code within a WKWebView?</strong></p>
  
  <p>To reproduce my problems (using swift), start a new single screen project in xCode 6, copy the code (courtesy of <a href="http://www.kinderas.com/" rel="noreferrer">kinderas</a>) provided below in your <code>ViewController.swift</code> file and drag the outlet to <code>View</code> under <code>View Controller</code> in the document outline in the <code>Main.storyboard</code> file. Refer to the tutorial I linked above in case of confusion.</p>
  
  <pre><code>import UIKit
  import WebKit
  
  class ViewController: UIViewController {
  
      @IBOutlet var containerView : UIView! = nil
      var webView: WKWebView?
  
      override func loadView() {
          super.loadView()
  
          self.webView = WKWebView()
          self.view = self.webView!
      }
  
      override func viewDidLoad() {
          super.viewDidLoad()
  
          var url = NSURL(string:"http://www.kinderas.com/")
          var req = NSURLRequest(URL:url)
          self.webView!.loadRequest(req)
      }
  
      override func didReceiveMemoryWarning() {
          super.didReceiveMemoryWarning()
      }
  
  }
  </code></pre>