     }
     controller.addUserScript(WKUserScript(source: source, injectionTime: .atDocumentStart, forMainFrameOnly: false))
     controller.add(Trampoline(delegate: self), name: DMPlayerViewController.messageHandlerEvent)
+    if loggerEnabled {
+        controller.addUserScript(WKUserScript(source: consoleHandler(), injectionTime: .atDocumentStart, forMainFrameOnly: false))
+        controller.add(Trampoline(delegate: self), name: DMPlayerViewController.consoleHandlerEvent)
+    }
     return controller
   }
   
+  private func consoleHandler() -> String {
+    var source = "window.console.log = function(...args) {"
+    source += "window.webkit.messageHandlers.\(DMPlayerViewController.consoleHandlerEvent).postMessage(args);"
+    source += "};"
+    return source
+  }
+    
   private func eventHandler() -> String {
     var source = "window.dmpNativeBridge = {"
     source += "triggerEvent: function(data) {"

    pause()
    webView.stopLoading()
    webView.configuration.userContentController.removeScriptMessageHandler(forName: DMPlayerViewController.messageHandlerEvent)
  }
  
  /// Load a video with ID and optional OAuth token

extension DMPlayerViewController: WKScriptMessageHandler {
 
  open func userContentController(_ userContentController: WKUserContentController, didReceive message: WKScriptMessage) {
    if message.name == DMPlayerViewController.consoleHandlerEvent {
      print(message.body)
    } else {
      guard let event = EventParser.parseEvent(from: message.body) else { return }
      delegate?.player(self, didReceiveEvent: event)
    }
  }
  
}
