checkly / headless-recorder

Chrome extension that records your browser interactions and generates a Playwright or Puppeteer script.
https://checklyhq.com/headless-recorder
MIT License
15.03k stars 722 forks source link

navigationPromise resolves once but used multiple times #184

Closed iofjuupasli closed 1 year ago

iofjuupasli commented 2 years ago

Usually Promise can be resolved only once

https://github.com/puppeteer/puppeteer/blob/main/experimental/puppeteer-firefox/lib/FrameManager.js#L167-L210

I thought maybe it has some different behavior for waitForNavigation, but didn't found that in puppeteer source code.

So in this example:

const puppeteer = require('puppeteer');
const browser = await puppeteer.launch()
const page = await browser.newPage()
const navigationPromise = page.waitForNavigation()

await page.goto('https://example.com/')

await page.setViewport({ width: 1920, height: 980 })

await page.waitForSelector('.bidi-highlight > .fixed-top > .navbar > .float-right > .btn-link')
await page.click('.bidi-highlight > .fixed-top > .navbar > .float-right > .btn-link')

await navigationPromise

await page.waitForSelector('#use-sso-button')
await page.click('#use-sso-button')

await navigationPromise

await page.waitForSelector('.lCoei > .d2laFc > .tgnCOd > .WBW9sf > .w1I7fb')
await page.click('.lCoei > .d2laFc > .tgnCOd > .WBW9sf > .w1I7fb')

await navigationPromise

await browser.close()

The second and third await navigationPromise do nothing actually

ChrisPrzR commented 2 years ago

Have you tried await page.waitForNavigation() in your navigationPromise constant? Perhaps you could call it like that instead of navigationPromise.

iofjuupasli commented 2 years ago

@ChrisPrzR the code is generated by headless-recorder. The idea of waitForNavigation method is that it should called before navigation, and await after navigation begins

ianaya89 commented 2 years ago

@iofjuupasli thanks for reporting it. We are currently working to make a better code and selector generation. Will keep you updated!

ianaya89 commented 1 year ago

https://github.com/checkly/headless-recorder/issues/232