Full Featured Google Chrome Dev Tools to JavaFX WebView browser debugging.

Overview

JavaFX WebView Debugger

Via WebSocket connection to Google Chrome Dev Tools

Build status Maven Central status

JavaFx WebView debugging with Chrome Dev tools is highly dependent on Google Chrome version and JavaFx Version.

If you can debug your scripts using another environment, I would highly recommend doing that instead. Only use JavaFx WebView based debugging when you absolutely need to debug the code under this environment.

JavaFx I use for debugging is JetBrains OpenJDK 1.8.0u152 build 1136 which I found to be the most stable for JavaFx WebView debugging. Other versions are more quirky and after starting debug server they need a page reload from the context menu before connecting Chrome Dev Tools. Otherwise, JavaFX crashes and takes the application with it.

I use Chrome version 65.0.3325.181 under OS X. Later versions work but console has no output. I have not investigated what is causing this. You can download older Chrome versions from Google Chrome Older Versions Download (Windows, Linux & Mac)

Here is a teaser screenshot of dev tools running with JavaFX WebView, showing off the console logging from scripts, with caller location for one click navigation to source:

DevTools

Requirements

  • Java 8 (not tested with 9)
  • The project is on Maven: com.vladsch.javafx-webview-debugger
  • dependencies:
    • org.glassfish:javax.json
    • org.jetbrains.annotations
    • com.vladsch.boxed-json
    • org.apache.log4j

Quick Start

Take a look at the Web View Debug Sample application for a working example. You can play with it and debug the embedded scripts before deciding whether you want to instrument your own application for Chrome Dev Tools debugging.

For Maven:

<dependency>
    <groupId>com.vladsch.javafx-webview-debugger</groupId>
    <artifactId>javafx-webview-debugger</artifactId>
    <version>0.7.6</version>
</dependency>

Credit where credit is due

I found out about the possibility of having any debugger for JavaFX WebView in mohamnag/javafx_webview_debugger. That implementation in turn was based on the solution found by Bosko Popovic.

I am grateful to Bosko Popovic for discovering the availability and to Mohammad Naghavi creating an implementation of the solution. Without their original effort this solution would not be possible.

Finally real debugging for JavaFX WebView

Working with JavaScript code in WebView was a debugging nightmare that I tried to avoid. My excitement about having a real debugger diminished when I saw how little was available with a bare-bones implementation due to WebView's lack of a full Dev Tools protocol. The console did not work and none of the console api calls from scripts made it to the Dev Tools console. No commandLineAPI for the same reason. Having to use logs for these is last century.

A proxy to get between Chrome Dev Tools and WebView solved most of the WebView debugging protocol limitations. It also allowed to prevent conditions that caused WebView to crash and bring the rest of the application with it. I don't mean a Java exception. I mean a core dump and sudden exit of the application. For my use cases this is not an acceptable option.

Now the console in the debugger works as expected, with completions, evaluations and console logging from scripts, stepping in/out/over, break points, caller location one click away and initialization debugging to allow pausing of the script before the JSBridge to JavaScript is established. Having a real debugger makes minced meat of script initialization issues.

The current version is the the code I use in my IntelliJ IDEA plugin, Markdown Navigator. With any functionality specific to my project added using the API of this library.

If you are working with JavaFX WebView scripts you need this functionality ASAP. Bugs that took hours to figure out now take literally seconds to minutes without any recompilation or major log reading. Take a look at the Web View Debug Sample application to see what you get and how to add it to your code.

What is working

  • all console functions: assert, clear, count, debug, dir, dirxml, error, exception, group, groupCollapsed, groupEnd, info, log, profile, profileEnd, select, table, time, timeEnd, trace, warn. With added extras to output to the Java console: print, println
  • all commandLineAPI functions implemented by JavaFX WebView: $, $$, $x, dir, dirxml, keys, values, profile, profileEnd, table, monitorEvents, unmonitorEvents, inspect, copy, clear, getEventListeners, $0, $_, $exception
    • Some limitations do exist because Runtime.evaluate is simulated. Otherwise, there was no way to get the stack frame for any console log calls that would result from the evaluation. Mainly, it caused the application to exit with a core dump more often than not. I figured it was more important to have the caller location for console logs than for the commandLineAPI calls.
  • No longer necessary to instrument the page to have JSBridge support code working. Only requires a page reload from WebView or Dev Tools.
  • Ability to debug break on page reload to debug scripts running before JSBridge is established
  • Safely stop debug session from Dev Tools or WebView side. This should have been easy but turned out to be the hardest part to solve. Any wrong moves or dangling references would bring down the whole application with a core-dump message.

