david-dick / firefox-marionette

This is a client module to automate the Mozilla Firefox browser via the Marionette protocol
https://metacpan.org/dist/Firefox-Marionette
Other
12 stars 3 forks source link

Lazy-loading doesn't work #23

Closed toreau closed 1 year ago

toreau commented 1 year ago

I have this simple test script, but lazy-loading doesn't work:

#!/usr/bin/env perl
#
use strict;
use warnings;
use Data::Dumper;
use feature 'say';

use Firefox::Marionette;
use Firefox::Marionette::Keys qw( PAGE_DOWN );

my $url = 'https://www.komplett.no/category/10412/datautstyr/pc-komponenter/skjermkort';

my $firefox = Firefox::Marionette->new(
    'width'   => 1920,
    'height'  => 1080,
    'visible' => 1,
);

$firefox->go( $url );
sleep( 2 );

my $cookie_consent = $firefox->find_class( 'btn-large primary' );
if ( $cookie_consent ) {
    $cookie_consent->click;
}

my $html = $firefox->html;

while ( 1 ) {
    $firefox->chrome->perform(
        $firefox->key_down( PAGE_DOWN ),
        $firefox->pause( 1_500 ),
    )->release->content;

    if ( $firefox->html eq $html ) {
        last;
    }

    $html = $firefox->html;
}

$firefox->quit;
david-dick commented 1 year ago

This looks like an issue with this website detecting robots and refusing to work with them, if you use the devtools option, you can see a whole bunch of http errors from the website refusing to download content.

david-dick commented 1 year ago

As a counter example, a slightly altered script to work with the google image function works fine

#!/usr/bin/env perl
#
use strict;
use warnings;
use Data::Dumper;
use feature 'say';

use Firefox::Marionette;
use Firefox::Marionette::Keys qw( PAGE_DOWN );

my $url = 'https://www.google.com.au/search?q=perl&hl=en&source=lnms&tbm=isch';

my $firefox = Firefox::Marionette->new(
    'width'   => 1920,
    'height'  => 1080,
    'visible' => 1,
);

$firefox->go( $url );

my $html = $firefox->html;

while ( 1 ) {
    $firefox->chrome->perform(
        $firefox->key_down( PAGE_DOWN ),
        $firefox->pause( 500 ),
    )->release->content;

    if ( $firefox->html eq $html ) {
        last;
    }

    $html = $firefox->html;
}

$firefox->quit;