requestId for redirected requests via webRequest

Hi

I’m building a WebExtension using the webRequest API to collect details about requests and responses for the user to review (similar to HttpFox.)

I can see in the webRequest docs that -
“The listener function is passed a details object … This includes a request ID, which is provided to enable an add-on to correlate events associated with a single request … It stays the same throughout a request, even across redirections”

I don’t understand how having redirects maintain the same requestId is helpful in correlating events.
If a request has to go through multiple redirects (like an ad-tracking pixel), there doesn’t seem to be a way to correlate the different request stages (e.g. onBeforeRequest, onCompleted) with each separate redirect request (like what you would see in the Network panel.)

I’m currently storing all requests by ID in an object map, so by default, multiple redirects get overwritten with the most recent event data.

Any suggestions, or should redirects actually be treated as new requestId’s?

Certainly not. As you can see in this sequence diagram, all events that happen after an redirect refer to the redirected request:

So if you want you can “back up” the request before the redirect as oldId +'-old'+ Math.random() or something whenever onBeforeRedirect happens.

1 Like

Ah, that makes sense, thanks so much for offering that solution.
I was trying to think of a way to connect those events to something like a ‘-new’ copy or pushing to an array (which I didn’t think could work properly), but keeping the ‘-old’ original request each time is obviously the right way to go. Thank you