Fetch Intercept
Import
Section titled “Import”import { startFetchInterceptors } from "webotron/plugins/fetch-intercept";Entry Point
Section titled “Entry Point”startFetchInterceptors(target, handlers)
const interceptor = await startFetchInterceptors(view, { onRequest: ({ paused }) => { if (paused.request.url.includes("/api")) { return { action: "fulfill", status: 200, body: { ok: true }, }; } return { action: "continue" }; },});
await interceptor.stop();Options
Section titled “Options”| Option | Type | Purpose |
|---|---|---|
patterns | Fetch patterns | Filter which requests to intercept. |
handleAuthRequests | boolean | Include auth flows in interception. |
Handlers
Section titled “Handlers”| Handler | Purpose |
|---|---|
onRequest | Intercept request stage and continue/fail/fulfill. |
onResponse | Intercept response stage and rewrite response body or headers. |
onError | Observe interception pipeline errors. |
What It Does
Section titled “What It Does”- Intercepts requests at request or response stage.
- Supports continue, fail, and fulfill actions.
- Can modify request overrides and response bodies.