Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
SeleniumHQ
GitHub Repository: SeleniumHQ/Selenium
Path: blob/trunk/third_party/closure/goog/labs/useragent/device.js
4140 views
1
/**
2
* @license
3
* Copyright The Closure Library Authors.
4
* SPDX-License-Identifier: Apache-2.0
5
*/
6
7
/**
8
* @fileoverview Closure user device detection (based on user agent).
9
* @see http://en.wikipedia.org/wiki/User_agent
10
* For more information on browser brand, platform, or engine see the other
11
* sub-namespaces in goog.labs.userAgent (browser, platform, and engine).
12
*/
13
14
goog.provide('goog.labs.userAgent.device');
15
16
goog.require('goog.labs.userAgent');
17
goog.require('goog.labs.userAgent.util');
18
19
/**
20
* Currently we detect the iPhone, iPod and Android mobiles (devices that have
21
* both Android and Mobile in the user agent string).
22
*
23
* @return {boolean} Whether the user is using a mobile device.
24
*/
25
goog.labs.userAgent.device.isMobile = function() {
26
'use strict';
27
if (goog.labs.userAgent.util.ASSUME_CLIENT_HINTS_SUPPORT ||
28
goog.labs.userAgent.useClientHints() &&
29
goog.labs.userAgent.util.getUserAgentData()) {
30
return goog.labs.userAgent.util.getUserAgentData().mobile;
31
}
32
return !goog.labs.userAgent.device.isTablet() &&
33
(goog.labs.userAgent.util.matchUserAgent('iPod') ||
34
goog.labs.userAgent.util.matchUserAgent('iPhone') ||
35
goog.labs.userAgent.util.matchUserAgent('Android') ||
36
goog.labs.userAgent.util.matchUserAgent('IEMobile'));
37
};
38
39
40
/**
41
* Currently we detect Kindle Fire, iPad, and Android tablets (devices that have
42
* Android but not Mobile in the user agent string).
43
*
44
* @return {boolean} Whether the user is using a tablet.
45
*/
46
goog.labs.userAgent.device.isTablet = function() {
47
'use strict';
48
if (goog.labs.userAgent.util.ASSUME_CLIENT_HINTS_SUPPORT ||
49
(goog.labs.userAgent.useClientHints() &&
50
goog.labs.userAgent.util.getUserAgentData())) {
51
return !goog.labs.userAgent.util.getUserAgentData().mobile &&
52
(goog.labs.userAgent.util.matchUserAgent('iPad') ||
53
goog.labs.userAgent.util.matchUserAgent('Android') ||
54
goog.labs.userAgent.util.matchUserAgent('Silk'));
55
}
56
return goog.labs.userAgent.util.matchUserAgent('iPad') ||
57
(goog.labs.userAgent.util.matchUserAgent('Android') &&
58
!goog.labs.userAgent.util.matchUserAgent('Mobile')) ||
59
goog.labs.userAgent.util.matchUserAgent('Silk');
60
};
61
62
63
/**
64
* @return {boolean} Whether the user is using a desktop computer (which we
65
* assume to be the case if they are not using either a mobile or tablet
66
* device).
67
*/
68
goog.labs.userAgent.device.isDesktop = function() {
69
'use strict';
70
return !goog.labs.userAgent.device.isMobile() &&
71
!goog.labs.userAgent.device.isTablet();
72
};
73
74