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

Headless mode not working #86

Open
Oggy16 opened this issue Nov 5, 2024 · 0 comments
Open

Headless mode not working #86

Oggy16 opened this issue Nov 5, 2024 · 0 comments

Comments

@Oggy16
Copy link

Oggy16 commented Nov 5, 2024

Hi,

I've just done a fresh install of Chromium and WWW-Mechanize-Chrome (from CPAN). I am testing the install with the following code:

use Log::Log4perl qw(:easy);
use WWW::Mechanize::Chrome;

Log::Log4perl->easy_init($ERROR);  # Set priority of root logger to ERROR
my $mech = WWW::Mechanize::Chrome->new(
    headless => 1,
    launch_exe => '/usr/local/bin/chrome',
);
$mech->get('https://google.com');
print "Browser Version: ".$mech->browser_version()."\n";   

I found that when I ran the above on a machine with no X server Perl would hang forever, no errors being printed.

I then tried running on a machine with a running X server, and despite "headless => 1" being set the chrome browser window would pop up, then the code would execute correctly.

Setting "headless => 0" or "headless => 1" makes no difference, in both cases the browser window pops up.

If I unset my DISPLAY variable so that the browser window cannot start then the below happens depending on the headless setting:

  • If "headless => 1", then the script will hang forever
  • If "headless => 0", then it terminates with the following error: Could not read websocket endpoint from Chrome output. Do you maybe have a non-debug instance of Chrome already running? at /usr/local/lib/perl5/site_perl/WWW/Mechanize/Chrome.pm line 1096.

With debug logging enabled, running with "headless => 1" and no X server I get the following:

2024/11/05 18:25:13 Spawning for websocket $VAR1 = [
          '/usr/local/bin/chrome',
          '--remote-debugging-port=0',
          '--remote-allow-origins=*',
          '--remote-debugging-address=127.0.0.1',
          '--no-first-run',
          '--mute-audio',
          '--no-default-browser-check',
          '--no-sandbox',
          '--safebrowsing-disable-auto-update',
          '--disable-background-networking',
          '--disable-background-timer-throttling',
          '--disable-backgrounding-occluded-windows',
          '--disable-breakpad',
          '--disable-default-apps',
          '--disable-dev-shm-usage',
          '--disable-domain-reliability',
          '--disable-gpu',
          '--disable-ipc-flooding-protection',
          '--disable-client-side-phishing-detection',
          '--disable-component-update',
          '--disable-hang-monitor',
          '--disable-popup-blocking',
          '--disable-prompt-on-repost',
          '--disable-renderer-backgrounding',
          '--disable-sync',
          '--disable-translate',
          '--disable-web-resources',
          '--headless',
          'about:blank'
        ];
2024/11/05 18:25:13 Spawned child as 38642, communicating via websocket
2024/11/05 18:25:13 Connecting to ws://127.0.0.1:32288/devtools/browser/4d12a239-1e8d-4b14-9aa3-b5193c47c9ba
2024/11/05 18:25:28 Connection closed

I checked my process list and Chrome carried on running after "Connection closed" for a while, then it terminated while Perl did not.

My Chromium version: Chrome/129.0.6668.100
WWW-Mechanize-Chrome library version: 0.73
OS: FreeBSD 14.1-RELEASE-p5

Do let me know if you need any more info.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant