-1

I'm trying to do a drag and drop function using typescript and Playwright. In the meantime I was trying to use the evaluateHandle method, however it seems that the code is not entering inside the method. I have a console.log inside the method that never logs in console. What am I doing wrong?

await page.evaluateHandle(async (data) => {
  const dt = new DataTransfer();
  console.log('Reached here');
  const blobData = await fetch(data).then(res => res.blob());

  const file = new File([blobData], 'ci.csv', { type: 'application/csv' });
  dt.items.add(file);
  return dt;
}, buffer);
dpombo
  • 1
  • 1

1 Answers1

0

Browser console message/errors can be listened like below at runtime:

const playwright = require("playwright");
 (async () => {
  const browser = await playwright.chromium.launch();
  const context = await browser.newContext();
  const page = await context.newPage();
  const errorLogs = []
  page.on("console", (message) => {
    if (message.type() === "error") {
      errorLogs.push(message.text())
    }
  })
  await page.evaluate(() => {
    console.error("hello from the browser")
  })
  console.log(errorLogs)
  await browser.close();
})();

There is also the pageError event which can be used to catch unhandled exceptions which get thrown inside the browser:

 page.on("pageerror", (err) => {
    console.log(err.message)
  })

Reference: https://playwright.dev/docs/api/class-consolemessage

Vishal Aggarwal
  • 1,929
  • 1
  • 13
  • 23