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

1
  • I'd use this 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)? Commented Jul 23, 2021 at 15:03

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.