{"record":{"id":"894ab9b012ab713f","repo":"karatelabs/karate","slug":"pdf-generation-not-supported-on-webdriver-backend","errorCode":null,"errorMessage":"PDF generation not supported on WebDriver backend","messagePattern":"PDF generation not supported on WebDriver backend","errorType":"exception","errorClass":"UnsupportedOperationException","httpStatus":null,"severity":"error","filePath":"karate-core/src/main/java/io/karatelabs/driver/w3c/W3cDriver.java","lineNumber":302,"sourceCode":"            session.sendAlertText(input);\n        }\n        if (accept) {\n            session.acceptAlert();\n        } else {\n            session.dismissAlert();\n        }\n    }\n\n    // ========== CoreDriver Tier 2: Extended Primitives ==========\n\n    @Override\n    public Mouse mouse() {\n        return new W3cMouse(session);\n    }\n\n    @Override\n    public byte[] pdf(Map<String, Object> pdfOptions) {\n        throw new UnsupportedOperationException(\n                \"PDF generation not supported on WebDriver backend\");\n    }\n\n    @Override\n    public Map<String, Object> cookie(String name) {\n        return session.getCookie(name);\n    }\n\n    @Override\n    public void cookie(Map<String, Object> cookie) {\n        session.addCookie(cookie);\n    }\n\n    @Override\n    public void intercept(List<String> patterns, InterceptHandler handler) {\n        throw new UnsupportedOperationException(\n                \"Request interception not supported on WebDriver backend\");\n    }","sourceCodeStart":284,"sourceCodeEnd":320,"githubUrl":"https://github.com/karatelabs/karate/blob/a22eb90246d958d15a47bf436693d0121ad2812d/karate-core/src/main/java/io/karatelabs/driver/w3c/W3cDriver.java#L284-L320","documentation":"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.","triggerScenarios":"Calling driver.pdf(...) (or the Karate pdf API) while running on the W3C WebDriver backend instead of the CDP driver.","commonSituations":"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.","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"],"exampleFix":"// before (karate-config)\n{ type: 'chromedriver' }  // W3C backend\n// after\n{ type: 'chrome' }  // CDP backend, supports pdf()","handlingStrategy":"fallback","validationCode":"// guard before calling\nif (!\"chrome\".equals(driverType)) {\n    skipPdfScenario();\n}","typeGuard":"boolean supportsPdf(String driverType) { return \"chrome\".equals(driverType); }","tryCatchPattern":"try {\n    byte[] pdf = karate.pdf(\"/path/out.pdf\");\n} catch (UnsupportedOperationException e) {\n    // W3C backend: generate via headless chrome CLI instead\n}","preventionTips":["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"],"tags":["unsupported-operation","pdf","webdriver","cdp"],"backgroundTag":"unsupported-operation","analyzedSha":"a22eb90246d958d15a47bf436693d0121ad2812d","analyzedAt":"2026-09-12T09:01:00.220Z","contentChangedAt":"2026-09-12T09:01:00.220Z","schemaVersion":2},"datasetVersion":"2026-09-16T19:17:19.609Z"}