karatelabs/karate · error · UnsupportedOperationException
PDF generation not supported on WebDriver backend
Error message
PDF generation not supported on WebDriver backend
What it means
W3cDriver.pdf() unconditionally throws UnsupportedOperationException because PDF generation is a Chrome DevTools (Page.printToPDF) capability that the plain WebDriver protocol does not provide. It is a static capability declaration, not a runtime condition.
Solutions
- Switch the driver type to chrome/cdp (DevTools-backed) in the karate config to get PDF support
- Avoid calling pdf() in tests that must run on the W3C backend, or guard with a capability check
- Generate the PDF out-of-band (e.g. headless Chrome CLI, server-side library) if WebDriver must stay
Example fix
// before (karate-config)
{ type: 'chromedriver' } // W3C backend
// after
{ type: 'chrome' } // CDP backend, supports pdf() Defensive patterns
Strategy: fallback
Validate before calling
// guard before calling
if (!"chrome".equals(driverType)) {
skipPdfScenario();
} Type guard
boolean supportsPdf(String driverType) { return "chrome".equals(driverType); } Try / catch
try {
byte[] pdf = karate.pdf("/path/out.pdf");
} catch (UnsupportedOperationException e) {
// W3C backend: generate via headless chrome CLI instead
} Prevention
- Use the CDP ('chrome') driver for scenarios needing PDF export
- Tag PDF scenarios so W3C/selenium-grid runs can exclude them
- Document driver capability differences in the team's test guidelines
When it happens
Trigger: Calling driver.pdf(...) (or the Karate pdf API) while running on the W3C WebDriver backend instead of the CDP driver.
Common situations: Test suite written against chrome/cdp driver later run with a generic WebDriver; switching driver 'type' in config between runs; porting CDP-specific scripts to a grid/selenium setup.
Understand the failure class
Background: UnsupportedOperationException and "is not supported" errors: when a library deliberately refuses a call — this error's family across 30 libraries.
Related errors
- Request interception not supported on WebDriver backend
- Dialog callback handler not supported on WebDriver backend…
- karate.match(String) is not available in this context
- karate.call() is not available in this context
- inputFile not supported by this driver
AI-assisted analysis of karatelabs/karate@a22eb90246 (2026-09-12).
Data as JSON: /api/errors/894ab9b012ab713f.
Report an issue: GitHub.
Appendix: source
Thrown at karate-core/src/main/java/io/karatelabs/driver/w3c/W3cDriver.java:302
session.sendAlertText(input);
}
if (accept) {
session.acceptAlert();
} else {
session.dismissAlert();
}
}
// ========== CoreDriver Tier 2: Extended Primitives ==========
@Override
public Mouse mouse() {
return new W3cMouse(session);
}
@Override
public byte[] pdf(Map<String, Object> pdfOptions) {
throw new UnsupportedOperationException(
"PDF generation not supported on WebDriver backend");
}
@Override
public Map<String, Object> cookie(String name) {
return session.getCookie(name);
}
@Override
public void cookie(Map<String, Object> cookie) {
session.addCookie(cookie);
}
@Override
public void intercept(List<String> patterns, InterceptHandler handler) {
throw new UnsupportedOperationException(
"Request interception not supported on WebDriver backend");
}View on GitHub (pinned to a22eb90246)