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

Support waitForNavigation for frames #2918

Closed
hlr1983 opened this issue Jul 19, 2018 · 2 comments
Closed

Support waitForNavigation for frames #2918

hlr1983 opened this issue Jul 19, 2018 · 2 comments
Labels

Comments

@hlr1983
Copy link

hlr1983 commented Jul 19, 2018

Steps to reproduce

Tell us about your environment:

What steps will reproduce the problem?

(async () => {

const puppeteer = await require('puppeteer');

const browser = await puppeteer.launch({headless:false,/* slowMo: 50*/});
const incognitoContext = await browser.createIncognitoBrowserContext();
const page = await incognitoContext.newPage();
page.on('dialog', async dialog => {
    await console.log('MESSAGE "%s": "%s"',dialog.type(),dialog.message());
    await dialog.dismiss();
});
await page.setCacheEnabled(false);

await page.goto('http://home.ubalt.edu/abento/frames/myframe.html', {waitUntil: ['load','domcontentloaded','networkidle0']});

const leftFrame = await page.frames().filter( el => el.name() == 'left')[0]
const rightFrame = await page.frames().filter( el => el.name() == 'right')[0]
await console.log('URLS: MAIN FRAME: %s ; RIGHT FRAME: %s ; LEFT FRAME: %s ', page.url(), rightFrame.url(), leftFrame.url());
const navigationPromise = page.waitForNavigation();
await leftFrame.click('a[href="option2.html"]');
await console.log('URLS: MAIN FRAME: %s ; RIGHT FRAME: %s ; LEFT FRAME: %s ', page.url(), rightFrame.url(), leftFrame.url());
await page.waitFor(5000);
await console.log('URLS: MAIN FRAME: %s ; RIGHT FRAME: %s ; LEFT FRAME: %s ', page.url(), rightFrame.url(), leftFrame.url()); // DISPLAY OTHER URL FOR rightFrame
await navigationPromise;
await console.log('URLS: MAIN FRAME: %s ; RIGHT FRAME: %s ; LEFT FRAME: %s ', page.url(), rightFrame.url(), leftFrame.url()); // NOT DISPLAYED, navigationPromise ERROR
await browser.close();
    
})();

What is the expected result?
I was expecting navigationPromise to be resolved, but it doesn't.

What happens instead?

navigationPromise isn't resolved. Is it the expected behavior? Is it possible to add a frame.waitForNavigation() function?

Screenshot:

image

Thanks

PS: I've also tried with the code below, using waitForNavigation as suggested in frame.click() documentation:

"use strict";

(async () => {

const puppeteer = await require('puppeteer');

const browser = await puppeteer.launch({headless:false,/* slowMo: 50*/});
const incognitoContext = await browser.createIncognitoBrowserContext();
const page = await incognitoContext.newPage();
page.on('dialog', async dialog => {
    await console.log('MESSAGE "%s": "%s"',dialog.type(),dialog.message());
    await dialog.dismiss();
});
await page.setCacheEnabled(false);

await page.goto('http://home.ubalt.edu/abento/frames/myframe.html', {waitUntil: ['load','domcontentloaded','networkidle0']});

const leftFrame = await page.frames().filter( el => el.name() == 'left')[0]
const rightFrame = await page.frames().filter( el => el.name() == 'right')[0]

await Promise.all([
    page.waitForNavigation(),
    leftFrame.click('a[href="option2.html"]')
]);

})();
@aslushnikov
Copy link
Contributor

@hlr1983 Your click navigates a frame rather than a page; unfortunately, we don't currently support waiting for navigation for frames.

One workaround would be to listen for framenavigated event.

await Promise.all([
  leftFrame.click('a[href="option2.html"]'),
  new Promise(resolve => page.once('framenavigated', resolve))
]);

@aslushnikov aslushnikov changed the title waitForNavigation behavior Support waitForNavigation for frames Jul 19, 2018
pomerantsev added a commit to pomerantsev/puppeteer that referenced this issue Jul 26, 2018
@JonnyBoy333
Copy link

I'm running into this same issue in my use case. Even if I use the suggestion that @aslushnikov posted, Promise.all is getting resolved prematurely because the 'framenavigated' event appears to be triggered before all the content inside the frame has loaded. We really need a await frame.waitForNavigation(); solution here that can wait for the frame to finish all network requests and other loading activities before proceeding.

Hope that PR gets merged soon.

aslushnikov added a commit to aslushnikov/puppeteer that referenced this issue Sep 17, 2018
This patch unifies logic in response trackign in page.goto and
page.waitForNavigation.

As a drive-by, we now make sure that we return the right response
for the right frame. This will come handy for future frame navigation
API.

References puppeteer#2918
aslushnikov added a commit that referenced this issue Sep 17, 2018
…3258)

This patch unifies logic in response trackign in page.goto and
page.waitForNavigation.

As a drive-by, we now make sure that we return the right response
for the right frame. This will come handy for future frame navigation
API.

References #2918
aslushnikov added a commit that referenced this issue Sep 19, 2018
This patch:
- moves implementation of page.goto and page.waitForNavigation
  into FrameManager. The defaultNavigationTimeout gets moved to
  FrameManager as well.
- moves NavigatorWatcher into FrameManager to avoid circular dependency

References #2918
aslushnikov added a commit to aslushnikov/puppeteer that referenced this issue Sep 19, 2018
This patch introduces API to manage frame navigations.
As a drive-by, the `response.frame()` method is added as a shortcut
for `response.request().frame()`.

Fixes puppeteer#2918.
aslushnikov added a commit that referenced this issue Sep 20, 2018
This patch introduces API to manage frame navigations.
As a drive-by, the `response.frame()` method is added as a shortcut
for `response.request().frame()`.

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

No branches or pull requests

3 participants