JavaFX WebEngine crashes after loading a web page with a video tag

223 Views Asked by At

I'm new to Java and developing a background previewer application for steam profiles in JavaFX to improve myself in Java.

After loading any steam profile page with an animated background into the WebEngine, every action such as scrolling down/up and hovering over any element causes the page to reload and this makes the application extremely slow and sometimes the application crashes after a short time.

How can I solve this problem? Is there a dependency I need to add for video playback other than javafx-web?

The Steam profile url that I loaded to the WebEngine

Error Message: Process finished with exit code -1073741819 (0xC0000005)


Code Snippet

I tried running the app with and without the video sources, but in both cases I still had the problem.

The code to remove the video sources is below the "Removing header and animated background video sources" comment line

package org.example;

import javafx.application.Application;
import javafx.stage.Stage;
import javafx.scene.Scene;
import javafx.scene.layout.StackPane;
import javafx.scene.web.WebView;
import javafx.scene.web.WebEngine;
import org.w3c.dom.Document;
import javafx.concurrent.Worker;


/**
 * JavaFX App
 */
public class App extends Application {

    @Override
    public void start(Stage stage) {
        stage.setTitle("Steam Assistant");
        stage.setMaximized(true);

        WebView browser = new WebView();
        WebEngine webEngine = browser.getEngine();
        webEngine.load("https://steamcommunity.com/id/voscope/");

        // Removing header and animated background video sources
        /*webEngine.getLoadWorker().stateProperty().addListener((observable, oldState, newState) -> {
            if (newState == Worker.State.SUCCEEDED) {
                Document document = webEngine.getDocument();

                var header = document.getElementById("global_header");
                header.setAttribute("style", "display: none;");

                var video = document.getElementsByTagName("video").item(0);
                video.removeChild(video.getFirstChild());

                webEngine.executeScript("document.getElementsByTagName('video')[0].load()");
            }
        });*/

        var scene = new Scene(new StackPane(browser), 640, 480);
        stage.setScene(scene);
        stage.show();
    }

    public static void main(String[] args) {
        launch();
    }

}

Maven Properties

Property Key Property Value
archetypeGroupId org.openjfx
archetypeArtifactId javafx-archetype-simple
archetypeVersion 0.0.6
javafx-version 19

pom.xml - I added the latest version (19) of javafx-web dependency

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <groupId>org.example</groupId>
    <artifactId>HelloFX</artifactId>
    <version>1.0-SNAPSHOT</version>
    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <maven.compiler.source>11</maven.compiler.source>
        <maven.compiler.target>11</maven.compiler.target>
    </properties>
    <dependencies>
        <dependency>
            <groupId>org.openjfx</groupId>
            <artifactId>javafx-controls</artifactId>
            <version>19</version>
        </dependency>
        <dependency>
            <groupId>org.openjfx</groupId>
            <artifactId>javafx-web</artifactId>
            <version>19</version>
        </dependency>
    </dependencies>
    <build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>3.8.0</version>
                <configuration>
                    <release>11</release>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.openjfx</groupId>
                <artifactId>javafx-maven-plugin</artifactId>
                <version>0.0.6</version>
                <executions>
                    <execution>
                        <!-- Default configuration for running -->
                        <!-- Usage: mvn clean javafx:run -->
                        <id>default-cli</id>
                        <configuration>
                            <mainClass>org.example.App</mainClass>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>
</project>
0

There are 0 best solutions below