'if url intercepted then go to next part of script
If URL is intercepted on Page2, selector won't be found on Page2, so I need to do nothing and page.goBack. I don't know how to skip the part of code for the page2 and go to the next part of code for the Page3. I tried several things but with no success (I'm really new on JS and Puppeteer, so I have pain to understand some basics I guess)
await page.setRequestInterception(true);
page.on('request', (request) => {
const url = request.url();
const filters = [
'https://example.com',
'https://example2.com',
];
const shouldAbort = filters.some((urlPart) => url.includes(urlPart));
if (shouldAbort) request.abort(), page.goBack();
else request.continue();
});
// Page 1
await page.waitForSelector('selector')
await navigationPromise
await page.evaluate(()=>document.querySelector('selector').click())
await navigationPromise
await page.goBack();
// Page 2
await page.waitForSelector('selector')
await navigationPromise
await page.evaluate(()=>document.querySelector('selector').click())
await navigationPromise
await page.goBack();
// Page 3
await page.waitForSelector('selector')
await navigationPromise
await page.evaluate(()=>document.querySelector('selector').click())
await navigationPromise
await page.goBack();
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
