Как использовать HtmlUnit для запуска Html, содержащего Canvas, в автономном режиме? - PullRequest
0 голосов
/ 24 февраля 2020

Я использую версию htmlunit 2.35.0 для запуска html в режиме без головы. Он отлично работает с html, содержащим SVG. Теперь я использую пользовательский фреймворк JavaScript, называемый geotoolkit, который отображает изображения холста. Я сталкиваюсь с проблемой, когда пытаюсь запустить html с canvas в режиме без головы, используя htmlunit. Пожалуйста, найдите ниже код и журналы ошибок. Может кто-нибудь, пожалуйста, дайте мне знать, как решить проблему?

код

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)
        at com.gargoylesoftware.htmlunit.javascript.HtmlUnitContextFactory.callSecured(HtmlUnitContextFactory.java:336)
        at com.gargoylesoftware.htmlunit.javascript.JavaScriptEngine.callFunction(JavaScriptEngine.java:814)
        at com.gargoylesoftware.htmlunit.javascript.JavaScriptEngine.callFunction(JavaScriptEngine.java:786)
        at com.gargoylesoftware.htmlunit.html.HtmlPage.executeJavaScriptFunction(HtmlPage.java:2534)
        at com.gargoylesoftware.htmlunit.html.HtmlPage.executeJavaScriptFunction(HtmlPage.java:2527)
        at com.gargoylesoftware.htmlunit.javascript.host.event.EventListenersContainer.executeEventListeners(EventListenersContainer.java:342)
        at com.gargoylesoftware.htmlunit.javascript.host.event.EventListenersContainer.executeAtTargetListeners(EventListenersContainer.java:379)
        at com.gargoylesoftware.htmlunit.javascript.host.event.EventTarget.executeEventLocally(EventTarget.java:100)
        at com.gargoylesoftware.htmlunit.html.HtmlScript.executeEvent(HtmlScript.java:414)
        at com.gargoylesoftware.htmlunit.html.HtmlScript.executeScriptIfNeeded(HtmlScript.java:380)
        at com.gargoylesoftware.htmlunit.html.HtmlScript$2.execute(HtmlScript.java:247)
        at com.gargoylesoftware.htmlunit.javascript.JavaScriptEngine.doProcessPostponedActions(JavaScriptEngine.java:936)
        at com.gargoylesoftware.htmlunit.javascript.JavaScriptEngine.access$200(JavaScriptEngine.java:104)
        at com.gargoylesoftware.htmlunit.javascript.JavaScriptEngine$HtmlUnitContextAction.run(JavaScriptEngine.java:880)
        at net.sourceforge.htmlunit.corejs.javascript.Context.call(Context.java:617)
        at net.sourceforge.htmlunit.corejs.javascript.ContextFactory.call(ContextFactory.java:534)
        at com.gargoylesoftware.htmlunit.javascript.HtmlUnitContextFactory.callSecured(HtmlUnitContextFactory.java:336)
        at com.gargoylesoftware.htmlunit.javascript.JavaScriptEngine.callFunction(JavaScriptEngine.java:814)
        at com.gargoylesoftware.htmlunit.javascript.JavaScriptEngine.callFunction(JavaScriptEngine.java:786)
        at com.gargoylesoftware.htmlunit.html.HtmlPage.executeJavaScriptFunction(HtmlPage.java:2534)
        at com.gargoylesoftware.htmlunit.html.HtmlPage.executeJavaScriptFunction(HtmlPage.java:2527)
        at com.gargoylesoftware.htmlunit.javascript.host.event.EventListenersContainer.executeEventListeners(EventListenersContainer.java:342)
        at com.gargoylesoftware.htmlunit.javascript.host.event.EventListenersContainer.executeAtTargetListeners(EventListenersContainer.java:379)
        at com.gargoylesoftware.htmlunit.javascript.host.event.EventTarget.executeEventLocally(EventTarget.java:100)
        at com.gargoylesoftware.htmlunit.html.HtmlScript.executeEvent(HtmlScript.java:414)
        at com.gargoylesoftware.htmlunit.html.HtmlScript.executeScriptIfNeeded(HtmlScript.java:380)
        at com.gargoylesoftware.htmlunit.html.HtmlScript$2.execute(HtmlScript.java:247)
        at com.gargoylesoftware.htmlunit.javascript.JavaScriptEngine.doProcessPostponedActions(JavaScriptEngine.java:936)
        at com.gargoylesoftware.htmlunit.javascript.JavaScriptEngine.access$200(JavaScriptEngine.java:104)
        at com.gargoylesoftware.htmlunit.javascript.JavaScriptEngine$HtmlUnitContextAction.run(JavaScriptEngine.java:880)
        at net.sourceforge.htmlunit.corejs.javascript.Context.call(Context.java:617)
        at net.sourceforge.htmlunit.corejs.javascript.ContextFactory.call(ContextFactory.java:534)
        at com.gargoylesoftware.htmlunit.javascript.HtmlUnitContextFactory.callSecured(HtmlUnitContextFactory.java:336)
        at com.gargoylesoftware.htmlunit.javascript.JavaScriptEngine.callFunction(JavaScriptEngine.java:814)
        at com.gargoylesoftware.htmlunit.javascript.JavaScriptEngine.callFunction(JavaScriptEngine.java:786)
        at com.gargoylesoftware.htmlunit.html.HtmlPage.executeJavaScriptFunction(HtmlPage.java:2534)
        at com.gargoylesoftware.htmlunit.html.HtmlPage.executeJavaScriptFunction(HtmlPage.java:2527)
        at com.gargoylesoftware.htmlunit.javascript.host.event.EventListenersContainer.executeEventListeners(EventListenersContainer.java:342)
        at com.gargoylesoftware.htmlunit.javascript.host.event.EventListenersContainer.executeAtTargetListeners(EventListenersContainer.java:379)
        at com.gargoylesoftware.htmlunit.javascript.host.event.EventTarget.executeEventLocally(EventTarget.java:100)
        at com.gargoylesoftware.htmlunit.html.HtmlScript.executeEvent(HtmlScript.java:414)
        at com.gargoylesoftware.htmlunit.html.HtmlScript.executeScriptIfNeeded(HtmlScript.java:380)
        at com.gargoylesoftware.htmlunit.html.HtmlScript$2.execute(HtmlScript.java:247)
        at com.gargoylesoftware.htmlunit.javascript.JavaScriptEngine.doProcessPostponedActions(JavaScriptEngine.java:936)
        at com.gargoylesoftware.htmlunit.javascript.JavaScriptEngine.access$200(JavaScriptEngine.java:104)
        at com.gargoylesoftware.htmlunit.javascript.JavaScriptEngine$HtmlUnitContextAction.run(JavaScriptEngine.java:880)
        at net.sourceforge.htmlunit.corejs.javascript.Context.call(Context.java:617)
        at net.sourceforge.htmlunit.corejs.javascript.ContextFactory.call(ContextFactory.java:534)
        at com.gargoylesoftware.htmlunit.javascript.HtmlUnitContextFactory.callSecured(HtmlUnitContextFactory.java:336)
        at com.gargoylesoftware.htmlunit.javascript.JavaScriptEngine.callFunction(JavaScriptEngine.java:814)
        at com.gargoylesoftware.htmlunit.javascript.JavaScriptEngine.callFunction(JavaScriptEngine.java:786)
        at com.gargoylesoftware.htmlunit.html.HtmlPage.executeJavaScriptFunction(HtmlPage.java:2534)
        at com.gargoylesoftware.htmlunit.html.HtmlPage.executeJavaScriptFunction(HtmlPage.java:2527)
        at com.gargoylesoftware.htmlunit.javascript.host.event.EventListenersContainer.executeEventListeners(EventListenersContainer.java:342)
        at com.gargoylesoftware.htmlunit.javascript.host.event.EventListenersContainer.executeAtTargetListeners(EventListenersContainer.java:379)
        at com.gargoylesoftware.htmlunit.javascript.host.event.EventTarget.executeEventLocally(EventTarget.java:100)
        at com.gargoylesoftware.htmlunit.html.HtmlScript.executeEvent(HtmlScript.java:414)
        at com.gargoylesoftware.htmlunit.html.HtmlScript.executeScriptIfNeeded(HtmlScript.java:380)
        at com.gargoylesoftware.htmlunit.html.HtmlScript$2.execute(HtmlScript.java:247)
        at com.gargoylesoftware.htmlunit.javascript.JavaScriptEngine.doProcessPostponedActions(JavaScriptEngine.java:936)
        at com.gargoylesoftware.htmlunit.javascript.JavaScriptEngine.access$200(JavaScriptEngine.java:104)
        at com.gargoylesoftware.htmlunit.javascript.JavaScriptEngine$HtmlUnitContextAction.run(JavaScriptEngine.java:880)
        at net.sourceforge.htmlunit.corejs.javascript.Context.call(Context.java:617)
        at net.sourceforge.htmlunit.corejs.javascript.ContextFactory.call(ContextFactory.java:534)
        at com.gargoylesoftware.htmlunit.javascript.HtmlUnitContextFactory.callSecured(HtmlUnitContextFactory.java:336)
        at com.gargoylesoftware.htmlunit.javascript.JavaScriptEngine.callFunction(JavaScriptEngine.java:814)
        at com.gargoylesoftware.htmlunit.javascript.JavaScriptEngine.callFunction(JavaScriptEngine.java:786)
        at com.gargoylesoftware.htmlunit.html.HtmlPage.executeJavaScriptFunction(HtmlPage.java:2534)
        at com.gargoylesoftware.htmlunit.html.HtmlPage.executeJavaScriptFunction(HtmlPage.java:2527)

1 Ответ

1 голос
/ 24 февраля 2020

Похоже, root вашей проблемы - это еще не доступная реализация CanvasRenderingContext2D.createImageData ().

Пожалуйста, откройте проблему на github, и я постараюсь это исправить.

Конечно, любые запросы на получение также приветствуются.

...