     }
   }
   
+  func webViewWebContentProcessDidTerminate(_ webView: WKWebView) {
+    self.sendNotification(message: "browser.terminated")
+  }
+  
   /*************************************************************************************
                                 Agent socket interface
    *************************************************************************************/

  }
  
  func startBrowser(id:String) {
    if webView != nil {
      webView!.navigationDelegate = nil
      webView!.removeFromSuperview()
      webView = nil
    }
    webView = WKWebView()
    webView!.frame = self.view.bounds
    self.view.addSubview(webView!)
    webView!.loadHTMLString(startPage, baseURL: URL(string: "http://www.webpagetest.org"))
    hasOrange = true
    webView!.navigationDelegate = self
    title = ""
    sendMessage(id:id, message:"OK")
  }
  
  func closeBrowser(id:String) {
    if webView != nil {
      webView!.navigationDelegate = nil
      webView!.removeFromSuperview()
      webView = nil
    }
    hasOrange = false
    title = "iWptBrowser"
    sendMessage(id:id, message:"OK")

  /*************************************************************************************
                                  Webview interfaces
   *************************************************************************************/
  override func observeValue(forKeyPath keyPath: String?, of object: Any?, change: [NSKeyValueChangeKey : Any]?, context: UnsafeMutableRawPointer?) {
    if keyPath != nil {
      switch keyPath! {
      case "estimatedProgress":
        if webView != nil {
          sendNotification(message:"page.progress", data:"\(webView!.estimatedProgress)")
        }
      case "title":
        if webView != nil && webView!.title != nil {
          title = webView!.title!
          sendNotification(message:"page.title", data: webView!.title!)
        }
      case "isLoading":
        if webView != nil {
          if webView!.isLoading {
            sendNotification(message: "page.loading")
          } else {
            sendNotification(message: "page.loadingFinished")
          }
        }
      default:
        self.log("Unexpected observation: \(keyPath!)")
      }
    }
  }
  
  func webView(_ webView: WKWebView, didCommit navigation: WKNavigation!) {
    self.sendNotification(message: "page.didCommit")
  }
  
  func webView(_ webView: WKWebView, didStartProvisionalNavigation navigation: WKNavigation!) {
    self.sendNotification(message: "page.didStartProvisionalNavigation")
  }
  
  func webView(_ webView: WKWebView, didReceiveServerRedirectForProvisionalNavigation navigation: WKNavigation!) {
    self.sendNotification(message: "page.didReceiveServerRedirectForProvisionalNavigation")
  }
  
  func webView(_ webView: WKWebView, didFinish navigation: WKNavigation!) {
    self.sendNotification(message: "page.didFinish")
  }
  
  func webView(_ webView: WKWebView, didFail navigation: WKNavigation!, withError: Error) {
    self.sendNotification(message: "page.didFail", data:"\(withError)")
  }

  func webView(_ webView: WKWebView, didFailProvisionalNavigation navigation: WKNavigation!, withError: Error) {
    self.sendNotification(message: "page.didFailProvisionalNavigation", data:"\(withError)")
  }

  func webView(_ webView: WKWebView, decidePolicyFor navigationAction: WKNavigationAction, decisionHandler: @escaping (WKNavigationActionPolicy) -> Void) {
    let url = navigationAction.request.url!
    if navigationAction.targetFrame == nil || navigationAction.targetFrame!.isMainFrame {
