Skip to content

[Feature] evaluate timeout  #13253

@bodinsamuel

Description

@bodinsamuel

Hello,

This is half feature request / half bug report, depends on how you read it :D
I noticed evaluate() do not have a timeout and this can be problematic when executing on a busy thread that will never let go.

# http://localhost:3000/page-crash.html
<!DOCTYPE html>
<html>

<head> </head>

<body>
  <script>
    txt = "a";
    while (1) {
      txt = txt += "a";  
    }
  </script>
</body>

</html>
const playwright = require('playwright');

(async () => {
  console.log('launching');
  const browser = await playwright.chromium.launch();
  const context = await browser.newContext();
  const page = await context.newPage();

  page.on('crash', () => {
    console.log('Page crashed');
  });

  console.log('before goto');
  try {
    res = await page.goto('http://localhost:3000/page-crash.html', {
      waitUntil: "domcontentloaded",
      timeout: 2000,
    });
  } catch (e) {
    // ignore timeout error
  }
  console.log('after goto');

  await page.evaluate(() => {
    console.log('hello');
  });
  console.log('after evaluate');

  await browser.close();
  console.log('close');

})()

Will Display

~ node index.js
launching
before goto
after goto
# wait 1-2minutes
Page crashed

# nothing else until SIGINT

Possible Resolutions

  • Add a timeout to evaluate so that it at least throw a timeout error
  • Evaluate could be stopped by page crash
  • Prevent page from consuming all the memory

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions