6

I have an issue with changing the user agent.

I am trying to use the following line in my runner.js file in the browsers array :

chrome:headless:userAgent=Mozilla/5.0\ \(Linux\;\ Android\ 5.0\;\ SM-G900P\ Build/LRX21T\)\ AppleWebKit/537.36\ \(KHTML,\ like\ Gecko\)\ Chrome/57.0.2987.133\ Mobile\ Safari/537.36

However, the best I can get is Mozilla/5.0 (Linux in the actual user agent.

The guide doesn't say anything explicit about user agents and how to escape them.

Could someone help me with using a custom user agent for the headless chrome? I can't seem to get over the escaping problem. Thanks.

Alex Skorkin
  • 4,264
  • 3
  • 25
  • 47
Istvan Fulop
  • 141
  • 1
  • 8

1 Answers1

5

I actually found the answer, you need to escape with \\ every ; character.

E.g:

chrome:headless:userAgent=Mozilla/5.0 (X11\\; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/60.0.3112.50 Safari/537.36

will work.

In case of using in cli command you need to double escape. (I didn't have success in that)

Istvan Fulop
  • 141
  • 1
  • 8
  • I am facing similar issue. I am setting chromeargs : = ["--headless", "--disable-gpu", "--window-size=1920,1080", "--no-sandbox", "--disable-dev-shm-usage", "--disable-extensions", "--start-maximized", '--user-agent=Mozilla/5.0 (X11\\; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/94.0.4606.61 Safari/537.36']; url is still blocked – sathiya Nov 30 '21 at 18:54