Add operating system to user agent string

This commit is contained in:
Alan Hamlett
2023-04-27 15:32:18 +02:00
parent 74ca75b9e9
commit cb23dcd2ed

View File

@@ -284,7 +284,7 @@ class WakaTimeCore {
// And send that in heartbeat // And send that in heartbeat
if (loggingType == 'domain') { if (loggingType == 'domain') {
heartbeat.url = getDomainFromUrl(heartbeat.url); heartbeat.url = getDomainFromUrl(heartbeat.url);
payload = this.preparePayload(heartbeat, 'domain'); payload = await this.preparePayload(heartbeat, 'domain');
await this.sendPostRequestToApi( await this.sendPostRequestToApi(
{ ...payload, ...navigationPayload }, { ...payload, ...navigationPayload },
apiKey, apiKey,
@@ -293,7 +293,7 @@ class WakaTimeCore {
} }
// Send entity in heartbeat // Send entity in heartbeat
else if (loggingType == 'url') { else if (loggingType == 'url') {
payload = this.preparePayload(heartbeat, 'url'); payload = await this.preparePayload(heartbeat, 'url');
await this.sendPostRequestToApi( await this.sendPostRequestToApi(
{ ...payload, ...navigationPayload }, { ...payload, ...navigationPayload },
apiKey, apiKey,
@@ -325,7 +325,8 @@ class WakaTimeCore {
* @returns {*} * @returns {*}
* @private * @private
*/ */
preparePayload(heartbeat: SendHeartbeat, type: string): Record<string, unknown> { async preparePayload(heartbeat: SendHeartbeat, type: string): Promise<Record<string, unknown>> {
const os = await this.getOperatingSystem();
let browserName = 'chrome'; let browserName = 'chrome';
let userAgent; let userAgent;
if (IS_FIREFOX) { if (IS_FIREFOX) {
@@ -338,7 +339,7 @@ class WakaTimeCore {
entity: heartbeat.url, entity: heartbeat.url,
time: moment().format('X'), time: moment().format('X'),
type: type, type: type,
user_agent: `${userAgent} ${browserName}-wakatime/${config.version}`, user_agent: `${userAgent} ${os} ${browserName}-wakatime/${config.version}`,
}; };
if (heartbeat.project) { if (heartbeat.project) {
@@ -348,6 +349,14 @@ class WakaTimeCore {
return payload; return payload;
} }
getOperatingSystem(): Promise<string> {
return new Promise((resolve) => {
chrome.runtime.getPlatformInfo(function(info) {
resolve(`${info.os}_${info.arch}`);
});
});
}
/** /**
* Sends AJAX request with payload to the heartbeat API as JSON. * Sends AJAX request with payload to the heartbeat API as JSON.
* *