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]: Frame navigated event did not trigger #9264

Closed
tzbo opened this issue Nov 14, 2022 · 8 comments
Closed

[Bug]: Frame navigated event did not trigger #9264

tzbo opened this issue Nov 14, 2022 · 8 comments

Comments

@tzbo
Copy link

tzbo commented Nov 14, 2022

Bug description

Steps to reproduce the problem:

 try {
            const iframe = document.createElement('iframe')
            iframe.setAttribute('style', 'display:none')
            iframe.src = location.href
            document.body.append(iframe)
            const data = await getData(iframe.contentWindow)
            iframe.parentNode.removeChild(iframe)
            return data
        } catch (error) {
            console.error(error)
            return
        }

This code will not trigger [frameattached] and [framenavigated].

If add break point at [const iframe = document.createElement('iframe')], then the event can be triggered again.

Puppeteer version

19.2.2

Node.js version

18

npm version

8.4

What operating system are you seeing the problem on?

macOS

Configuration file

No response

Relevant log output

No response

@tzbo tzbo added the bug label Nov 14, 2022
@Lightning00Blade
Copy link
Collaborator

@tzbo Presumable the code you show is in your HTML. Are you setting up listeners before navigating to the page, like so:

  const browser = await puppeteer.launch();
  const page = await browser.newPage();
  page.on("frameattached", () => {
    console.log(`It attached.`);
  });
  page.on("framedetached", () => {
    console.log(`It detached.`);
  });
  await page.goto("http://127.0.0.1:8080/");
  await browser.close();

This worked for me. Setting of Listeners should happen before navigation, else they may be added after the event has occurred.

@tzbo
Copy link
Author

tzbo commented Nov 14, 2022

https://abrahamjuliot.github.io/creepjs/tests/iframes.html

You can open this to test.

@Lightning00Blade
Copy link
Collaborator

Is it possible you are closing the window as soon as the page load.? It looks like your code is Async and would need a way to await the changes. Example with page.waitForNetworkIdle() worked with your code:

  const browser = await puppeteer.launch();
  const page = await browser.newPage();
  page.on("frameattached", () => {
    console.log(`It attached.`);
  });
  page.on("framedetached", () => {
    console.log(`It detached.`);
  });
  await page.goto("https://abrahamjuliot.github.io/creepjs/tests/iframes.html");

  await page.waitForNetworkIdle();

  await browser.close();

That can also be page.waitForSelector() if you want to check a element or
a simple await new Promise((resolve) => setTimeout(resolve, X)); can also work.

@tzbo
Copy link
Author

tzbo commented Nov 14, 2022

Please try to open this link. The [same origin] frame will not trigger [frameattached] event.

You can find 8 [frameattached] events if you open this link. But there should be 9 events. The code creates 8 iframes and there is another main frame. So there should be 9 events.

@Lightning00Blade
Copy link
Collaborator

@tzbo Can you provide your Puppeteer Script that the issue is happening?

@tzbo
Copy link
Author

tzbo commented Nov 16, 2022

const browser = await puppeteer.launch();
  const page = await browser.newPage();
  page.on("frameattached", () => {
    console.log(`It attached.`);
  });
  page.on("framedetached", () => {
    console.log(`It detached.`);
  });
  await page.goto("https://abrahamjuliot.github.io/creepjs/tests/iframes.html");

  await page.waitForNetworkIdle();

  await browser.close();

This script is okay. There should be nine [It attached] events. But got 8.

@OrKoN
Copy link
Collaborator

OrKoN commented Nov 16, 2022

@tzbo @Lightning00Blade IMO, sounds like it is working as expected. The main frame is never attached/detached as it exists since the creation of the page and can only be navigated (which the goto handles).

@tzbo
Copy link
Author

tzbo commented Nov 17, 2022

May be same problem with 1106

@jrandolf jrandolf closed this as completed Jan 2, 2023
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

4 participants