In progress

  • highlighting of elements hovered over in the element tree of dev tools. Node resolution is working. Kludged highlighting by setting a class on the element with translucent background color defined instead of using an overlay element or the proper margin, borders, padding and container size.

Not done

  • Debugger paused overlay

Probably not doable

  • profiling not available. Don't know enough about what's needed to say whether it is doable.

JSBridge Provided Debugging Support

The missing functionality from the WebView debugger is implemented via a proxy that gets between chrome dev tools and the debugger to fill in the blanks and to massage the conversation allowing chrome dev tools to do their magic.

For this to work, some JavaScript and the JSBridge instance need to work together to provide the essential glue. The implementation is confined to the initialization script. Most other scripts can be oblivious to whether the JSBridge is established or not. Console log api is one of the missing pieces in the WebView debugger, any console log calls made before the JSBridge to Java is established will not have caller identification and will instead point to the initialization code that played back the cached log calls generated before the connection was established.

The JSBridge implementation also provides a mechanism for data persistence between page reloads. It is generic enough if all the data you need to persist can be JSON.stringify'd because the implementation does a call back to the WebView engine to serialize the passed in state argument. This text will need to be inserted into the generated HTML page to allow scripts access to their state before the JSBridge is hooked in. Scripts can also register for a callback when the JSBridge is established.

The down side of the latter approach, is by the time this happens, WebView has already visually updated the page. If the script is responsible for any visual modification of the page based on persisted state then the unmodified version will flash on screen before the script is run.

Allowing scripts to get their state before JSBridge is established makes for smoother page refresh.

Getting Full Featured Debugging

This requires a little support from the Java to JavaScript bridge and the debug proxy. See the Web View Debug Sample application for an example.

I have not tried it with Java 9, and suspect that the debug protocol has changed and the proxy may not work with it without modifications.

However, these are the instructions to compile for Java 9 WebView debugger access as given by mohamnag/javafx_webview_debugger.

WebEngine.impl_getDebugger() is an internal API and is subject to change which is happened in Java 9. So if you are using Java 9, you need to use following code instead to start the debug server.

ℹ️ This code is now part of DevToolsDebugProxy and if it works on the JRE then debugging will be available. Otherwise, it will not.

Class webEngineClazz = WebEngine.class;

Field debuggerField = webEngineClazz.getDeclaredField("debugger");
debuggerField.setAccessible(true);

Debugger debugger = (Debugger) debuggerField.get(webView.getEngine());
DevToolsDebuggerServer devToolsDebuggerServer.startDebugServer(debugger, WEBVIEW_DEBUG_PORT, 0, null, null);

For this to work, you have to pass this parameter to Java compiler: --add-exports javafx.web/com.sun.javafx.scene.web=ALL-UNNAMED.

As examples, this can be done for Maven as follows:

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-compiler-plugin</artifactId>
    <version>3.7.0</version>
    <configuration>
        <source>9</source>
        <target>9</target>
        <compilerArgs>
            <arg>--add-exports</arg>
            <arg>javafx.web/com.sun.javafx.scene.web=ALL-UNNAMED</arg>
        </compilerArgs>
    </configuration>
 </plugin>

or for IntelliJ under Additional command line parameters in Preferences > Build, Execution, Deployment > Compiler > Java Compiler.

