问题
How to block requests from a certain URL using JavaScript? For example, the manual way to do so on chrome will be to open the inspect page, go to network and block from there. But I need to block requests from certain URLs for an automated test that i am writing in JavaScript (using testcafe, if that offers any help).
Here are screenshots of manually blocking a request from chrome, I want to do the same thing automatically in my test/JavaScript: ScreenShot1 Screenshot2
Thank you.
Edit: I tired following this post: Blocking request in Chrome but for some reason i always keep getting an error stating that chrome is undefined when I use chrome.webRequest
回答1:
You can use the nock library, which allows you to intercept requests and process them as you wish.
来源:https://stackoverflow.com/questions/48295525/request-blocking-using-javascript