im currently trying to catch an error occured by injected script.
what ive done
const path = require('path');
const puppeteer = require('puppeteer');
describe('Test page', () => {
it('should fail on script error', async () => {
const browser = await puppeteer.launch({ headless: false });
const page = await browser.newPage();
await page.addScriptTag({ path: path.join(__dirname, 'test.js') });
await browser.close();
});
});
my test.js
console.log(qwerty)
i need to work with scenario where my spec handles loaded script errors. Ive tried to watch for window errors within evaluate block const error = await page.evaluate(() => window.onerror = () => console.log('error')) but seems no results, also tried to catch this errors from puppeteer page like
page.on('pageerror', function(err) {
console.log(err);
});
i feel like im digging in a wrong context
addScriptTagor what you're trying to test, exactly. I assume you're trying to add a script tag that points to a local script that exists, but yet you expect it to fail to load...? Even if this made sense, why would you want to test this in the first place (please provide more context)?