- Class: RequestInterceptor
- Class: RequestSpy
- Class: ResponseFaker
- Class: ResponseModifier
- Class: RequestModifier
- Class: RequestRedirector
- Class: RequestBlocker
The RequestInterceptor
will call all spies, fakers and blocker to dertermine if an intercepted request matches. against the matcher
function and notify all spies with a matching pattern and block requests matching any pattern in urlsToBlock
.
matcher
: <(url: string, pattern: string) => boolean>>logger?
: <{log: (text: string) => void}>
The matcher
will be called for every url, testing the url against patterns of any RequestSpy
provided and also any url added to urlsToBlock
.
The logger
if provided will output any requested url with a 'loaded' or 'aborted' prefix and any exception caused by puppeteer's abort and continue functions.
- interceptedRequest: interceptedRequest provided by puppeteer's 'request' event
Function to be registered with puppeteer's request event.
requestSpy
: <IRequestSpy> spy to register
Register a RequestSpy
with the RequestInterceptor
.
Clears all registered spies.
responseFaker
: <IResponseFaker> faker to register
Register a ResonseFaker
with the RequestInterceptor
.
Clears all registered fakers.
responseModifier
: <IRequestModifier> modifier to register
Register a RequestModifier
with the RequestInterceptor
.
Clears all registered modifiers.
urlsToBlock
: <Array<string> | <string>> urls to be blocked if matched
block
will always add urls to the list of urls to block. Passed arrays will be merged with existing urls to block.
urlsToBlock
: <Array<string>> setter forurlsToBlock
Setter to overwrite existing urls to block.
Clears all registered patterns of urls to block.
requestBlocker
<IRequestBlocker>
Allows you to replace the default RequestBlocker by your own implementation.
RequestSpy
is used to count and verify intercepted requests matching a specific pattern.
pattern
: <string|Array<string>>
pattern
passed to the matcher
function of the RequestInterceptor
.
- returns: <boolean> returns whether any url matched the
pattern
- returns: <Array<string>> returns a list of urls that matched the
pattern
- returns: <Array<Request>> returns a list of requests that matched the
pattern
- returns: <number> number of urls that matched the
pattern
- request <Request> request object provided by puppeteer
- matcher <(url: string, pattern: string) => boolean>> matching function passed to RequestInterceptor's constructor
- returns: <boolean> returns true if any pattern provided to the
RequestSpy
matches the request url
The RequestInterceptor
calls this method to determine if an interceptedRequest matches the RequestSpy.
- matchedRequest: <Request> request that was matched
The RequestInterceptor
calls this method when an interceptedRequest matches the pattern.
ResponseFaker
is used to provide a fake response when matched to a specific pattern.
pattern
: <string|Array>responseFake
: <((request: Request) => RespondOptions | Promise<RespondOptions>) | RespondOptions> for details refer to puppeteer API
- returns: <Array<string>> return the
pattern
list of the faker
- returns: <Promise> return the fake response
The RequestInterceptor
calls this method when an interceptedUrl matches the pattern.
- request <Request> request object provided by puppeteer
- matcher <(url: string, pattern: string) => boolean>> matching function passed to RequestInterceptor's constructor
- returns: <boolean> returns true if any pattern provided to the
ResponseFaker
matches the request url
The RequestInterceptor
calls this method to determine if an interceptedRequest matches.
ResponseModifier
is used to load the original response and modify it on the fly as a fake response when matched to a specific pattern.
pattern
: <string|Array>responseModifierCallback
: <(err: Error | undefined, response: string, request: Request) => string | Promise>
- returns: <Array<string>> return the
pattern
list of the faker
request
: <Request>- returns: <Promise> return the fake response
The RequestInterceptor
calls this method when an interceptedUrl matches the pattern.
- request <Request> request object provided by puppeteer
- matcher <(url: string, pattern: string) => boolean>> matching function passed to RequestInterceptor's constructor
- returns: <boolean> returns true if any pattern provided to the
ResponseModifier
matches the request url
The RequestInterceptor
calls this method to determine if an interceptedRequest matches.
RequestModifier
is used to change the request when matched to a specific pattern.
pattern
: <string|Array<string>>requestOverride
: <((request: Request) => Promise | Overrides) | Overrides>httpRequestFactory?
: <IRequestFactory> Factory to create a http request
- returns: <Array<string>> return the
pattern
list of the modifier
request
: <Request>- returns: <Promise> return the request overrides
The RequestInterceptor
calls this method when an interceptedUrl matches the pattern.
- request <Request> request object provided by puppeteer
- matcher <(url: string, pattern: string) => boolean>> matching function passed to RequestInterceptor's constructor
- returns: <boolean> returns true if any pattern provided to the
RequestModifier
matches the request url
The RequestInterceptor
calls this method to determine if an interceptedRequest matches.
RequestRedirector
is used to change request url when matched to a specific pattern.
pattern
: <string|Array<string>>redirectionUrl
: <((request: Request) => Promise | string) | string>
- returns: <Array<string>> return the
pattern
list of the modifier
request
: <Request> request object provided by puppeteer- returns: <Promise> return the request overrides
The RequestInterceptor
calls this method when an interceptedUrl matches the pattern.
- request <Request> request object provided by puppeteer
- matcher <(url: string, pattern: string) => boolean>> matching function passed to RequestInterceptor's constructor
- returns: <boolean> returns true if any pattern provided to the
RequestRedirector
matches the request url
The RequestInterceptor
calls this method to determine if an interceptedRequest matches.
RequestBlocker
is used to by the RequestInterceptor to match requests to block.
- request <Request> request object provided by puppeteer
- matcher <(url: string, pattern: string) => boolean>> matching function passed to RequestInterceptor's constructor
The RequestInterceptor
calls this method to determine if an interceptedRequest matches.
- urls <Array | string>
Adds new urls to the block list.
Removes all entries of the block list.