Install & Compatibility
Where this runs
tested against v? · npm install
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
muslnode 18–226 runs
build_error
glibcnode 18–226 runs
build_error
Code
Verified usage
Verified import paths — ran on the pinned version, not inferred.
default (function)
✓ import WebdriverAjax from 'wdio-intercept-service'
✗ const WebdriverAjax = require('wdio-intercept-service').default
ESM default export. Do not use .default with require() – you will get an object with a default property instead of the function.
setupInterceptor
✓ browser.setupInterceptor()
✗ browser.setupinterceptor()
Case-sensitive command added to browser object after service is initialized. Must be called before making requests you want to intercept.
expectRequest
✓ browser.expectRequest('GET', '/api/foo', 200)
✗ browser.expectRequest('GET', '/api/foo')
Third argument (statusCode) is required. Can use string or RegExp for URL.
assertRequests
✓ browser.assertRequests()
✗ browser.assertRequests({ timeout: 2000 })
assertRequests does not accept options. Use separate pause() or wait strategies before calling it.
Demonstrates setting up the service manually with WebdriverIO standalone, intercepting an XHR/fetch request, and asserting it.
import { remote } from 'webdriverio';
import WebdriverAjax from 'wdio-intercept-service';
async function run() {
const browser = await remote({
logLevel: 'warn',
capabilities: { browserName: 'chrome' }
});
const serviceLauncher = WebdriverAjax();
serviceLauncher.before(null, null, browser);
serviceLauncher.beforeTest();
await browser.url('https://example.com');
await browser.setupInterceptor();
await browser.expectRequest('GET', '/api/data', 200);
await browser.click('#load-data');
await browser.pause(1000);
await browser.assertRequests();
const request = await browser.getRequest(0);
console.log('Request method:', request.method);
await browser.deleteSession();
}
run().catch(console.error);
Errors
Common errors & fixes
TypeError: Cannot read properties of undefined (reading 'before')
Calling serviceLauncher.before before the service is initialized or with incorrect arguments.
fixEnsure the service is initialized with `const serviceLauncher = WebdriverAjax();` and then call `serviceLauncher.before(null, null, browser);` passing the browser instance.
Error: expectRequest requires a method, url, and statusCode.
Calling expectRequest with missing or invalid arguments (e.g., no statusCode).
fixUse `browser.expectRequest('GET', '/api/foo', 200);` – all three arguments are required. AssertionError: expected 0 to equal 1
Request was not intercepted because setupInterceptor() was not called or the request was made before it was called.
fixEnsure browser.setupInterceptor() is called before the action that triggers the request.
SyntaxError: Unexpected token 'export'
Using ES module import syntax in a CommonJS environment (e.g., Node.js without 'type': 'module' or .mjs extension).
fixUse `const WebdriverAjax = require('wdio-intercept-service');` or configure your project for ESM. Audit
Dependencies
webdriveriorequiredPeer dependency; must be installed in the project with a compatible version (v5+ for current plugin, v8+ recommended).