checkly/headless-recorder

navigationPromise resolves once but used multiple times

iofjuupasli opened this issue · 4 comments

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

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

@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

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