Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
seleniumhq
GitHub Repository: seleniumhq/selenium
Path: blob/trunk/javascript/atoms/userAgent.js
2884 views
1
// Licensed to the Software Freedom Conservancy (SFC) under one
2
// or more contributor license agreements. See the NOTICE file
3
// distributed with this work for additional information
4
// regarding copyright ownership. The SFC licenses this file
5
// to you under the Apache License, Version 2.0 (the
6
// "License"); you may not use this file except in compliance
7
// with the License. You may obtain a copy of the License at
8
//
9
// http://www.apache.org/licenses/LICENSE-2.0
10
//
11
// Unless required by applicable law or agreed to in writing,
12
// software distributed under the License is distributed on an
13
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14
// KIND, either express or implied. See the License for the
15
// specific language governing permissions and limitations
16
// under the License.
17
18
/**
19
* @fileoverview Similar to goog.userAgent.isVersion, but with support for
20
* getting the version information when running in a firefox extension.
21
*/
22
goog.provide('bot.userAgent');
23
24
goog.require('goog.string');
25
goog.require('goog.userAgent');
26
goog.require('goog.userAgent.product');
27
goog.require('goog.userAgent.product.isVersion');
28
29
30
/**
31
* Whether the rendering engine version of the current browser is equal to or
32
* greater than the given version. This implementation differs from
33
* goog.userAgent.isVersion in the following ways:
34
* <ol>
35
* <li>in a Firefox extension, tests the engine version through the XUL version
36
* comparator service, because no window.navigator object is available
37
* <li>in IE, compares the given version to the current documentMode
38
* </ol>
39
*
40
* @param {string|number} version The version number to check.
41
* @return {boolean} Whether the browser engine version is the same or higher
42
* than the given version.
43
*/
44
bot.userAgent.isEngineVersion = function (version) {
45
if (goog.userAgent.IE) {
46
return goog.string.compareVersions(
47
/** @type {number} */(goog.userAgent.DOCUMENT_MODE), version) >= 0;
48
} else {
49
return goog.userAgent.isVersionOrHigher(version);
50
}
51
};
52
53
54
/**
55
* Whether the product version of the current browser is equal to or greater
56
* than the given version. This implementation differs from
57
* goog.userAgent.product.isVersion in the following ways:
58
* <ol>
59
* <li>in a Firefox extension, tests the product version through the XUL version
60
* comparator service, because no window.navigator object is available
61
* <li>on Android, always compares to the version to the OS version
62
* </ol>
63
*
64
* @param {string|number} version The version number to check.
65
* @return {boolean} Whether the browser product version is the same or higher
66
* than the given version.
67
*/
68
bot.userAgent.isProductVersion = function (version) {
69
if (goog.userAgent.product.ANDROID) {
70
return goog.string.compareVersions(
71
bot.userAgent.ANDROID_VERSION_, version) >= 0;
72
} else {
73
return goog.userAgent.product.isVersion(version);
74
}
75
};
76
77
78
/**
79
* Whether we are a WebExtension.
80
*
81
* @const
82
* @type {boolean}
83
*/
84
bot.userAgent.WEBEXTENSION = (function () {
85
// The content script global object is different than it's window
86
// Which requires accessing the chrome and browser objects through this
87
try {
88
return !!((goog.global.chrome || goog.global.browser)['extension']);
89
} catch (e) {
90
return false;
91
}
92
})();
93
94
/**
95
* Whether we are on IOS.
96
*
97
* @const
98
* @type {boolean}
99
*/
100
bot.userAgent.IOS = goog.userAgent.product.IPAD ||
101
goog.userAgent.product.IPHONE;
102
103
104
/**
105
* Whether we are on a mobile browser.
106
*
107
* @const
108
* @type {boolean}
109
*/
110
bot.userAgent.MOBILE = bot.userAgent.IOS || goog.userAgent.product.ANDROID;
111
112
113
/**
114
* Android Operating System Version.
115
* @private {string}
116
* @const
117
*/
118
bot.userAgent.ANDROID_VERSION_ = (function () {
119
if (goog.userAgent.product.ANDROID) {
120
var userAgentString = goog.userAgent.getUserAgentString();
121
var match = /Android\s+([0-9\.]+)/.exec(userAgentString);
122
return match ? match[1] : '0';
123
} else {
124
return '0';
125
}
126
})();
127
128
129
/**
130
* Whether the current document is IE in a documentMode older than 8.
131
* @type {boolean}
132
* @const
133
*/
134
bot.userAgent.IE_DOC_PRE8 = goog.userAgent.IE &&
135
!goog.userAgent.isDocumentModeOrHigher(8);
136
137
138
/**
139
* Whether the current document is IE in IE9 (or newer) standards mode.
140
* @type {boolean}
141
* @const
142
*/
143
bot.userAgent.IE_DOC_9 = goog.userAgent.isDocumentModeOrHigher(9);
144
145
146
/**
147
* Whether the current document is IE in a documentMode older than 9.
148
* @type {boolean}
149
* @const
150
*/
151
bot.userAgent.IE_DOC_PRE9 = goog.userAgent.IE &&
152
!goog.userAgent.isDocumentModeOrHigher(9);
153
154
155
/**
156
* Whether the current document is IE in IE10 (or newer) standards mode.
157
* @type {boolean}
158
* @const
159
*/
160
bot.userAgent.IE_DOC_10 = goog.userAgent.isDocumentModeOrHigher(10);
161
162
163
/**
164
* Whether the current document is IE in a documentMode older than 10.
165
* @type {boolean}
166
* @const
167
*/
168
bot.userAgent.IE_DOC_PRE10 = goog.userAgent.IE &&
169
!goog.userAgent.isDocumentModeOrHigher(10);
170
171
172
/**
173
* Whether the current browser is Android pre-gingerbread.
174
* @type {boolean}
175
* @const
176
*/
177
bot.userAgent.ANDROID_PRE_GINGERBREAD = goog.userAgent.product.ANDROID &&
178
!bot.userAgent.isProductVersion(2.3);
179
180
181
/**
182
* Whether the current browser is Android pre-icecreamsandwich
183
* @type {boolean}
184
* @const
185
*/
186
bot.userAgent.ANDROID_PRE_ICECREAMSANDWICH = goog.userAgent.product.ANDROID &&
187
!bot.userAgent.isProductVersion(4);
188
189
190
/**
191
* Whether the current browser is Safari 6.
192
* @type {boolean}
193
* @const
194
*/
195
bot.userAgent.SAFARI_6 = goog.userAgent.product.SAFARI &&
196
bot.userAgent.isProductVersion(6);
197
198
199
/**
200
* Whether the current browser is Windows Phone.
201
* @type {boolean}
202
* @const
203
*/
204
bot.userAgent.WINDOWS_PHONE = goog.userAgent.IE &&
205
goog.userAgent.getUserAgentString().indexOf('IEMobile') != -1;
206
207