* Return an object containing the name and version of the current browser. * @example `browser()` => { name: 'firefox', version: '42' } * Based on http://stackoverflow.com/a/38080051/2834898 * * @returns {{ name: string, version: string }}
()
| 449 | * @returns {{ name: string, version: string }} |
| 450 | */ |
| 451 | static browser() { |
| 452 | const ua = navigator.userAgent; |
| 453 | let tem; |
| 454 | let M = ua.match(/(opera|chrome|safari|firefox|msie|trident(?=\/))\/?\s*(\d+)/i) || []; |
| 455 | |
| 456 | if (/trident/i.test(M[1])) { |
| 457 | tem = /\brv[ :]+(\d+)/g.exec(ua) || []; |
| 458 | return { name: 'ie', version: (tem[1] || '') }; |
| 459 | } |
| 460 | |
| 461 | if (M[1] === 'Chrome') { |
| 462 | tem = ua.match(/\b(OPR|Edge)\/(\d+)/); |
| 463 | if (tem !== null) { |
| 464 | return { name: tem[1].replace('OPR', 'opera'), version: tem[2] }; |
| 465 | } |
| 466 | } |
| 467 | |
| 468 | M = M[2]?[M[1], M[2]]:[navigator.appName, navigator.appVersion, '-?']; |
| 469 | if ((tem = ua.match(/version\/(\d+)/i)) !== null) { |
| 470 | M.splice(1, 1, tem[1]); |
| 471 | } |
| 472 | |
| 473 | return { name: M[0].toLowerCase(), version: M[1] }; |
| 474 | } |
| 475 | |
| 476 | /** |
| 477 | * Check if the browser is controlled by Selenium. |