WebGL with WWW::Mechanize::Chrome (and others)

285 Views Asked by At

I need to run an automated process accessing WebGL inside an iFrame - headless, and after a login.

Up until now I've attempted to do this in different ways:

  • Firefox::Marionette which fails because it doesn't support WebGL
  • WWW::Mechanize::Chrome which fails if I attempt to run it headless (but works like a charm on non-headless)
  • WWW::Mechanize::Chrome via xvfb-run - which fails with "No executable like '/usr/bin/xvfb-run -a --server-args="-screen 0 1280x800x24 -ac -nolisten tcp -dpi 96 +extension RANDR" /usr/bin/google-chrome'

The latter is run like this:

my $mech = WWW::Mechanize::Chrome->new(
                       headless => 0,
                       launch_exe => '/usr/bin/xvfb-run -a --server-args="-screen 0 1280x800x24 -ac -nolisten tcp -dpi 96 +extension RANDR" /usr/bin/google-chrome',
                       launch_arg => ["--headless" , "--no-sandbox"],
                      );

Is there something I haven't tried that could work? I am using perl - but might grudgingly try Python if there's a chance it will work.

2

There are 2 best solutions below

0
simone On BEST ANSWER

xvfb-run must be prepended to the perl script like this

/usr/bin/xvfb-run -a --server-args="-screen 0 1280x800x24 \
    -ac -nolisten tcp -dpi 96 +extension RANDR" \
    perl chrome_script.pl

so it wraps the script, and the chrome instance inside it.

See the manual for xvfb-run

0
ddick On

I've added some documentation to show how to get WebGL working with Firefox::Marionette if you're still interested. Specifically you need to initialise like so;

my $firefox = Firefox::Marionette->new( addons => 1, visible => 1 );