Search code examples
google-chromeperlheadlessfirefox-marionette

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


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.


Solution

  • 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