Estoy tratando de obtener valores de una página usando titiritero, el objetivo principal es extraer una URL si el contenido es válido, sin embargo, la página puede devolver un error dentro de la etiqueta ap.
async function example() { const browser = await puppeteer.launch({ headless: true, }); const page = await browser.newPage(); await page.goto('https://example.com'); // The page might load an error inside of ap element // I don't want to block the rest of the script using await page.waitForSelector('p', {timeout: 5000}) .then( async () => { const pString = await page.evaluate(() => { return document.querySelector('p').innerHTML; }); console.log(pString); if(pString.includes('error')) { console.log('Page contains an error'); //i need to make the main function 'return' if this happens } }) // Wait for the link to load if everything is ok await page.waitForSelector('a', {timeout: 5000}); const link = await page.$('a'); // other stuff }No puedo encontrar una forma adecuada de hacer esto sin tener que esperar el tiempo de espera