Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Setting a custom userAgent in HTML or JavaScript

Tags:

Is there any way to do this? I'm trying to send a GET request to a website, but I want to customize my UserAgent. Is there any way to do this in pure HTML and JavaScript? I'd like it to all execute locally.

like image 317
user3528112 Avatar asked Apr 23 '14 15:04

user3528112


People also ask

Is userAgent deprecated?

The origin trial that allowed sites to test the fully reduced User-Agent will end on April 19, 2022. After that date, the User-Agent String will be gradually reduced. To review the whole schedule, see Chromium Blog: User-Agent Reduction Origin Trial and Dates.

What is userAgent in JS?

The userAgent property returns the user-agent header sent by the browser to the server. The userAgent property is read-only. The value returned, contains information about the browser name, version and platform. The web specification suggests that browsers should provide as little header information as possible.

How do I change user agent in HTML?

Select the “Advanced” tab and enable the “Show Develop menu in menu bar” option at the bottom of the window. Click Develop > User Agent and select the user agent you want to use in the list. If the user agent you want to use isn't shown here, select “Other” and you can provide a custom user agent.


1 Answers

This is working for me.

Object.defineProperty(navigator, 'userAgent', {     get: function () { return 'Mozilla/5.0 (Windows NT 6.2; WOW64; rv:28.0) Gecko/20100101 Firefox/28.0)'; } }); 

It is an updated version of code4coffee's answer as Object.prototype.__defineGetter__() is deprecated: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/__defineGetter__

like image 178
Peter Rhodes Avatar answered Oct 13 '22 08:10

Peter Rhodes