Corion / WWW-Mechanize-Chrome

automate the Chrome browser
https://metacpan.org/release/WWW-Mechanize-Chrome
Artistic License 2.0
30 stars 12 forks source link

Browser hangs when click() method called on a javascript link #21

Closed sdondley closed 5 years ago

sdondley commented 6 years ago

Let's say you have a link that when clicked triggers an ajax call to load more content into the page. If the click() method is used to click the link, the browser hangs because it never receives an HTTP::Response back. I've hacked together a fix for my own purposes but it would be better to make a proper fix. I'm looking for guidance on what that fix would be. Here's my temporary hack which modifies the _mightNavigate call found at the end of the click method:

    my $response = $x ? 
    $self->_mightNavigate( sub {

        $self->driver->send_message('Runtime.callFunctionOn', objectId => $id, functionDeclaration => 'function() { this.click(); }', arguments => []);
    }, %options)
    :
    $self->_mightNavigate( sub {
        $self->driver->send_message('Runtime.callFunctionOn', objectId => $id, functionDeclaration => 'function() { this.click(); }', arguments => []);
    }, %options)
    ->get;

The way it works is if I pass in a value for $x to the method, it will call _mightNavigate without the get method.

Corion commented 5 years ago

The (more) correct solution would be to use the intrapage option to ->click:

$mech->click( { selector => '.foo', intrapage => 1 });

Currently, I have a problem coming up with a test case where the detection for "no HTTP response will come" fails. If you have a slimmed down test case, this would help.

sdondley commented 5 years ago

Unfortunately, I don't remember where I encountered this problem. It may have been the Twitter login button on their web page but I'm not sure.

sdondley commented 5 years ago

I think I found it. It looks like it's a link in Facebook group discussions:

click( { xpath => $s->xpath . '//div[@class="UFIList"]/div/div/div[1]//a[@class="UFIPagerLink"]' }, 1 );
Corion commented 5 years ago

Thank you for digging into this. If you can create a page that reproduces the behaviour from that, that would be great. As it is, I can't replicate it and I don't even have an URL to reproduce the behaviour.

sdondley commented 5 years ago

I was just looking it over. It looks like Facebook changed their ids quite a bit so it would be a nightmare to track down.

I'd try using the link this guy was talking about: https://www.perlmonks.org/?node_id=11105389

Corion commented 5 years ago

Yes, I could go rummaging around in an ill-defined nest of web pages. It seems that the problem cannot be reproduced at this time.

I'm closing this bug until a reproducible case is presented.

sdondley commented 5 years ago

OK, if I run across it again, I'll let you know.