I would like to attach an id
to each request going out via my extension. I have tried:
browser.webRequest.onBeforeSendHeaders.addListener(
function (details) {
const headers = details.requestHeaders ?? []
headers.push({
name: 'x-devqaly-request-id',
value: uuidv4()
})
console.log(headers) // it shows that the header was added
return { requestHeaders: headers }
},
{ urls: ['https://api.codotto.com/*'] }, // The URL is correct as it works in other parts of the code with browser.webRequest.onBeforeRequest
['requestHeaders']
)
But when I inspect the requests going out the header x-devqaly-request-id
is not being attached to the request.
manifest.json
{
"name": "devqaly",
"description": "Record your screen while we record network requests, clicks, and events in your backend",
"manifest_version":3,
...
"permissions": [
"storage",
"webRequest",
"scripting",
"declarativeNetRequest"
],
"host_permissions": [
"<all_urls>"
]
}
I know that there is browser.declarativeNetRequest.updateDynamicRules
but it is not possible to update the rules for each request. As you can see from the code example, I need to have a unique identifier for each request being sent in the header per request
How can I add a header using browser.webRequest.onBeforeSendHeaders
? If not possible, is there a way to achieve sending a unique id per request in the header?