class DeviceAtlasInfoPst extends HTMLElement { constructor() { super(); this.attachShadow({ mode: 'open' }); this._primarySoftwareType = null; this.softwareIcons = { 'browser': '', 'desktop': '', 'app': '', 'previewer': '', 'default': '' }; } async connectedCallback() { const apiKey = this.getAttribute('apikey'); const LICENCE_KEY = this.getAttribute('apikey'); const CLOUD_PATH = '/v1/detect/properties'; this.render(); const SERVERS = [ {'host': 'region0.deviceatlascloud.com', 'port': 443}, {'host': 'region1.deviceatlascloud.com', 'port': 443}, {'host': 'region2.deviceatlascloud.com', 'port': 443}, {'host': 'region3.deviceatlascloud.com', 'port': 443} ]; const getRandomInt = (min, max) => Math.floor(Math.random() * (max - min + 1)) + min; // List of high entropy hints to get const hints = [ 'architecture', 'model', 'platformVersion', 'uaFullVersion', 'fullVersionList', 'wow64' ]; if (!apiKey) { this.shadowRoot.innerHTML = '
Error: API key is missing. Please set the "apikey" attribute.
'; return; } try { const hintHeaders = new Headers(); if (navigator.userAgentData) { try { // Request the high entropy values const hintData = await navigator.userAgentData.getHighEntropyValues(hints); // Construct headers with hints & serialize complex objects like fullVersionList for (const [key, value] of Object.entries(hintData)) { hintHeaders.append(`CH-${key}`, typeof value === 'object' ? JSON.stringify(value) : value); } } catch (err) { console.error("Failed to get client hints:", err); } } else { console.warn("User Agent Client Hints not supported in this browser."); } const i = getRandomInt(0, SERVERS.length-1); const url = 'https://' + SERVERS[i].host + ':' + SERVERS[i].port + CLOUD_PATH + '?licencekey=' + encodeURIComponent(apiKey) + '&useragent=' + encodeURIComponent(navigator.userAgent); const data = await (await fetch(url, { method: "GET", //headers: hintHeaders })).json(); this._primarySoftwareType = data.properties.primarySoftwareType; this.render(); this.dispatchEvent(new CustomEvent('deviceatlasready', { detail: { primarySoftwareType: this._primarySoftwareType } })); } catch (error) { console.error('Error communicating with DeviceAtlas Cloud API:', error); this.shadowRoot.innerHTML = 'Error communicating with DeviceAtlas Cloud API.
'; } } get primarySoftwareType() { return this._primarySoftwareType; } get softwareIcon() { const type = this._primarySoftwareType ? this._primarySoftwareType.toLowerCase() : ''; return this.softwareIcons[type] || this.softwareIcons['default']; } render() { this.shadowRoot.innerHTML = ` ${this.softwareIcon }