JAVAFX / WebView / WebEngine FireBugLite or Some other debugger?

我的未来我决定 提交于 2019-11-26 22:35:57
roosevelt

I was able to fix the problem. It seems like the current stable version of FirebugLite works well for traditional browsers but something is different that makes it fail for an application viewed by the JAVAFX WebView.

I was able to add Firebug to my application by using an uncompressed version of FirebugLite

<script type='text/javascript' src='http://getfirebug.com/releases/lite/1.2/firebug-lite-compressed.js'></script>

The solution came from: Testing IE6 with Firebug Lite

The command you provided in your question works for me (well mostly).

Perhaps you are not waiting until the WebView has loaded a document before trying to trigger Firebug.

For example, the following code will launch Firebug Lite for me (JavaFX 8b103, OS X 10.8).

import javafx.application.Application;
import javafx.beans.value.ChangeListener;
import javafx.beans.value.ObservableValue;
import javafx.scene.Scene;
import javafx.scene.web.WebEngine;
import javafx.scene.web.WebView;
import javafx.stage.Stage;
import org.w3c.dom.Document;

public class WebViewWithDebugger extends Application {
  public static void main(String[] args) { launch(args); }
  @Override public void start(Stage primaryStage) {
    final WebView webView = new WebView();
    final WebEngine engine = webView.getEngine();
    engine.load("http://docs.oracle.com/javafx/2/get_started/animation.htm");
    engine.documentProperty().addListener(new ChangeListener<Document>() {
      @Override public void changed(ObservableValue<? extends Document> prop, Document oldDoc, Document newDoc) {
        enableFirebug(engine);
      }
    });
    primaryStage.setScene(new Scene(webView));
    primaryStage.show();
  }

  /**
   * Enables Firebug Lite for debugging a webEngine.
   * @param engine the webEngine for which debugging is to be enabled.
   */
  private static void enableFirebug(final WebEngine engine) {
    engine.executeScript("if (!document.getElementById('FirebugLite')){E = document['createElement' + 'NS'] && document.documentElement.namespaceURI;E = E ? document['createElement' + 'NS'](E, 'script') : document['createElement']('script');E['setAttribute']('id', 'FirebugLite');E['setAttribute']('src', 'https://getfirebug.com/' + 'firebug-lite.js' + '#startOpened');E['setAttribute']('FirebugLite', '4');(document['getElementsByTagName']('head')[0] || document['getElementsByTagName']('body')[0]).appendChild(E);E = new Image;E['setAttribute']('src', 'https://getfirebug.com/' + '#startOpened');}"); 
  }
}

Firebug Lite itself doesn't seem particularly great at debugging web pages (at least under WebView for me). The console, html, css and dom panels seemed to be fine, as well as the inspect option. So some useful info there. The script portion showed the scripts but I didn't see anyway to set breakpoints, watches, etc in the scripts.

alistair

I found with the JavaFX Webview that the best way of quickly debugging javascript was to do the following:

webView.getEngine().setOnAlert(new EventHandler<WebEvent<String>>() {
    @Override 
    public void handle(WebEvent<String> event) {
        System.out.println(event.getData());
    }
});  

That pipes through all your alert("whatever"); pieces of code so you can see what's going on.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!