1

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

ddeadlink
  • 249
  • 2
  • 13
  • I'd use [this](https://stackoverflow.com/questions/58089425/how-do-print-the-console-output-of-the-page-in-puppeter-as-it-would-appear-in-th) to capture page output. I'm not really clear about the `addScriptTag` or 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)? – ggorlen Jul 23 '21 at 15:03

0 Answers0