How can I force my program to use an updated version of Google-Chrome when using it in headless mode?

Question:

I have a Python script which uses Google Chrome to perform some tasks in YouTube Studio. The script works as expected when I disable:

options.add_argument('--headless')

but when I use it with the headless option it’s unable to find some elements, so I decided to take a screenshot to see what was going on.

enter image description here

It looks like, for some reason, when I use the headless mode, the executed Chrome version is older.

I have also tried to change the user agent: options.add_argument("–user-agent=User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/69.0.3497.100 Safari/537.36"), but it doesn’t work.

How can I execute an updated version of Chrome using headless mode?

Answers:

As suggested the problem was in the user agent version.

User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/69.0.3497.100 Safari/537.36

From the agent info we can see the chrome version is:

Chrome/69.0.3497.100

which is quite old version of chrome.

Try with newer version example:

Chrome/105.0.0.0

Simplest way to fetch actual version is from your browser.
Open new tab, click F12 or inspect – view page source,
Navigate to Network tab, Open some site ex: google.com, check some of the network requests. Select one of the requests until you see: "Request Headers" with the actual to your browser user-agent information.

Answered By: Infern0