Options
All
  • Public
  • Public/Protected
  • All
Menu

regex + adjustment parameters for modifying or rejecting resources being loaded by the webpage. Example: {regex:".*css.*",isBlacklisted:true}

Hierarchy

  • IResourceModifier

Index

Properties

Optional category

category: "navigationRequest" | "pageResource" | "subFrameResource"

new for Chrome backend. (not available on WebKit).

pass one of the listed categories to modify all requests of that type.

can be used in instead of, or in addition to, the type or regex property (results are additive)

Optional changeCaptureRegex

changeCaptureRegex: string

special pattern matching regex. capture groups can replace parts of the changeUrl that use the special marker tokens $$0, $$1, etc on to $$9 .

Note You use changeCaptureRegex to construct custom marker tokens that can be used inside of your changeUrl string.

for example: if resourceUrl="http://google.com/somescript.js" changeCaptureRegex="^.*?/(.*)$" would create a match group for everything after the last / character and changeUrl="http://example.com/$$1" would then get evaluated to "http://example.com/somescript.js"

Optional changeUrl

changeUrl: string

changes the current URL of the network request.

You can inject parts of the original URL into your changeUrl using one of the special marker tokens: $$port $$protocol` $$host or $$path.

Note You can use changeCaptureRegex to construct custom marker tokens that can be used inside of your changeUrl string.

example

changeUrl="$$protocol://example.com/redirect$$path" would change the URL https://mysite.org/products/item1.html to https://example.com/redirect/products/item1.html

Optional isBlacklisted

isBlacklisted: boolean

if true, blacklists the request unless a later matching resourceAdjustor changes it back to false (we process in a FIFO fashion) by default, we don't blacklist anything. You should keep it this way when rendering jpeg (where the visuals matter), if processing text/data, blacklisting .css files ['..css.'] will work fine. check the response.metrics for other resources you could blacklist (example: facebook, google analytics, ad networks)

Optional method

method: string

new for Chrome backend. (not available on WebKit).

set to override the method.

Optional postData

postData: string

new for Chrome backend. (not available on WebKit).

set to override the post body.

Optional regex

regex: string

pattern used to match a resource's url.

can be used in instead of, or in addition to, the category or type property (results are additive)

examples: it really depends what the site is and what you are wanting to block, but for example to block anything with the text "facebook" or "linkedin" in the url:

javascript requestModifiers:[{regex:".*facebook.*",isBlacklisted:true},{regex:".*linkedin.*",isBlacklisted:true}]

It's especially useful if you just need the text, as you can block all css files from loading, such as: ".*\.css.*"

Don't use this to block images. instead, images are blocked by using the IRequestSettings.ignoreImages=true property`

Optional setHeader

setHeader: object

optional key/value pairs for adjusting the headers of this resource's request. example: {"Accept-encoding":"gzip", "hello":"world"}

Type declaration

  • [key: string]: string

Optional setResponse

setResponse: object

new for Chrome backend. (not available on WebKit).

set the response to be returned to the requesting page. warning: setting this to an empty object will force a blank response. to skip this, do not set it, or set to null.

Type declaration

  • Optional body?: string

    set the response body

  • Optional contentType?: string

    sets the Content-Type response header

  • Optional headers?: object

    set response headers

    • [key: string]: string
  • Optional status?: number

    set response status code.

    default

    200

Optional type

type: "document" | "stylesheet" | "image" | "media" | "font" | "script" | "texttrack" | "xhr" | "fetch" | "eventsource" | "websocket" | "manifest" | "other"

new for Chrome backend. (not available on WebKit).

pass one of the categories to modify all requests of that type.

can be used in instead of, or in addition to, the category or regex property (results are additive)