function getDeviceInfo() { let rootURL = "https://connect.garmin.com/modern/activity/"; let loc = window.location.href; if (loc.indexOf(rootURL) != 0) { console.log("This script must be run on GC device page (with a URL starting with " + rootURL + ")") alert("This script must be run on GC device page (with a URL starting with " + rootURL + ")") return; } let activityID = loc.replace(rootURL, ""); var xhr = new XMLHttpRequest(); xhr.open('GET', 'https://connect.garmin.com/activity-service/activity/' + activityID); xhr.setRequestHeader("NK", "NT") xhr.setRequestHeader('di-backend', 'connectapi.garmin.com') const token = JSON.parse(localStorage.token).access_token; xhr.setRequestHeader('Authorization', 'Bearer ' + token); xhr.onload = function () { let obj = JSON.parse(xhr.response) let deviceID = obj.metadataDTO.deviceMetaDataDTO.deviceId; console.log('The device ID for this activity is: ' + deviceID) alert('The device ID for this activity is: ' + deviceID) }; xhr.send() } getDeviceInfo();