-
-
Save jrran90/2941ed9cae82af09fae4cda6826d8b4e to your computer and use it in GitHub Desktop.
Override user agent on all browsers
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| function setUserAgent(window, userAgent) { | |
| // Works on Firefox, Chrome, Opera and IE9+ | |
| if (navigator.__defineGetter__) { | |
| navigator.__defineGetter__('userAgent', function () { | |
| return userAgent; | |
| }); | |
| } else if (Object.defineProperty) { | |
| Object.defineProperty(navigator, 'userAgent', { | |
| get: function () { | |
| return userAgent; | |
| } | |
| }); | |
| } | |
| // Works on Safari | |
| if (window.navigator.userAgent !== userAgent) { | |
| var userAgentProp = { | |
| get: function () { | |
| return userAgent; | |
| } | |
| }; | |
| try { | |
| Object.defineProperty(window.navigator, 'userAgent', userAgentProp); | |
| } catch (e) { | |
| window.navigator = Object.create(navigator, { | |
| userAgent: userAgentProp | |
| }); | |
| } | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment