Skip to content

Commit

Permalink
fix: set more appropriate user agent (#20)
Browse files Browse the repository at this point in the history
  • Loading branch information
alexplischke authored Sep 19, 2024
1 parent cae2230 commit e3fd26f
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions src/driver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import wd, { Client } from 'webdriver';
import * as fs from 'fs';
import { isDevice, isSimulator } from './device';
import { CreateSessionError } from './errors';
import path from 'path';

export type Size = {
width: number;
Expand All @@ -25,6 +26,7 @@ export class SauceDriver {
private readonly tags?: string[];
private readonly region: Region;
private readonly jobName?: string;
private readonly user_agent: string;

constructor(
username: string,
Expand All @@ -42,6 +44,20 @@ export class SauceDriver {
this.jobName = jobName;
this.build = build ?? Math.random().toString(36).substring(2, 10);
this.tags = tags;
this.user_agent = this.getUserAgent();
}

getUserAgent() {
try {
const packageData = JSON.parse(
fs.readFileSync(path.join(__dirname, '..', 'package.json'), 'utf-8'),
);
return 'testcafe-browser-provider-sauce/' + packageData.version;
} catch (e) {
/* empty */
}

return 'testcafe-browser-provider-sauce/unknown';
}

createCapabilities(
Expand Down Expand Up @@ -91,6 +107,9 @@ export class SauceDriver {
screenResolution?: string,
) {
const webDriver = await wd.newSession({
headers: {
'User-Agent': this.user_agent,
},
protocol: 'https',
hostname: hostByRegion.get(this.region),
port: 443,
Expand Down

0 comments on commit e3fd26f

Please sign in to comment.