Request headers

Author: ghostCreated May 6, 2021Updated May 6, 2021
Labelsquestion

The documentation says that I can add a header to the request

  var xhr = event.data.xhr
  xhr.setRequestHeader("X-Request-Id", "123...")

But it doesn't work, I get an error: DOMException: Failed to execute 'setRequestHeader' on 'XMLHttpRequest': The object's state must be OPENED. Which makes sense.

Of course I can open a connection and specify the required settings, something like

            let xhr = event.data.xhr;
            xhr.open('GET', event.data.url, true);
            xhr.setRequestHeader("Authorization", "Bearer " + token);
            xhr.send();

but in this case, when I navigate through the pages, I will constantly send the old requests and immediately get interrupted.

Is there a solution to this problem?