Skip to content

Fetch Intercept

import { startFetchInterceptors } from "webotron/plugins/fetch-intercept";
  • 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();
OptionTypePurpose
patternsFetch patternsFilter which requests to intercept.
handleAuthRequestsbooleanInclude auth flows in interception.
HandlerPurpose
onRequestIntercept request stage and continue/fail/fulfill.
onResponseIntercept response stage and rewrite response body or headers.
onErrorObserve interception pipeline errors.
  • Intercepts requests at request or response stage.
  • Supports continue, fail, and fulfill actions.
  • Can modify request overrides and response bodies.