Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Feature]: make waitForFunction timeout condition error readable #9578

Closed
danielcaldas opened this issue Jan 25, 2023 · 2 comments
Closed

[Feature]: make waitForFunction timeout condition error readable #9578

danielcaldas opened this issue Jan 25, 2023 · 2 comments
Labels

Comments

@danielcaldas
Copy link

Feature description

Here's a stack trace for a timeout condition expiration.

✕ should add an empty rule row and render it properly (9169 ms)

  ● [E2E] rule basic UI interactions › should add an empty rule row and render it properly

    TimeoutError: Waiting failed: 5000ms exceeded

      at Timeout.<anonymous> (../node_modules/puppeteer/src/common/WaitTask.ts:79:11)

Test Suites: 1 failed, 1 total
Tests:       1 failed, 1 total

Now the failing code is:

await ctx.extensionPage.waitForFunction(
      () => {
        return document.querySelectorAll('.row__editor .mdc-tab__ripple')?.length === 5;
      },
      { timeout: 5000 }
    );

I'm only able to traceback the failure because that's the only statement in my test with 5000 timeout, otherwise it would be impossible to trace.

Ideally we should have either the client code lines in the stack trace, or even better allow a string parameter to be specified in the waitForFunction API to be logged upon error/timeout for debugging purposes.

@xgqfrms
Copy link

xgqfrms commented Sep 4, 2023

Why doesn't the console.log method work in the waitForFunction callback?

It is difficult for developers to know what the error is.

error

$ node ./pp-class.js
/Users/xgqfrms-mm/Documents/github/cyclic-express-server/node_modules/puppeteer-core/lib/cjs/puppeteer/common/WaitTask.js:59
                void this.terminate(new Errors_js_1.TimeoutError(`Waiting failed: ${options.timeout}ms exceeded`));
                                    ^

TimeoutError: Waiting failed: 30000ms exceeded
    at Timeout.<anonymous> (/Users/xgqfrms-mm/Documents/github/cyclic-express-server/node_modules/puppeteer-core/lib/cjs/puppeteer/common/WaitTask.js:59:37)
    at listOnTimeout (node:internal/timers:564:17)
    at process.processTimers (node:internal/timers:507:7)

Node.js v18.12.0

image

demo

// import puppeteer from 'puppeteer';
const puppeteer = require('puppeteer');

class Crawler {
  constructor(url = '') {
    this.url = url;
  }
  async test (selector = '') {
    const browser = await puppeteer.launch({headless: "new"});
    const page = await browser.newPage();
    await page.goto(this.url);
    await page.setViewport({width: 1920, height: 1080});
    const matches = await page.waitForFunction((selector) => {
      console.log(`❓ selector`, selector)
      // ❌  selector
      const arr = [...document.querySelectorAll(selector)];
      // ✅ 
      // const arr = [...document.querySelectorAll('.trim-title-container')];
      return arr.length ? arr : null;
    });
    console.log(`✅ matches`, matches)
    const contents = await matches.evaluate(els => els.map(e => e.innerText));
    console.log(`✅ contents`, contents)
    await browser.close();
  }
}

(async () => {
  const url = `https://www.tesla.cn/modely/design#overview`;
  const selector = `.trim-title-container`;
  const crawler = new Crawler(url)
  await crawler.test(selector);
})();

@Lightning00Blade
Copy link
Collaborator

Closed by #11330

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants