RequestHook.onRequest Method

Handles the request before it is sent.

class MyRequestHook extends RequestHook {
    async onRequest (event) {
        // ...

The onRequest method's event object exposes the following fields.

Property Type Description
event.requestOptions RequestOptions Contains the request parameters. You can use it to change the request parameters before the request is sent.
event.isAjax Boolean Specifies if the request is performed using AJAX.
async onRequest (event) {
    if(event.isAjax) {

        event.requestOptions.headers['custom-header'] = 'value';


The RequestOptions object contains the request parameters.

Property Type Description
headers Object The request headers in the property-value form.
body Buffer The request body.
url String The URL of the resource.
protocol String The request protocol. Default: http:.
hostname String The domain name or IP address of the destination server. Default: localhost.
host String The domain name or IP address of the destination server, including the listening port. Default: localhost:80.
port Number The port of the remote server. Default: 80.
path String The request path. Should include query string if any. For example, '/index.html?page=12'. An exception is thrown when the request path contains illegal characters (e.g., spaces). Default: '/'.
method String The HTTP request method. Default: 'GET'.
credentials Object Credentials that were used for authentication in the current session with NTLM or Basic authentication. For HTTP Basic authentication, these are username and password. NTLM authentication additionally specifies workstation and domain. See HTTP Authentication.
proxy Object If a proxy is used, the property contains information about its host, hostname, port, proxyAuth, authHeader and bypassRules.
isAjax Boolean Specifies whether the request is an AJAX request (xhr or fetch).