karatelabs/karate · error · UnsupportedOperationException

Request interception not supported on WebDriver backend

Error message

Request interception not supported on WebDriver backend

What it means

W3cDriver.intercept() unconditionally throws UnsupportedOperationException: network request interception/mocking relies on DevTools Fetch domain, which the W3C WebDriver protocol does not expose. The capability exists only on the CDP driver.

Solutions

  1. Run the scenario on the CDP driver (type 'chrome') where interception is supported
  2. Replace interception with an application-level mock/proxy (e.g. point the app at a stub server)
  3. Skip intercept-dependent scenarios on W3C backends via tags/conditional config

Example fix

// before
{ type: 'chromedriver' } and calling intercept(['**/api/**'], handler)
// after
{ type: 'chrome' }  // CDP backend supports interception
Defensive patterns

Strategy: fallback

Validate before calling

// only set up interception on CDP backend
if (driverSupportsIntercept) {
    karate.intercept(patterns, handler);
} else {
    startStubServer(); // app-level mock instead
}

Type guard

boolean supportsIntercept(String driverType) { return "chrome".equals(driverType); }

Try / catch

try {
    karate.intercept(patterns, handler);
} catch (UnsupportedOperationException e) {
    // fall back to stub server / proxy-based mocking
}

Prevention

When it happens

Trigger: Calling driver.intercept(patterns, handler) — or Karate's intercept/mocking API — while running on a WebDriver (chromedriver/geckodriver) backend.

Common situations: Mocking external APIs in UI tests with config switched to a WebDriver backend; tests shared between CDP and selenium-grid runs; copy-pasting CDP-based intercept examples into W3C-based suites.

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


AI-assisted analysis of karatelabs/karate@a22eb90246 (2026-09-12). Data as JSON: /api/errors/92680118cd92ba51. Report an issue: GitHub.

Appendix: source

Thrown at karate-core/src/main/java/io/karatelabs/driver/w3c/W3cDriver.java:318

    @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");
    }

    @Override
    public void window(String operation) {
        switch (operation) {
            case "maximize" -> session.maximizeWindow();
            case "minimize" -> session.minimizeWindow();
            case "fullscreen" -> session.fullscreenWindow();
            default -> logger.warn("Unknown window operation: {}", operation);
        }
    }

    @Override
    public void tab(Object target) {
        if (target instanceof Integer) {
            List<String> handles = session.getWindowHandles();
            int index = (Integer) target;

View on GitHub (pinned to a22eb90246)