UNPKG

@braze/web-sdk

Version:

Braze SDK for web sites and other JS platforms.

67 lines (66 loc) 1.7 kB
import ge from "./base-device-parser.js"; import { Browsers as oi } from "./device-constants.js"; export default class ai extends ge { constructor() { if ( (super(), (this.userAgentData = navigator.userAgentData), (this.browser = null), (this.version = null), this.userAgentData) ) { const t = this.Bc(); (this.browser = t.browser || "Unknown Browser"), (this.version = t.version || "Unknown Version"); } this.OS = null; } ef() { return this.browser; } ff() { return this.version; } Ha(t) { if (this.OS) return Promise.resolve(this.OS); const s = (s) => { for (let r = 0; r < t.length; r++) { const i = ai.nf(s, t[r]); if (i) return (this.OS = i), this.OS; } return s; }; return this.userAgentData.platform ? Promise.resolve(s(this.userAgentData.platform)) : this.getHighEntropyValues() .then((t) => (t.platform ? s(t.platform) : navigator.platform)) .catch(() => navigator.platform); } Bc() { const t = {}, s = this.userAgentData.brands; if (s && s.length) for (const r of s) { const s = this.Vc(oi), i = r.brand.match(s); if (i && i.length > 0) { (t.browser = i[0]), (t.version = r.version); break; } } return t; } Vc(t) { const s = []; for (const r in t) { const i = r; s.push(t[i]); } return new RegExp("(" + s.join("|") + ")", "i"); } getHighEntropyValues() { return this.userAgentData.getHighEntropyValues ? this.userAgentData.getHighEntropyValues(["platform"]) : Promise.reject(); } }