I’m using onBeforeRequest to intercept page requests with “blocking” active. Frequently when I call browser.webRequest.filterResponseData(details.requestId it failes with the error ‘Invalid request ID’.
Why? And how should I handle that error?
I was just ignoring it, but I noticed that sometimes when I’m browsing with the extension active, certain requests can block for several minutes before returning. If I unload the extension, the requests resolve immediately. I’ve put in a bunch of debugging statement but can’t figure out what’s causing the requests to block, but I’m wondering if these Invalid request ID errors are related.
For context, the idea is to replace third party API calls with calls to a different third party API. For example, if a webapp is making calls to Infura (an ethereum related service), the goal is to catch that request, make it to the user’s own node instead, and then serve the response from the user’s own node.
This is only possible if there is a way to block the filter while an async task completes.
thanks for the docs, managed to get things working.
I think the big thing I was missing is that ondata needs to be set. I was using onstart, but that meant that data wasn’t always being intercepted. The race condition was that sometimes onstart would call filter.close() in time, but other times it would not.
Now that I’m calling ondata to catch all the data, it’s possible to do onstop asynchronously, which is allowing me to call filter.write in a .then() block without issues.