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

[Bug]: waitForNavigation does not complete navigation when used with click #9924

Closed
1 of 2 tasks
coder-hxl opened this issue Mar 28, 2023 · 6 comments
Closed
1 of 2 tasks

Comments

@coder-hxl
Copy link

coder-hxl commented Mar 28, 2023

Bug expectation

After executing the navigation to the second page, I still get the content of the first page,

Bug behavior

  • Flaky
  • PDF

Minimal, reproducible example

import puppeteer from 'puppeteer'
;(async () => {
  const browser = await puppeteer.launch()
  const page = await browser.newPage()
  await page.setViewport({ width: 1280, height: 1024 })
  await page.goto('https://github.com/coder-hxl/x-crawl/releases')

  const navHandles = await page.$$('div[role="navigation"] [aria-label]')
  for (let i = 1; i <= navHandles.length; i++) {
    const tagContents = await page.$$eval(
      'section .Box-body .wb-break-word a',
      (aEls) => aEls.map((item) => item.innerHTML)
    )

    console.log(tagContents)

    if (i < navHandles.length) {
      await Promise.all([
        page.waitForNavigation(),
        page.click('div[role="navigation"] .next_page')
      ])
    }
  }

  await browser.close();
})()

Error string

no error

Puppeteer configuration

No response

Puppeteer version

v19.8.0

Node version

v19.0.0

Package manager

pnpm

Package manager version

v7.14.2

Operating system

Windows

@github-actions
Copy link

github-actions bot commented Mar 28, 2023

The issue has been labeled as confirmed by the automatic analyser.
Someone from the Puppeteer team will take a look soon!


Analyzer run

@coder-hxl
Copy link
Author

coder-hxl commented Mar 28, 2023

Add await page.screenshot({ path: ./upload/${i}-page.jpg }) to complete the navigation.

import puppeteer from 'puppeteer'
;(async () => {
  const browser = await puppeteer.launch()
  const page = await browser.newPage()
  await page.setViewport({ width: 1280, height: 1024 })
  await page.goto('https://github.com/coder-hxl/x-crawl/releases')

  const navHandles = await page.$$('div[role="navigation"] [aria-label]')
  for (let i = 1; i <= navHandles.length; i++) {
    await page.screenshot({ path: `./upload/${i}-page.jpg` })

    const tagContents = await page.$$eval(
      'section .Box-body .wb-break-word a',
      (aEls) => aEls.map((item) => item.innerHTML)
    )

    console.log(tagContents)

    if (i < navHandles.length) {
      await Promise.all([
        page.waitForNavigation(),
        page.click('div[role="navigation"] .next_page')
      ])
    }
  }

  await browser.close();
})()

@OrKoN
Copy link
Collaborator

OrKoN commented Mar 28, 2023

I am unable to reproduce. All navigations happen without problem for me (the code was missing the browser.close() to exit):

import puppeteer from 'puppeteer'
;(async () => {
  const browser = await puppeteer.launch({ headless: true, })
  const page = await browser.newPage()
  await page.setViewport({ width: 1280, height: 1024 })
  await page.goto('https://github.com/coder-hxl/x-crawl/releases')

  const navHandles = await page.$$('div[role="navigation"] [aria-label]')
  for (let i = 1; i <= navHandles.length; i++) {
    const tagContents = await page.$$eval(
      'section .Box-body .wb-break-word a',
      (aEls) => aEls.map((item) => item.innerHTML)
    )

    console.log(tagContents)

    if (i < navHandles.length) {
      await Promise.all([
        page.waitForNavigation(),
        page.click('div[role="navigation"] .next_page')
      ])
    }
  }
  await browser.close();
})()

@OrKoN OrKoN closed this as not planned Won't fix, can't repro, duplicate, stale Mar 28, 2023
@coder-hxl
Copy link
Author

coder-hxl commented Mar 28, 2023

@OrKoN After executing the navigation to the second page, I still get the content of the first page

@OrKoN
Copy link
Collaborator

OrKoN commented Mar 28, 2023

This might be due to the fact that GitHub does not always trigger a navigation and loads the page via SPA? You need to wait for the new page content instead of the navigation then. E.g.,

import puppeteer from 'puppeteer'
;(async () => {
  const browser = await puppeteer.launch({ headless: true, })
  const page = await browser.newPage()
  await page.setViewport({ width: 1280, height: 1024 })
  await page.goto('https://github.com/coder-hxl/x-crawl/releases')

  const navHandles = await page.$$('div[role="navigation"] [aria-label]')
  for (let i = 1; i <= navHandles.length; i++) {
    await page.waitForSelector(`[aria-current=page][aria-label="Page ${i}"]`);

    const tagContents = await page.$$eval(
      'section .Box-body .wb-break-word a',
      (aEls) => aEls.map((item) => item.innerHTML)
    )

    console.log(tagContents)

    if (i < navHandles.length) {
      console.log('here')
      await page.click('div[role="navigation"] .next_page');
    }
  }
  await browser.close();
})()

@coder-hxl
Copy link
Author

@OrKoN Appreciate your reply.

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

No branches or pull requests

2 participants