symfonygoogle-chromeuser-agentsymfony-panther

Change user-agent for Symfony Panther Chromeclient


How do I change the user-agent in a headless Chrome created by Symfony's Panther createChromeClient()?

When I create a Chrome client with

$client = \Symfony\Component\Panther\Client::createChromeClient();

I see in the access_log a user-agent of

"Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) HeadlessChrome/77.0.3865.90 Safari/537.36"

I searched for solutions, and think I have to change the user-agent string via the arguments of the chrome, but can't find the right way, because the answers on the web aren't for PHP or Panther.

Cheers!


Solution

  • I found it:

    $client = \Symfony\Component\Panther\Client::createChromeClient(null, [
                '--user-agent=Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/79.0.3945.88 Safari/537.36',
                '--window-size=1200,1100',
                '--headless',
                '--disable-gpu',
    ]);
    

    This question gave me the idea.