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

async wait feature not working well #240

Open
taishi55 opened this issue Dec 11, 2024 · 6 comments
Open

async wait feature not working well #240

taishi55 opened this issue Dec 11, 2024 · 6 comments
Labels
triage This ticket will be looked at shortly

Comments

@taishi55
Copy link

taishi55 commented Dec 11, 2024

Description

await page.type('textarea', `Hello World\n\nThis is a bot.`, { delay: 10 });
await page.waitForTimeout(5000);
await page.keyboard.press('Enter');
  • It doesn't wait typing complete text. It cut off after "Hello World".
  • Also I get error message page.waitForTimeout is not a function.
  • I tried a simple delay function await new Promise((resolve) => setTimeout(resolve, 5000)); But this also doesn't work either (no error but it doesn't wait 5 seconds).
  • await page.keyboard.press('Enter'); This enters twice.

Full steps to reproduce the issue

Please run the following code to view the bug.

const { connect } = require('puppeteer-real-browser');
const { browser } = await connect({
        headless: false,  // #test
        args: [
            '--no-sandbox',
            '--disable-setuid-sandbox',
        ],
        customConfig: {},
        turnstile: true,
        connectOption: {},
        disableXvfb: false,
        ignoreAllFlags: false,
});
const page = await browser.newPage();
await page.setRequestInterception(true);
page.on('request', (req) => {
    // if (['image', 'stylesheet', 'font'].includes(req.resourceType())) {
    if (['image', 'stylesheet', 'font'].includes(req.resourceType())) {
        req.abort(); // Block unnecessary resources
    } else {
        req.continue(); // Allow other resources
    }
});

await page.goto('https://www.perplexity.ai', { waitUntil: 'networkidle0' });
await page.waitForSelector('textarea', { visible: true, timeout: 5000 });
await page.click('textarea');
await page.focus('textarea');
await page.type('textarea', `Hello World\n\nThis is a bot.`, { delay: 10 });
await page.waitFor(5000); // Wait for 1.5 second before pressing Enter
await page.keyboard.press('Enter');

---package.json---

"dependencies": {
    "puppeteer-real-browser": "^1.3.20"
  }

---node version---
node -v
v20.14.0

Issue Type

Bug

Operating System

Mac OS

Do you use Docker?

None

@taishi55 taishi55 added the triage This ticket will be looked at shortly label Dec 11, 2024
@RubberArchind
Copy link

for the page.type it should be related to #235

@taishi55

This comment was marked as duplicate.

@RubberArchind
Copy link

RubberArchind commented Dec 11, 2024

Thank you @RubberArchind. My mistake was having await page.click('textarea');

However, I wanna keep this ticket open for another issue. If you add next lines with \n\n, it automatically enters. await page.type('textarea', Hello World.\n\nThis is a bot., { delay: 10 }); This enters after Hello World.

Overall if you avoid \n\n in the input, you can run fine. The following works now.

await page.goto('https://www.perplexity.ai', { waitUntil: 'networkidle0' });
await page.waitForSelector('textarea', { visible: true, timeout: 5000 });
await page.focus('textarea');
await page.type('textarea', `Hello World. This is a bot.`, { delay: 10 });
await new Promise((resolve) => setTimeout(resolve, 2000));
await page.keyboard.press('Enter');

just enter it then since you use backthick it should be worked i guess.

await page.type('textarea', `Hello World. 

This is a bot.`, { delay: 10 });

Use it like this instead of \n for enter?

@taishi55

This comment was marked as duplicate.

@taishi55

This comment was marked as duplicate.

@taishi55

This comment was marked as duplicate.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
triage This ticket will be looked at shortly
Projects
None yet
Development

No branches or pull requests

2 participants