Comments
  • Java 8 problem. Cannot run example files properly.

    Java 8 problem. Cannot run example files properly.

    I have been unable to use Java 8 as my version of intelliJ does not support creating a JavaFX project with a java version less than 11. When using Java11+ I cannot run your jar due to this error. Error: Could not find or load main class com.vladsch.javafx.webview.debugger.WebViewDebugSample. I'm certain that class is there as I've opened your test jar in a decompiler. Is there any way to use this tool with Java 11+? Any suggestions regarding how I can get the Debug Sample to work would be greatly appreciated. Thank you!

    opened by brr53 0
  • Bump junit from 4.12 to 4.13.1

    Bump junit from 4.12 to 4.13.1

    Bumps junit from 4.12 to 4.13.1.

    Release notes

    Sourced from junit's releases.

    JUnit 4.13.1

    Please refer to the release notes for details.

    JUnit 4.13

    Please refer to the release notes for details.

    JUnit 4.13 RC 2

    Please refer to the release notes for details.

    JUnit 4.13 RC 1

    Please refer to the release notes for details.

    JUnit 4.13 Beta 3

    Please refer to the release notes for details.

    JUnit 4.13 Beta 2

    Please refer to the release notes for details.

    JUnit 4.13 Beta 1

    Please refer to the release notes for details.

    Commits
    • 1b683f4 [maven-release-plugin] prepare release r4.13.1
    • ce6ce3a Draft 4.13.1 release notes
    • c29dd82 Change version to 4.13.1-SNAPSHOT
    • 1d17486 Add a link to assertThrows in exception testing
    • 543905d Use separate line for annotation in Javadoc
    • 510e906 Add sub headlines to class Javadoc
    • 610155b Merge pull request from GHSA-269g-pwp5-87pp
    • b6cfd1e Explicitly wrap float parameter for consistency (#1671)
    • a5d205c Fix GitHub link in FAQ (#1672)
    • 3a5c6b4 Deprecated since jdk9 replacing constructor instance of Double and Float (#1660)
    • Additional commits viewable in compare view

    Dependabot compatibility score

    Dependabot will resolve any conflicts with this PR as long as you don't alter it yourself. You can also trigger a rebase manually by commenting @dependabot rebase.


    Dependabot commands and options

    You can trigger Dependabot actions by commenting on this PR:

    • @dependabot rebase will rebase this PR
    • @dependabot recreate will recreate this PR, overwriting any edits that have been made to it
    • @dependabot merge will merge this PR after your CI passes on it
    • @dependabot squash and merge will squash and merge this PR after your CI passes on it
    • @dependabot cancel merge will cancel a previously requested merge and block automerging
    • @dependabot reopen will reopen this PR if it is closed
    • @dependabot close will close this PR and stop Dependabot recreating it. You can achieve the same result by closing it manually
    • @dependabot ignore this major version will close this PR and stop Dependabot creating any more for this major version (unless you reopen the PR or upgrade to it yourself)
    • @dependabot ignore this minor version will close this PR and stop Dependabot creating any more for this minor version (unless you reopen the PR or upgrade to it yourself)
    • @dependabot ignore this dependency will close this PR and stop Dependabot creating any more for this dependency (unless you reopen the PR or upgrade to it yourself)
    • @dependabot use these labels will set the current labels as the default for future PRs for this repo and language
    • @dependabot use these reviewers will set the current reviewers as the default for future PRs for this repo and language
    • @dependabot use these assignees will set the current assignees as the default for future PRs for this repo and language
    • @dependabot use this milestone will set the current milestone as the default for future PRs for this repo and language

    You can disable automated security fix PRs for this repo from the Security Alerts page.

    dependencies 
    opened by dependabot[bot] 0
  • Bump Java-WebSocket from 1.3.7 to 1.5.0

    Bump Java-WebSocket from 1.3.7 to 1.5.0

    Bumps Java-WebSocket from 1.3.7 to 1.5.0.

    Release notes

    Sourced from Java-WebSocket's releases.

    Release 1.5.0

    Breaking Changes

    This release requires API Level 1.7.

    Security

    This release contains a security fix for CVE-2020-11050.

    Take a look at the advisory here for more information.

    Notable changes:

    • Issue 574 - Implementation of per message deflate extension (PR 866)
    • Issue 997 - Access to SSLParameters used by the WebSocketClient (PR 1000)
    • PR 1001 - Allow user to specify max number of pending connections to a server

    Check out the changelog and the milestone for more information.

    A special thanks to all the contributors of this release: @haruntuncay @PhilipRoman

    Release 1.4.1

    Notable changes:

    • PR 906 - Implemented a custom DNS resolver, see #859
    • PR 893 - Provide a way to access the SSLSession of a websocket instance
    • PR 944 - Add ability to customize ping messages with custom data
    • PR 868 - Add a way to put additional headers to handshake for connecting/reconnecting, see #865
    • PR 971 - Enabled OSGi metadata in MANIFST-MF for created JAR

    Check out the changelog and the milestone for more information.

    A special thanks to all the contributors of this release:

    Release 1.4.0

    Breaking changes:

    • Issue 753 - Breaking changes in 1.4
    • Issue 670 - Use a logging framework such as as SLF4J instead of System.out.println (PR 754)
    ... (truncated)
    Changelog

    Sourced from Java-WebSocket's changelog.

    Version Release 1.5.0 (2020/05/06)

    Breaking Changes

    This release requires API Level 1.7.

    Security

    This release contains a security fix for CVE-2020-11050.

    Take a look at the advisory here for more information.

    New Features

    • Issue 574 - Implementation of per message deflate extension (PR 866)
    • PR 866 - Add PerMessageDeflate Extension support, see #574
    • Issue 997 - Access to SSLParameters used by the WebSocketClient (PR 1000)
    • Issue 574 - Implementation of per message deflate extension (PR 866)
    • PR 1001 - Allow user to specify max number of pending connections to a server
    • PR 1000 - SSLParameters for WebSocketClient
    • PR 866 - Add PerMessageDeflate Extension support, see #574

    In this release 3 issues and 4 pull requests were closed.

    ###############################################################################

    Version Release 1.4.1 (2020/03/12)

    Bugs Fixed

    • Issue 940 - WebSocket handshake fails over WSS, if client uses TLS False Start (PR 943)
    • Issue 921 - ConcurrentModificationException when looping connections
    • Issue 905 - IOException wrapped in InternalError not handled properly (PR 901)
    • Issue 900 - OnClose is not called when client disconnect (PR 914)
    • Issue 869 - Lost connection detection is sensitive to changes in system time (PR 878)
    • Issue 665 - Data read with end of SSL handshake is discarded (PR 943)
    • PR 943 - Merge pull request #943 from da-als/master
    • PR 922 - Fix ConcurrentModificationException when iterating through connection
    • PR 914 - Merge pull request #914 from marci4/Issue900
    • PR 902 - ConcurrentModificationException when using broadcast
    • PR 901 - fix when proxy tunneling failed (IOException is hidden) JDK-8173
    • PR 878 - Replace TimerTask with ScheduledExecutorService

    New Features

    • Issue 969 - Loggers should be declared non-static (PR 970)
    • Issue 962 - Improvements in socket connect to server (PR 964)
    • Issue 941 - How to send customized ping message on connectionLostTimeout interval (PR 944)
    • Issue 890 - Would like to get SSLSession from WebSocket on server to examine client certificates (PR 893)
    • Issue 865 - Append new headers to the client when reconnecting
    ... (truncated)
    Commits
    • 54ca4f4 Merge pull request #1009 from marci4/UpdateChangelog1.5.0
    • 046f24b Update CHANGELOG.md
    • 63222d1 Merge pull request #1006 from marci4/FixTestPerMessageDeflate
    • 1e2e890 Update PerMessageDeflateExtensionTest.java
    • 9d890db Merge pull request #1001 from TooTallNate/issue-991
    • cab3fda Merge pull request #1000 from marci4/Issue997
    • ca38a4b Add "since 1.5.0" tag to new methods
    • 3ebbe21 Allow user to specify max number of pending connections to a server
    • 0670985 Rework after review
    • 2dbe2d3 API for SSLParameters
    • Additional commits viewable in compare view

    Dependabot compatibility score

    Dependabot will resolve any conflicts with this PR as long as you don't alter it yourself. You can also trigger a rebase manually by commenting @dependabot rebase.


    Dependabot commands and options

    You can trigger Dependabot actions by commenting on this PR:

    • @dependabot rebase will rebase this PR
    • @dependabot recreate will recreate this PR, overwriting any edits that have been made to it
    • @dependabot merge will merge this PR after your CI passes on it
    • @dependabot squash and merge will squash and merge this PR after your CI passes on it
    • @dependabot cancel merge will cancel a previously requested merge and block automerging
    • @dependabot reopen will reopen this PR if it is closed
    • @dependabot close will close this PR and stop Dependabot recreating it. You can achieve the same result by closing it manually
    • @dependabot ignore this major version will close this PR and stop Dependabot creating any more for this major version (unless you reopen the PR or upgrade to it yourself)
    • @dependabot ignore this minor version will close this PR and stop Dependabot creating any more for this minor version (unless you reopen the PR or upgrade to it yourself)
    • @dependabot ignore this dependency will close this PR and stop Dependabot creating any more for this dependency (unless you reopen the PR or upgrade to it yourself)
    • @dependabot use these labels will set the current labels as the default for future PRs for this repo and language
    • @dependabot use these reviewers will set the current reviewers as the default for future PRs for this repo and language
    • @dependabot use these assignees will set the current assignees as the default for future PRs for this repo and language
    • @dependabot use this milestone will set the current milestone as the default for future PRs for this repo and language

    You can disable automated security fix PRs for this repo from the Security Alerts page.

    dependencies 
    opened by dependabot[bot] 0
  • Source Maps troubleshooting

    Source Maps troubleshooting

    I integrated by copy & pasting from the sample code, I'm loading a file from the file system and it's a webpack environment. Source maps show when the same code is accessed via a web server and a Chrome instance. But when loading with WebView, the source maps are not found, and it's hard to debug a minified version. Is there any way to make source maps accessible via the debugger?

    opened by bolerio 2
  • Java 9 Support

    Java 9 Support

    The following example needs to be updated:

    Class webEngineClazz = WebEngine.class;
    
    Field debuggerField = webEngineClazz.getDeclaredField("debugger");
    debuggerField.setAccessible(true);
    
    Debugger debugger = (Debugger) debuggerField.get(webView.getEngine());
    DevToolsDebuggerServer devToolsDebuggerServer.startDebugServer(debugger, 51742, 1);
    

    To:

    Class webEngineClazz = WebEngine.class;
    
    Field debuggerField = webEngineClazz.getDeclaredField("debugger");
    debuggerField.setAccessible(true);
    
    Debugger debugger = (Debugger) debuggerField.get(webView.getEngine());
    DevToolsDebuggerServer bridge = new DevToolsDebuggerServer(debugger, WEBVIEW_DEBUG_PORT, 0, null, null);
    

    Using this class is not well documented, and just something I've used from the previous repo this was based upon.

    When using the new class DevToolsJsBridge, as shown in the example, there's no way to pass a Debugger instance. The underlying method it uses, .impl_getDebugger(), on WebEngine is not supported in Java 9 (and presumed above).

    Would it be possible to allow support to either pass in a Debugger, use reflection to extract the debugger field or check for which method is available (Java 9 seems to have getDebugger()?

    Also what is the difference between DevToolsJsBridge and DevToolsDebuggerServer ?

    opened by marcuscraske 2
Owner
Vladimir Schneider
Vladimir Schneider
JavaFX Webview of JSON resume files

ResumeFX renders a JavaFX view of .json file that follows jsonresume.org standard and has the necessary configuration to be embedded in the web browser thanks to JPro.

TangoraBox 7 Dec 15, 2021
JavaFX micro-framework that follows MVVM Pattern with Google Guice dependency Injection

ReactiveDeskFX (JavaFX and Google Guice MVVM Pattern micro-framework) JavaFX micro-framework to develop very fast JavaFX components with minimal code

TangoraBox 3 Jan 9, 2022
A collection of tools and libraries for easier development on the JavaFX platform!

This project is archived I do not realistically have the time to take care of this project, unfortunately. It originally was built along a Twitter cli

Tristan Deloche 100 Dec 13, 2022
A small tools to play with JavaFX Color.derive() function - allows to create custom colors and to save those in color palettes.

DeriveColorsFX This is not a serious application. Its a small tool where I just played with the method Color::deriveColor provided by JavaFX. Also its

Oliver Löffler 11 Oct 9, 2022
TMU is very simple app for posting your digital manga as article into Telegraph for further reading using any browser or in Telegram with Instant View.

TMU is very simple app for posting your digital manga as article into Telegraph for further reading using any browser or in Telegram with Instant View. App may be very helpful for content translators that searching easy way to share their work.

null 5 Oct 6, 2022
A Time Series Data Browser

Contents What is binjr? Features Getting started Trying it out Getting help Contributing How is it licensed? What is binjr? binjr is a time series bro

binjr 206 Dec 17, 2022
Tray Icon implementation for JavaFX applications. Say goodbye to using AWT's SystemTray icon, instead use a JavaFX Tray Icon.

FXTrayIcon Library intended for use in JavaFX applications that makes adding a System Tray icon easier. The FXTrayIcon class handles all the messy AWT

Dustin Redmond 248 Dec 30, 2022
Lib-Tile is a multi Maven project written in JavaFX and NetBeans IDE 8 and provides the functionalities to use and handle easily Tiles in your JavaFX application.

Lib-Tile Intention Lib-Tile is a multi Maven project written in JavaFX and NetBeans IDE and provides the functionalities to use and handle easily Tile

Peter Rogge 13 Apr 13, 2022
DataFX - is a JavaFX frameworks that provides additional features to create MVC based applications in JavaFX by providing routing and a context for CDI.

What you’ve stumbled upon here is a project that intends to make retrieving, massaging, populating, viewing, and editing data in JavaFX UI controls ea

Guigarage 110 Dec 29, 2022
HUAWEI 3D Modeling Kit project contains a sample app. Guided by this demo, you will be able to implement full 3D Modeling Kit capabilities, including 3D object reconstruction and material generation.

HUAWEI 3D Modeling Kit Sample English | 中文 Introduction This project includes apps developed based on HUAWEI 3D Modeling Kit. The project directory is

HMS 59 Jan 1, 2023
Terminal GUI library for simple ANSI console tools and graphical interfaces with Windows/Linux support

TerminalCore Terminal GUI library for Windows/Linux. This library contains all colors as ascii codes, native functions of the respective operating sys

Pascal 3 Oct 19, 2022
Collection of Binding helpers for JavaFX(8)

Advanced-Bindings for JavaFX (8) advanced-bindings is a collection of useful helpers and custom binding implementations to simplify the development of

Manuel Mauky 63 Nov 19, 2022
Docking framework for JavaFX platform

Docking framework for JavaFX platform AnchorFX is a gratis and open source library for JavaFX to create graphical interfaces with docking features Anc

Alessio Vinerbi 197 Oct 15, 2022
A library of +70 ready-to-use animations for JavaFX

AnimateFX A library of ready-to-use animations for JavaFX Features: Custom animations Custom interpolators Play/Stop animation Play an animation after

Loïc Sculier 366 Jan 5, 2023
BootstrapFX: Bootstrap for JavaFX

BootstrapFX BootstrapFX is a partial port of Twitter Bootstrap for JavaFX. It mainly provides a CSS stylesheet that closely resembles the original whi

Kordamp 810 Dec 28, 2022
A Java framework for creating sophisticated calendar views (JavaFX 8, 9, 10, and 11)

CalendarFX A Java framework for creating sophisticated calendar views based on JavaFX. A detailed developer manual can be found online: CalendarFX 8 D

DLSC Software & Consulting GmbH 660 Jan 6, 2023
Allow runtime modification of JavaFX CSS

cssfx ⚠ WARNING ⚠ In version 11.3.0 we have relocated & refactored the project. maven groupId has been changed to fr.brouillard.oss java module name h

Matthieu Brouillard 134 Jan 2, 2023
A JavaFX UI framework to create fully customized undecorated windows

CustomStage A JavaFX undecorated stage which can fully be customized Donations If this project is helpful to you and love my work and feel like showin

Oshan Mendis 186 Jan 6, 2023