-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
528 lines (470 loc) · 26.4 KB
/
index.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1" />
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0">
<meta name="keywords"
content="browser detection, user-agent, javascript, detect os, mobile, tablet, detect device, cpu, javascript, nodejs, jquery, typescript, client hints, bots, iphone, ipad, android" />
<meta name="description" content="UAParser.js is the most comprehensive, compact, & up-to-date isomorphic JavaScript library to detect visitor's Browser, Engine, OS, CPU, and Device type/model.">
<meta name="application-name" content="UAParser.js">
<meta property="og:title" content="UAParser.js">
<meta property="og:url" content="https://alanhe421.github.io/ua-parser-js">
<meta property="og:image" content="https://uaparser.dev/images/uap-header.png">
<meta property="og:type" content="website">
<meta property="og:description" content="Abstract away the hassle of user-agent detection">
<meta property="og:locale" content="en_US">
<title>UAParser.js - Detect Browser, Engine, OS, CPU, and Device type/model from User-Agent & Client Hints data using JavaScript. Supports browser & node.js environment. Also available as jQuery plugin & TypeScript-ready development.</title>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/11.8.0/styles/default.min.css">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/11.8.0/styles/srcery.min.css">
<link rel="stylesheet" type="text/css" href="semantic-ui/semantic.css">
<link rel="stylesheet" type="text/css" href="https://cdn.jsdelivr.net/npm/toastify-js/src/toastify.min.css">
<link rel="stylesheet" type="text/css" href="css/style.css">
<link rel="icon" type="image/png" href="images/uap-logo.png">
<script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>
<script src="semantic-ui/semantic.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/clipboard.js/2.0.8/clipboard.min.js"></script>
<script src="js/ua-parser.js"></script>
<script src="js/ua-list-example.js"></script>
<script src="js/script.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/11.8.0/highlight.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/toastify-js"></script>
</head>
<body>
<div class="pusher">
<div class="ui inverted instagram vertical masthead center aligned segment">
<div class="ui text container">
<h1>UAParser.js</h1>
<h2>Abstracts Away The Hassle of User-Agent Detection</h2>
<div class="ui massive buttons">
<a href="#check" class="ui violet button"><i class="magic icon"></i>Check UA</a>
<a href="https://github.com/faisalman/ua-parser-js" class="ui green button" target="_blank"><i class="book icon"></i>Read Docs</a>
<a href="https://www.npmjs.com/package/ua-parser-js" class="ui blue button" target="_blank"><i class="download icon"></i>Download</a>
</div>
</div>
<img alt="UAParser.js Illustration" class="ui centered image illustration" src="images/uap-illustrations.png" />
</div>
<!--div id="try" class="ui text container">
<div class="ui horizontal divider">
FEATURED : OUR SPONSORS
</div>
<div class="ui tall stacked segment">
<div class="ui stackable grid">
<div class="column">
<a href="https://opencollective.com/ua-parser-js"
class="ui right floated large labeled icon button">
<i class="share icon"></i>PUT YOUR LOGO / TEXT HERE</a>
</div>
</div>
</div>
</div-->
<div class="ui text container">
<div id="demo" class="ui horizontal divider">
DEMO: USER-AGENT PLAYGROUND
</div>
<div class="ui tall stacked segment">
<div class="ui basic segment">
<div class="ui black massive label">
<p id="ua-txt" class="code"></p><button id="btn-clipboard"
class="ui right floated labeled icon violet large button" data-clipboard-target="#ua-txt"><i
class="clipboard icon"></i>COPY TO CLIPBOARD</button>
</div>
<div class="ui basic segment center aligned">
<p class="what-provides" id="ua-txt-info">
What your browser tells you = 😵💫 🤯 ❌
</p>
<div class="ui horizontal divider">
VS
</div>
<p class="what-provides">
What UAParser.js provides = 🙂 💲💲💲 ✅
</p>
</div>
<pre><code id="ua-result" class="language-json"></code></pre>
</div>
<div id="demo-result" class="ui equal width stackable internally celled grid">
<div class="row">
<div class="column">
<div class="ui center aligned animated icon">
<i class="edge icon"></i>
Browser
</div>
<div class="ui center aligned header">
<div class="header" id="browser-txt"></div>
</div>
<div class="ui basic segment">
<img alt="detected browser icon" class="ui tiny centered image" id="browser-img" src="">
</div>
</div>
<div class="column">
<div class="ui center aligned animated icon">
<i class="cogs icon"></i>
Engine
</div>
<div class="ui center aligned header">
<div class="header" id="engine-txt"></div>
</div>
<div class="ui basic segment">
<img alt="detected engine icon" class="ui tiny centered image" id="engine-img" src="">
</div>
</div>
<div class="column">
<div class="ui center aligned animated icon">
<i class="windows icon"></i>
OS
</div>
<div class="ui center aligned header">
<div class="header" id="os-txt"></div>
</div>
<div class="ui basic segment">
<img alt="detected os icon" class="ui tiny centered image" id="os-img" src="">
</div>
</div>
</div>
<div class="row">
<div class="column">
<div class="ui center aligned animated icon">
<i class="tv icon"></i>
Device
</div>
<div class="ui basic segment">
<img alt="detected device type icon" class="ui tiny centered image" id="type-img" src="">
<div class="ui center aligned header">
<div class="header" id="type-txt"></div>
</div>
</div>
</div>
<div class="column">
<div class="ui center aligned animated icon">
<i class="mobile alternate icon"></i>
Series
</div>
<div class="ui basic segment">
<img alt="detected device vendor icon" class="ui tiny centered image" id="device-img" src="">
<div class="ui center aligned header">
<div class="header" id="device-txt"></div>
</div>
</div>
</div>
<div class="column">
<div class="ui center aligned animated icon">
<i class="microchip icon"></i>
CPU
</div>
<div class="ui basic segment">
<img alt="detected cpu icon" class="ui tiny centered image" id="cpu-img" src="">
<div class="ui center aligned header">
<div id="cpu-txt"></div>
</div>
</div>
</div>
</div>
</div>
<div class="ui horizontal divider" id="check">
TRY MORE EXAMPLES
</div>
<form class="ui large form">
<div class="field">
<label>Pick another User-Agent to test:</label>
<select class="ui search dropdown" id="demo-select">
<option value="">Select</option>
</select>
</div>
<div class="field">
<label>OR simply type any User-Agent that you want to check:</label>
<div class="ui right action input">
<input type="text" name="custom-ua"
placeholder="Mozilla/5.0 (Linux; U; Android 4.0.3; H4NY4-C0NT0H Build/CR7) . . . .">
<div class="ui right labeled icon violet button" id="demo-btn">
<i class="redo alternate icon"></i>
CHECK
</div>
</div>
</div>
<div class="field">
</div>
</form>
</div>
<div id="gpu-divider" class="ui horizontal divider">
DETECT GPU FROM WEBGL DATA (EXPERIMENTAL FEATURE)
</div>
<div id="gpu-segment" class="ui tall stacked segment">
<div class="ui equal width stackable internally celled grid">
<div class="row">
<div class="column">
<div class="ui right aligned icon">
<i class="microchip icon"></i>
GPU
</div>
<img alt="detected gpu icon" class="ui tiny centered image" id="gpu-img" src="">
<div class="ui center aligned header">
<div id="gpu-txt"></div>
</div>
</div>
</div>
</div>
</div>
<div class="ui horizontal divider">
QUICKSTART
</div>
<div class="ui top attached tabular menu">
<a class="item active" data-tab="esm">ESM / TypeScript</a>
<a class="item" data-tab="node">Node.js</a>
<a class="item" data-tab="html">HTML</a>
<a class="item" data-tab="jquery">jQuery</a>
<a class="item" data-tab="cli">Command Line</a>
</div>
<div class="ui bottom attached tab tall stacked segment active" data-tab="esm">
<div class="ui basic segment">
<p>To get started, install UAParser.js using npm:</p>
<pre><code>$ npm install ua-parser-js
</code></pre>
<p>Then, import the library in your application:</p>
<pre><code class="language-js">import { UAParser } from 'ua-parser-js';
const ua = 'Mozilla/5.0 (X11; U; Linux armv7l; en-GB; rv:1.9.2a1pre)
Gecko/20090928 Firefox/3.5 Maemo Browser 1.4.1.22 RX-51 N900';
const { browser, cpu, device } = UAParser(ua);
console.log(browser.name); // Maemo Browser
console.log(cpu.is('arm')); // true
console.log(device.is('mobile')); // true
console.log(device.vendor); // Nokia
console.log(device.model); // N900
</code></pre>
<a href="https://docs.uaparser.dev/intro/quick-start/using-es-modules-typescript.html" class="ui large violet button"><i class="external alternate icon"></i>READ THE DOCS</a>
</div>
</div>
<div class="ui bottom attached tab tall stacked segment" data-tab="html">
<div class="ui basic segment">
<p>Download UAParser.js from the official GitHub repository: <a href="https://github.com/faisalman/ua-parser-js/blob/master/dist/ua-parser.min.js">ua-parser-js</a>, then place the following script tag in your HTML file to include the library:</p>
<pre><code class="language-js"><script src="ua-parser.min.js"></script>
</code></pre>
<p>Alternatively, you can use a CDN like <a href="https://cdn.jsdelivr.net/npm/ua-parser-js/src/ua-parser.min.js">jsDelivr</a> or <a href="https://cdnjs.com/libraries/UAParser.js">cdnjs</a> in your script tag:</p>
<pre><code class="language-js"><script src="https://cdn.jsdelivr.net/npm/ua-parser-js/dist/ua-parser.min.js"></script>
</code></pre>
<p>Then, use the library in your HTML page:</p>
<pre><code class="language-html">
<!doctype html>
<html>
<head>
<script src="ua-parser.min.js"></script>
<script>
const uap = new UAParser();
console.log(uap.getResult());
/*
/// This will print an object structured like this:
{
ua: "",
browser: {
name: "",
version: "",
major: "",
type: ""
},
engine: {
name: "",
version: ""
},
os: {
name: "",
version: ""
},
device: {
model: "",
type: "",
vendor: ""
},
cpu: {
architecture: ""
}
}
*/
// The result depends on current window.navigator.userAgent value
// Now let's try a custom user-agent string as an example
const uastring1 = "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/535.2 (KHTML, like Gecko) Ubuntu/11.10 Chromium/15.0.874.106 Chrome/15.0.874.106 Safari/535.2";
uap.setUA(uastring1);
const result = uap.getResult();
console.log(result.browser); // {name: "Chromium", version: "15.0.874.106", major: "15", type: undefined}
console.log(result.device); // {model: undefined, type: undefined, vendor: undefined}
console.log(result.os); // {name: "Ubuntu", version: "11.10"}
console.log(result.os.version); // "11.10"
console.log(result.engine.name); // "WebKit"
console.log(result.cpu.architecture); // "amd64"
// Do some other tests
const uastring2 = "Mozilla/5.0 (compatible; Konqueror/4.1; OpenBSD) KHTML/4.1.4 (like Gecko)";
console.log(uap.setUA(uastring2).getBrowser().name); // "Konqueror"
console.log(uap.getOS()); // {name: "OpenBSD", version: undefined}
console.log(uap.getEngine()); // {name: "KHTML", version: "4.1.4"}
const uastring3 = 'Mozilla/5.0 (PlayBook; U; RIM Tablet OS 1.0.0; en-US) AppleWebKit/534.11 (KHTML, like Gecko) Version/7.1.0.7 Safari/534.11';
console.log(uap.setUA(uastring3).getDevice().model); // "PlayBook"
console.log(uap.getOS()); // {name: "RIM Tablet OS", version: "1.0.0"}
console.log(uap.getBrowser().name); // "Safari"
</script>
</head>
<body>
</body>
</html>
</code></pre>
<a href="https://docs.uaparser.dev/intro/quick-start/using-html.html" class="ui large violet button"><i class="external alternate icon"></i>READ THE DOCS</a>
</div>
</div>
<div class="ui bottom attached tab tall stacked segment" data-tab="node">
<div class="ui basic segment">
<p>In a server-side environment like Node.js, UAParser.js can parse the <code>[User-Agent]</code> and <code>[Sec-CH-UA-*]</code> headers from the incoming HTTP requests. </p>
<p>To get started, install UAParser.js using npm:</p>
<pre><code>$ npm install ua-parser-js
</code></pre>
<p>Then, require the library in your Node.js application:</p>
<pre><code class="language-js">const http = require('http');
const uap = require('ua-parser-js');
http.createServer(function (req, res) {
// get user-agent header
let ua = uap(req.headers['user-agent']);
/*
// Since v2.0.0
// you can also pass Client Hints data to UAParser
// note: only works in a secure context (localhost or https://)
// from any browsers that are based on Chrome 85+
// https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Sec-CH-UA
const getHighEntropyValues = 'Sec-CH-UA-Full-Version-List, Sec-CH-UA-Mobile, Sec-CH-UA-Model, Sec-CH-UA-Platform, Sec-CH-UA-Platform-Version, Sec-CH-UA-Arch, Sec-CH-UA-Bitness';
res.setHeader('Accept-CH', getHighEntropyValues);
res.setHeader('Critical-CH', getHighEntropyValues);
ua = uap(req.headers).withClientHints();
*/
// write the result as response
res.end(JSON.stringify(ua, null, ' '));
})
.listen(1337, '127.0.0.1');
console.log('Server running at http://127.0.0.1:1337/');
</code></pre>
<a href="https://docs.uaparser.dev/intro/quick-start/using-node-js.html" class="ui large violet button"><i class="external alternate icon"></i>READ THE DOCS</a>
</div>
</div>
<div class="ui bottom attached tab tall stacked segment" data-tab="jquery">
<div class="ui basic segment">
<p>Although written in vanilla JavaScript, UAParser.js automatically detects the presence of <code>jQuery</code> (or <code>Zepto</code>) and creates a <code>$.ua</code> object in addition to the <code>window.UAParser</code> constructor.</p>
<h4>Properties</h4>
<p>The result of detected user-agent</p>
<ul>
<li><code>$.ua.browser</code></li>
<li><code>$.ua.cpu</code></li>
<li><code>$.ua.device</code></li>
<li><code>$.ua.engine</code></li>
<li><code>$.ua.os</code></li>
</ul>
<h4>Methods</h4>
<p>To get or set the user-agent</p>
<ul>
<li><code>$.ua.get()</code></li>
<li><code>$.ua.set(ua)</code></li>
</ul>
<h4>Code Example:</h4>
<pre><code>// Say we are in a browser where jQuery is present
// with user-agent: "Mozilla/5.0 (Linux; U; Android 2.3.4; en-us; Sprint APA7373KT Build/GRJ22) AppleWebKit/533.1 (KHTML, like Gecko) Version/4.0"
// Get the details
console.log($.ua.device); // {vendor: "HTC", model: "Evo Shift 4G", type: "mobile"}
console.log($.ua.os); // {name: "Android", version: "2.3.4"}
console.log($.ua.os.name); // "Android"
console.log($.ua.get()); // "Mozilla/5.0 (Linux; U; Android 2.3.4; en-us; Sprint APA7373KT Build/GRJ22) AppleWebKit/533.1 (KHTML, like Gecko) Version/4.0"
if($.ua.browser.is("IE")) {
alert("Please upgrade!");
}
// Now let's try another custom user-agent
$.ua.set('Mozilla/5.0 (Linux; U; Android 3.0.1; en-us; Xoom Build/HWI69) AppleWebKit/534.13 (KHTML, like Gecko) Version/4.0 Safari/534.13');
// Test again
console.log($.ua.browser.name); // "Safari"
console.log($.ua.engine.name); // "Webkit"
console.log($.ua.device); // {vendor: "Motorola", model: "Xoom", type: "tablet"}
console.log($.ua.browser.version); // "4.0"
console.log($.ua.browser.major); // "4"
// Add class to <body> tag
// <body class="ua-browser-safari ua-devicetype-tablet">
$('body')
.addClass(
'ua-browser-' +
$.ua.browser.name +
' ua-devicetype-' +
$.ua.device.type);
</code></pre>
<a href="https://docs.uaparser.dev/intro/quick-start/using-jquery.html" class="ui large violet button"><i class="external alternate icon"></i>READ THE DOCS</a>
</div>
</div>
<div class="ui bottom attached tab tall stacked segment" data-tab="cli">
<div class="ui basic segment">
You can use <code>npx</code> to run UAParser.js from the command line without installing the package:
<pre><code>$ npx ua-parser-js "Flock/2.16 (Zenwalk 7.3; es_PR;)"
# console output:
"
[
{
"ua": "Flock/2.16 (Zenwalk 7.3; es_PR;)",
"browser": {
"name": "Flock",
"version": "2.16",
"major": "2"
},
"cpu": {},
"device": {},
"engine": {},
"os": {
"name": "Zenwalk",
"version": "7.3"
}
}
]
"
# let's save the result into a log file:
$ npx ua-parser-js "Flock/2.16 (Zenwalk 7.3; es_PR;)" >> log.txt
</code></pre>
<a href="https://docs.uaparser.dev/intro/quick-start/using-cli.html" class="ui large violet button"><i class="external alternate icon"></i>READ THE DOCS</a>
</div>
</div>
</div>
<div class="ui hidden divider">
</div>
</div>
<div class="ui instagram inverted vertical footer segment">
<div class="ui text container">
<div class="ui stackable inverted divided equal height stackable grid">
<div class="five wide column">
<div class="ui basic right aligned segment">
<img alt="UAParser.js logo transparent" class="ui centered small image" src="images/uap-logo-transparent.png">
</div>
</div>
<div class="eleven wide column">
<div class="ui basic right aligned segment">
<div class="ui inverted link animated selection horizontal list">
<a target="_blank" class="item" href="https://github.com/faisalman/ua-parser-js"><img
alt="GitHub stars badge" src="https://img.shields.io/github/stars/faisalman/ua-parser-js?color=yellow&logo=github&style=for-the-badge"></a>
<a target="_blank" class="item" href="https://www.npmjs.com/package/ua-parser-js"><img
alt="NPM downloads badge" src="https://img.shields.io/npm/dm/ua-parser-js?color=red&logo=npm&label=NPM%20DOWNLOADS&style=for-the-badge"></a>
<a target="_blank" class="item" href="https://www.npmjs.com/package/ua-parser-js"><img
alt="NPM latest version badge" src="https://img.shields.io/npm/v/ua-parser-js.svg?logo=npm&color=red&style=for-the-badge"></a>
<a target="_blank" class="item"
href="https://www.jsdelivr.com/package/npm/ua-parser-js"><img
alt="Jsdelivr badge" src="https://img.shields.io/jsdelivr/npm/hm/ua-parser-js?logo=jsdelivr&style=for-the-badge"></a>
<a target="_blank" class="item" href="https://bundlephobia.com/package/ua-parser-js"><img
alt="Bundlephobia badge" src="https://img.shields.io/bundlephobia/minzip/ua-parser-js?logo=hackthebox&logoColor=white&style=for-the-badge" /></a>
<a target="_blank" class="item"
href="https://github.com/faisalman/ua-parser-js/graphs/contributors"><img
alt="GitHub sponsors badge" src="https://img.shields.io/github/contributors/faisalman/ua-parser-js?color=purple&logo=githubsponsors&style=for-the-badge"></a>
<a target="_blank" class="item" href="https://cdnjs.com/libraries/UAParser.js"><img
alt="CDNJS badge" src="https://img.shields.io/cdnjs/v/UAParser.js.svg?color=orange&style=for-the-badge"></a>
<a href="https://opencollective.com/ua-parser-js" target="_blank" class="item"><img
alt="OpenCollective badge"
src="https://img.shields.io/opencollective/all/ua-parser-js?color=teal&style=for-the-badge"></a>
<a href="https://github.com/faisalman/ua-parser-js" target="_blank" class="item">
<img alt="OSSF Scorecard badge" src="https://img.shields.io/ossf-scorecard/github.com/faisalman/ua-parser-js?label=openssf%20scorecard&style=for-the-badge"></a>
<iframe src="https://github.com/sponsors/faisalman/button" title="Github Sponsor"
height="32" width="114" style="border: 0; border-radius: 6px;"></iframe>
</div>
</div>
</div>
</div>
<div class="ui right aligned basic segment">
<p>UAParser.js is licensed under MIT / AGPLv3 / PRO licenses. Copyright (c) 2012-2024 Faisal Salman.</p>
</div>
</div>
</div>
</div>
</body>
</html>