Skip to content

Unable to run Html containing Canvas in headless mode using HtmlUnit? #140

Description

@nites67

I am using htmlunit 2.35.0 version to run the html in headless mode. It is working fine with html containing SVG. Now, I am using a custom JavaScript framework called geotoolkit which renders canvas images. I am facing issue when I try to run the html with canvas in headless mode using htmlunit. Please find the below code and error logs. Can anyone please let me know how to fix the issue ? I have also raised the issue on stackoverflow. Here is the link

https://stackoverflow.com/questions/60372112/how-to-use-htmlunit-to-run-html-containing-canvas-in-headless-mode

import java.io.File;
import java.nio.file.Paths;
import com.gargoylesoftware.htmlunit.WebClient;
import com.gargoylesoftware.htmlunit.html.HtmlPage;

String path = Paths.get("Input/Editor").toAbsolutePath()+File.separator+"canvas.html";
WebClient webClient = new WebClient();
File file = new File(path);
HtmlPage page = webClient.getPage(file.toURI().toURL().toString());         
webClient.getOptions().setJavaScriptEnabled(true);
webClient.waitForBackgroundJavaScript(10000);                       
System.out.println(page.asXml());
webClient.close();
Feb 24, 2020 11:22:29 AM com.gargoylesoftware.htmlunit.javascript.host.canvas.CanvasRenderingContext2D createImageData
    INFO: CanvasRenderingContext2D.createImageData() not yet implemented
    Feb 24, 2020 11:22:29 AM com.gargoylesoftware.htmlunit.javascript.DefaultJavaScriptErrorListener scriptException
    SEVERE: Error during JavaScript execution
    ======= EXCEPTION START ========
    EcmaError: lineNumber=[1426] column=[0] lineSource=[null] name=[TypeError] sourceName=[file:/D:/Playground/HeadlessTest/Input/BHAEditor/geotoolkit/geotoolkit.adv.js] message=[TypeError: Cannot read property "width" from undefined (file:/D:/Playground/HeadlessTest/Input/BHAEditor/geotoolkit/geotoolkit.adv.js#1426)]
    com.gargoylesoftware.htmlunit.ScriptException: TypeError: Cannot read property "width" from undefined (file:/D:/Playground/HeadlessTest/Input/BHAEditor/geotoolkit/geotoolkit.adv.js#1426)
        at com.gargoylesoftware.htmlunit.javascript.JavaScriptEngine$HtmlUnitContextAction.run(JavaScriptEngine.java:885)
        at net.sourceforge.htmlunit.corejs.javascript.Context.call(Context.java:617)
        at net.sourceforge.htmlunit.corejs.javascript.ContextFactory.call(ContextFactory.java:534)

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions