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

await waitForNavigation times-out? #50

Open
Deracination opened this issue Oct 4, 2022 · 2 comments
Open

await waitForNavigation times-out? #50

Deracination opened this issue Oct 4, 2022 · 2 comments
Assignees
Labels
enhancement New feature or request

Comments

@Deracination
Copy link

Using waitForNavigation after a click always times-out.

Here's an example:

my $pw = Playwright->new();
my $browser = $pw->launch( headless => 1, type => 'chrome' );
my $page = $browser->newPage({ viewport => { width => 2048, height => 1024 }});

$page->goto('https://github.com/teodesian/playwright-perl', { waitUntil => 'networkidle' });
$page->click('text="Go to file"');

$pw->await( $page->waitForNavigation({ waitUntil => "domcontentloaded" }));

This is based on a JS playwright test script which does the following:

await Promise.all([
            this.page.click(sel),
            this.page.waitForNavigation({ waitUntil: "domcontentloaded" }),
        ]);
@teodesian teodesian self-assigned this Oct 5, 2022
@teodesian teodesian added bug Something isn't working invalid This doesn't seem right and removed bug Something isn't working labels Oct 5, 2022
@teodesian
Copy link
Owner

Note that you have done your waiting in JS in a Promise.all, which fires both requests simultaneously.

In the perl you are clicking the link that executes navigation, and then waiting.
I suspect if you do your wait before the click, and then await the promise like so:

my $promise = $page->waitForNavigation({ waitUntil => "domcontentloaded" }));
$page->click('text="Go to file"');
$pw->await($promise);

the code will work. See the example here:
https://github.com/teodesian/playwright-perl/blob/main/example.pl#L96


In summary, because perl is not an event-driven language like javascript, you have to handle things slightly differently than you would expect. From a technical point of view, this is not actually any different than what is going on in JS -- you have to set up the relevant listener before the required event happens, or a timeout will occur. Promise.All simply allows you to not feel that pain.

@teodesian
Copy link
Owner

I can on the other hand say with confidence that it would be valuable and a good user experience to implement a similar capability to promise.All which may be used to abstract away such akwardness. Reopening as a feature request along those lines.

@teodesian teodesian reopened this Oct 5, 2022
@teodesian teodesian added enhancement New feature or request and removed invalid This doesn't seem right labels Oct 5, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants