In reading the documentation about request override in the Puppeteer API, I see the following notes of caution:
Furthermore, here is the code I use (in PuppeteerSharp) to do the request override:
static void Main(string[] args)
{
Task.Run(async () =>
{
Browser b = await Puppeteer.LaunchAsync(new LaunchOptions()
{
ExecutablePath = "C:\Program Files (x86)\Google\Chrome\Application\chrome.exe",
DefaultViewport = null,
Headless = false
});
Page[] pages = await b.PagesAsync();
Page page = pages[0];
await page.SetRequestInterceptionAsync(true);
// Subscribe to requests
page.Request += HandleRequestIntercepted;
}
}
public static void HandleRequestIntercepted(object sender, RequestEventArgs args)
{
Payload payload = new Payload();
if (args.Request.Url.Contains("adservice.google.com"))
payload.Url = "https://www.amazon.com"; // NEW URL
args.Request.ContinueAsync(payload);
}
And the result is that the request URL is not changed (just like the original documentation described):
How can I do a request URL override where the request URL in DevTools is overridden to the new URL?
question from:
https://stackoverflow.com/questions/66056455/puppeteer-how-to-do-a-proper-request-url-override 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…