Issue: Audit usage of navigator.userAgent, navigator.appVersion, and navigator.platform
The reason one sees the message is well explained in the description of the very same message (audit).
The real question is who/what is the source of it. There is a hint to the file extended-css.js
.
Here is an example with another file (as I do not have the extended-css.js
):
Right click on the file and then choose Open in new tab
.
So there you can see that the reason for the audit message is the hook.js
file from the Vue.js devtools extension.
In your case it would be another extension or library you are using - direct or indirect (for example a part of vuetify
, etc.).
From there you have 3 choices:
- ignore it
- wait for the authors of the library to fix the issue and update it
- disable the extension/remove the library causing it.
I cannot use console.log, console.warn, console.error in browser
I've found the solution to it. Turn out I run npm run dev
instead of npm run watch
. I'm not sure how this work but when I change to use npm run watch
it works fine.
How to determine browser platform without navigator.platform
It turns out that the only realistic option for now is to look at the User Agent string and make decisions based on that (either by handrolling code, or using a user agent parsing library that does that for you).
This is not ideal, but as the goal is OS detection, and explicitly not browser detection, it's also not too hacky or liable to break in the future.
Changing navigator.userAgent using Chrome Extension
navigator.userAgent
is a read-only property. If you want to change navigator.userAgent
, then you need to either create a new object and copy the properties, or create a new object and inherit from navigator
and assign a new getter/setter.
I've recently created such an extension. I'm on Linux, though I occasionally download the Chrome for Windows. The following extension changes the user agent to Windows XP on Chrome's download page:
contentscript.js
var actualCode = '(' + function() {
'use strict';
var navigator = window.navigator;
var modifiedNavigator;
if ('userAgent' in Navigator.prototype) {
// Chrome 43+ moved all properties from navigator to the prototype,
// so we have to modify the prototype instead of navigator.
modifiedNavigator = Navigator.prototype;
} else {
// Chrome 42- defined the property on navigator.
modifiedNavigator = Object.create(navigator);
Object.defineProperty(window, 'navigator', {
value: modifiedNavigator,
configurable: false,
enumerable: false,
writable: false
});
}
// Pretend to be Windows XP
Object.defineProperties(modifiedNavigator, {
userAgent: {
value: navigator.userAgent.replace(/\([^)]+\)/, 'Windows NT 5.1'),
configurable: false,
enumerable: true,
writable: false
},
appVersion: {
value: navigator.appVersion.replace(/\([^)]+\)/, 'Windows NT 5.1'),
configurable: false,
enumerable: true,
writable: false
},
platform: {
value: 'Win32',
configurable: false,
enumerable: true,
writable: false
},
});
} + ')();';
var s = document.createElement('script');
s.textContent = actualCode;
document.documentElement.appendChild(s);
s.remove();
manifest.json
{
"name": "navigator.userAgent",
"description": "Change navigator.userAgent to Windows on Chrome's download page.",
"version": "1",
"manifest_version": 2,
"content_scripts": [{
"run_at": "document_start",
"js": ["contentscript.js"],
"matches": [
"*://www.google.com/intl/*/chrome/browser/*"
]
}]
}
As you can see, I'm declaring the content script instead of dynamically inserting it, to make sure that my code runs before the page is loaded. Further, I'm using one of the tricks described in this answer to change the page's navigator
instead of some other navigator
in the isolated content script world.
Note that this only modifies the userAgent as seen from JavaScript. If you want to modify the user agent that's sent to the server, take a look at Associate a custom user agent to a specific Google Chrome page/tab.
What is the list of possible values for navigator.platform as of today?
Disclaimer: please note this property is sent by the browser and can thus be faked, just like user agent strings. Never rely on the navigator
object to be completely accurate.
The definition
As far as I know there isn't a single public list of all possible `navigator.platform` values, even though the property has been around for quite a bit. To make things worse, the property's definition changed throughout the years. It used to be:
navigator.platform
indicates the machine type for which the browser was compiled.
This basically means the property can return Win16
when the user is running a browser compiled for 16-bit, even though the user is on a 32-bit or 64-bit Windows machine.
Of course W3Schools lists the old definition (I'm not even gonna link to them). W3 and MDN have agreed on a different definition though:
navigator.platform
represents the platform on which the browser is executing.
Still, this definition is a bit vague. A decade ago a 'platform' would either be a CPU architecture or an operating system. In recent years handheld and media devices can be platforms too.
The interpretation
As with everything on the web, our fate is in the hands of the mighty browser vendors. In this case, all the major browsers (IE, Safari, Firefox and Chrome) agree that my 64-bit Windows machine is a `Win32` platform. This means they're sticking to the old definition as far as Windows goes, because none of them are compiled for 64-bit thus far. Look on the bright side though: at least they all agree on something for once.It seems like we're a bit luckier when it comes to handheld and media devices. As you've already stated in your question, the iPhone, iPod and iPad each got a unique value, even though they're all running the same operating system. All of Nintendo's and Sony's devices are returning unique values too. So only now navigator.platform
is starting to look interesting.
But then Opera Mini for iPhone comes along, messing things up again. Opera Mini actually returns a code engine version number, which is a completely different interpretation of platform
than anything we've come across so far. So now we're back where we started and we start to understand why there's so little information on this subject out there.
Even though the interpretations vary and I don't have a complete answer for you, I did feel like I should add my 2 cents for anyone else out there researching the navigator.platform
property.
The list
Below is a (definitely non-definite) list of the values I know of that I could verify with multiple sources. Because of the vague definition, I'm not too sure what the best way to order these is. For now I divided them into a few categories based on operating system or device brand and listed additional information and release dates where applicable.Android
It's really hard to test for Android devices. Android devices will return Android
just as often as some version of Linux. For example on a Nexus 5 phone, both the Android browser and Chrome return Linux armv7l
. In rare cases Android devices can even return null
(instead of undefined
).
Android
(2008)Linux
: see notes abovenull
Apple
As far as iOS goes: Safari, Chrome and Mercury agree, but Opera messes things up.
iPhone
(2007)iPod
(2007)iPad
(2010)iPhone Simulator
: simulator shipped with XcodeiPod Simulator
: simulator shipped with XcodeiPad Simulator
: simulator shipped with XcodeMacintosh
MacIntel
: Intel processor (2005)MacPPC
: PowerPC processorMac68K
: 68000 processorPike v7.6 release 92
: Opera Mini 5 on any iPhone (2009)Pike v7.8 release 517
: Opera Mini 7 on any iPhone (2012)
BlackBerry
BlackBerry
(2003)
FreeBSD
FreeBSD
FreeBSD i386
: x86 (IA-32) processorFreeBSD amd64
: AMD x86-64 processor
Linux
Seriously unreliable because so many platforms are built on this. For example, Chrome on ChromeOS or Linux x86-64 both return Linux i686
as that's what they were compiled for.
Note Linux ARM lists architecture flags, e.g. armv5tej
would denote a v5 ARM architecture with Thumb support ('T'), a DSP instruction set ('E'), and Jazelle support ('J').
Linux
Linux aarch64
Linux armv5tejl
Linux armv6l
Linux armv7l
Linux armv8l
Linux i686
Linux i686 on x86_64
Linux i686 X11
: based on X11 Window SystemLinux MSM8960_v3.2.1.1_N_R069_Rev:18
: Sony Xperia VLinux ppc64
Linux x86_64
Linux x86_64 X11
: based on X11 Window System
Microsoft
Even on a 64-bit Windows 8 they all stick to Win32
.
OS/2
(1994†)Pocket PC
Windows
Win16
: Windows 3.1x (1992†)Win32
: Windows 95 and upWinCE
Mozilla (Firefox OS)
An empty string is returned in the web browser on Firefox OS. See this bug report.
KaiOS
The web browser on KaiOS (based on Firefox) also returns the empty string (same as Firefox OS). See this bug report.
Nintendo
New Nintendo 3DS
(2014)Nintendo DSi
(2008)Nintendo 3DS
(2011)Nintendo Wii
(2006)Nintendo WiiU
(2012)
OpenBSD
OpenBSD amd64
Symbian / S40
Nokia_Series_40
(1999†)S60
(2002†)Symbian
: Opera on SymbianSymbian OS
Palm
PalmOS
(1996)webOS
(2009)
Solaris
SunOS
SunOS i86pc
SunOS sun4u
: SPARC processor
Sony
PLAYSTATION 3
(2006)PlayStation 4
(2013)PSP
: PlayStation Portable (2004)
Various
HP-UX
: Hewlett-Packard UniXmasking-agent
: value changes to this when using Masking Agent for FirefoxWebTV OS
X11
: X11 Window System
Have a device that's not on this list? Please leave a comment listing your device's properties and its navigator.platform
value (feel free to use this JSFiddle to find the value).
Related Topics
Django, Content Security Policy Directive
Code Folding for CSS in Vscode
How to I Solve This SASS Interpolation Issue
CSS: Nth-Of-Type() and: Not() Selector
Fix Div to Bottom Without Using CSS Position
Reactjs Change Background Image Dynamically
Jquery UI Styled Text Input Box
How to Add Classes to Laravel 4 Forms
Targeting Specific Column in Table
CSS Center Image in a Clipped Parent Div
Bootstrap 3: How to Create Responsive, Square .Thumbnail Divs
Two Divs on The Same Row and Center Align Both of Them
Background Position, Margin-Top
Chrome Not Picking Up @Font-Face Otf
Selecting Children Elements But Not Grandchildren
Twitter Bootstrap Accordion and Button Dropdown Overflow Issue