使命感
Page.printToPDF
命令,并传递包含定义
@font-face
结果
org.openqa.selenium.WebDriverException: unknown error: session deleted because of page crash
。
我使用下面的代码在Java中生成pdf。
chromeDriver.get(url);
var pdf = (String) ((HasCdp) chromeDriver)
.executeCdpCommand(
"Page.printToPDF",
Map.of("headerTemplate", "the contents of the html below", ... other parameters))
.get("data");
以下html可用作复制问题的头模板:
<html>
<head>
<style type="text/css">
@font-face {
font-family: "Titillium Web";
src: url(https://fonts.gstatic.com/s/titilliumweb/v15/NaPDcZTIAOhVxoMyOr9n_E7ffGjEGIVzY4SY.woff2) format('woff2');
}
</style>
</head>
<body>
<div>
<div style="font-weight: 600; font-size: 15pt; font-family: 'Titillium Web'; ">Testing header</div>
<div style="font-size: 10pt; font-family: 'Titillium Web'; ">This is working as a standalone html, but crashing in ChromeDriver</div>
</div>
</body>
</html>
详细的错误和堆栈跟踪如下:
org.openqa.selenium.WebDriverException: unknown error: session deleted because of page crash
from unknown error: cannot determine loading status
from tab crashed
(Session info: headless chrome=105.0.5195.54)
Build info: version: '4.5.0', revision: 'fe167b119a'
System info: os.name: 'Linux', os.arch: 'amd64', os.version: '5.4.0-125-generic', java.version: '17.0.4'
Driver info: org.openqa.selenium.chrome.ChromeDriver
Command: [44af04a45bd843fc4fc23163eee329d6, executeCdpCommand {cmd=Page.printToPDF, params={displayHeaderFooter=true, headerTemplate=[something like the html above], marginLeft=0.7874015748031497, marginBottom=1.299212598425197, paperWidth=8.267716535433072, marginTop=1.299212598425197, marginRight=0.7874015748031497, paperHeight=11.692913385826772}}]
Capabilities {acceptInsecureCerts: false, browserName: chrome, browserVersion: 105.0.5195.54, chrome: {chromedriverVersion: 105.0.5195.52 (412c95e51883..., userDataDir: /tmp/.com.google.Chrome.2XGZbo}, goog:chromeOptions: {debuggerAddress: localhost:34545}, networkConnectionEnabled: false, pageLoadStrategy: normal, platformName: LINUX, proxy: Proxy(), se:cdp: ws://localhost:34545/devtoo..., se:cdpVersion: 105.0.5195.54, setWindowRect: true, strictFileInteractability: false, timeouts: {implicit: 600000, pageLoad: 600000, script: 600000}, unhandledPromptBehavior: dismiss and notify, webauthn:extension:credBlob: true, webauthn:extension:largeBlob: true, webauthn:virtualAuthenticators: true}
Session ID: 44af04a45bd843fc4fc23163eee329d6
at jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) ~[?:?]
at jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:77) ~[?:?]
at jdk.internal.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45) ~[?:?]
at java.lang.reflect.Constructor.newInstanceWithCaller(Constructor.java:499) ~[?:?]
at java.lang.reflect.Constructor.newInstance(Constructor.java:480) ~[?:?]
at org.openqa.selenium.remote.codec.w3c.W3CHttpResponseCodec.createException(W3CHttpResponseCodec.java:200) ~[selenium-remote-driver-4.5.0.jar:?]
at org.openqa.selenium.remote.codec.w3c.W3CHttpResponseCodec.decode(W3CHttpResponseCodec.java:133) ~[selenium-remote-driver-4.5.0.jar:?]
at org.openqa.selenium.remote.codec.w3c.W3CHttpResponseCodec.decode(W3CHttpResponseCodec.java:53) ~[selenium-remote-driver-4.5.0.jar:?]
at org.openqa.selenium.remote.HttpCommandExecutor.execute(HttpCommandExecutor.java:184) ~[selenium-remote-driver-4.5.0.jar:?]
at org.openqa.selenium.remote.service.DriverCommandExecutor.invokeExecute(DriverCommandExecutor.java:167) ~[selenium-remote-driver-4.5.0.jar:?]
at org.openqa.selenium.remote.service.DriverCommandExecutor.execute(DriverCommandExecutor.java:142) ~[selenium-remote-driver-4.5.0.jar:?]
at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:547) ~[selenium-remote-driver-4.5.0.jar:?]
at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:602) ~[selenium-remote-driver-4.5.0.jar:?]
at org.openqa.selenium.remote.RemoteExecuteMethod.execute(RemoteExecuteMethod.java:40) ~[selenium-remote-driver-4.5.0.jar:?]
at org.openqa.selenium.chromium.AddHasCdp$1.executeCdpCommand(AddHasCdp.java:58) ~[selenium-chromium-driver-4.5.0.jar:?]
at org.openqa.selenium.chromium.ChromiumDriver.executeCdpCommand(ChromiumDriver.java:212) ~[selenium-chromium-driver-4.5.0.jar:?]
一切都按预期进行,以防我没有使用新字体或没有定义它。
有人知道如何解决这个问题吗?