Is there a way to intercept all network requests made by JavaScript in a web browser?

时间:2019-04-16 23:45:34

标签: javascript xmlhttprequest fetch monkeypatching

F.e., maybe I can monkey patch fetch and XMLHttpRequest so that I can change the request. But what if some code is using window.location? Can I monkey patch that somehow? What other ways?

1 个答案:

答案 0 :(得分:0)

Yes. You can use Service Workers API. Check Service worker concepts and Using example. Using service workers you can intercept any requests and responses, reject them or pass. Beside that service workers are available throughout different pages, so pages can communicate.