0

It doesn't appear this is possible, looking at the Mozilla docs, but I came upon this answer which doesn't make sense to me. The reason I want to do this is that I want to trick Bing into thinking it is being accessed by a mobile device/browser.

L8R
  • 401
  • 5
  • 21
  • The code in that answer is purposed to be run in the window you're opening. – Teemu Sep 16 '22 at 11:52
  • Why do you need to change the UserAgent? – mx0 Sep 16 '22 at 11:58
  • @mx0 To trick a website into thinking a mobile device is accessing it. – L8R Sep 16 '22 at 23:05
  • @hackerman what's exactly your use case? who is going to access that website? – mx0 Sep 17 '22 at 11:23
  • @mx0 I am making a website that opens to Bing on a smaller window. The site was ideally made for PC browsers, but I am not sure if it would work on mobile browsers. – L8R Sep 17 '22 at 13:27

1 Answers1

0

You can't modify the UserAgent property using JavaScript.

From Mozilla Docs

The Navigator.userAgent read-only property returns the user agent string for the current browser.

It is possible to change the User-Agent header for a XHR request but it doesn't work for the Chrome browser.

mx0
  • 6,445
  • 12
  • 49
  • 54
  • You can, the code at the linked post works as it is. I'm not sure, if it changes the value of `userAgent` of the HTTP headers in the requests, though. – Teemu Sep 16 '22 at 11:50
  • 1
    Browser will still send the true header, you cannot spoof `User-Agent` anymore. I'm not sure about XHR request... – mx0 Sep 16 '22 at 11:54
  • @Teemu The code at the linked post is meant for iframe. – L8R Sep 17 '22 at 00:27