Skip to content

Commit

Permalink
fix(default-browser): os lookup wrong
Browse files Browse the repository at this point in the history
  • Loading branch information
blakebyrnes committed Dec 6, 2024
1 parent 08431a2 commit f38248e
Show file tree
Hide file tree
Showing 8 changed files with 24 additions and 18 deletions.
1 change: 0 additions & 1 deletion agent/main/lib/Page.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ import { assert, createPromise } from '@ulixee/commons/lib/utils';
import { IJsPath } from '@ulixee/js-path';
import IDialog from '@ulixee/unblocked-specification/agent/browser/IDialog';
import IExecJsPathResult from '@ulixee/unblocked-specification/agent/browser/IExecJsPathResult';
import { IFrame } from '@ulixee/unblocked-specification/agent/browser/IFrame';
import INavigation from '@ulixee/unblocked-specification/agent/browser/INavigation';
import {
IPage,
Expand Down
7 changes: 5 additions & 2 deletions core/lib/Session.ts
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,10 @@ export default class Session
return this.core.sessionRegistry;
}

protected constructor(readonly options: ISessionCreateOptions, public core: Core) {
protected constructor(
readonly options: ISessionCreateOptions,
public core: Core,
) {
super();

for (const key of Object.keys(options)) {
Expand Down Expand Up @@ -817,7 +820,7 @@ export default class Session

const {
string: userAgentString,
operatingSystemName,
operatingSystemNameKey: operatingSystemName,

Check failure on line 823 in core/lib/Session.ts

View workflow job for this annotation

GitHub Actions / Build Javascript

Property 'operatingSystemNameKey' does not exist on type 'IUserAgentOption | {}'.

Check failure on line 823 in core/lib/Session.ts

View workflow job for this annotation

GitHub Actions / Test chrome-latest (node 18; ubuntu-latest)

Property 'operatingSystemNameKey' does not exist on type 'IUserAgentOption | {}'.

Check failure on line 823 in core/lib/Session.ts

View workflow job for this annotation

GitHub Actions / Test chrome-130-0 (node 20.x; ubuntu-latest)

Property 'operatingSystemNameKey' does not exist on type 'IUserAgentOption | {}'.

Check failure on line 823 in core/lib/Session.ts

View workflow job for this annotation

GitHub Actions / Test chrome-115-0 (node 20.x; ubuntu-latest)

Property 'operatingSystemNameKey' does not exist on type 'IUserAgentOption | {}'.

Check failure on line 823 in core/lib/Session.ts

View workflow job for this annotation

GitHub Actions / Test chrome-latest (node 22; ubuntu-latest)

Property 'operatingSystemNameKey' does not exist on type 'IUserAgentOption | {}'.

Check failure on line 823 in core/lib/Session.ts

View workflow job for this annotation

GitHub Actions / Test chrome-120-0 (node 20.x; ubuntu-latest)

Property 'operatingSystemNameKey' does not exist on type 'IUserAgentOption | {}'.

Check failure on line 823 in core/lib/Session.ts

View workflow job for this annotation

GitHub Actions / Test chrome-latest (node 20; ubuntu-latest)

Property 'operatingSystemNameKey' does not exist on type 'IUserAgentOption | {}'.

Check failure on line 823 in core/lib/Session.ts

View workflow job for this annotation

GitHub Actions / Test chrome-latest (node 22; macos-13)

Property 'operatingSystemNameKey' does not exist on type 'IUserAgentOption | {}'.

Check failure on line 823 in core/lib/Session.ts

View workflow job for this annotation

GitHub Actions / Test chrome-latest (node 20; macos-13)

Property 'operatingSystemNameKey' does not exist on type 'IUserAgentOption | {}'.
operatingSystemVersion: osVersion,
uaClientHintsPlatformVersion,
browserVersion,
Expand Down
2 changes: 1 addition & 1 deletion plugins/default-browser-emulator/lib/BrowserData.ts
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ function getOperatingSystemParts(userAgentOption: IUserAgentOption): {
name: string;
version: string;
} {
const { operatingSystemName: name, operatingSystemVersion: version } = userAgentOption;
const { operatingSystemCleanName: name, operatingSystemVersion: version } = userAgentOption;
let { major, minor } = version;

if (name.startsWith('mac')) {
Expand Down
20 changes: 12 additions & 8 deletions plugins/default-browser-emulator/lib/UserAgentOptions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ export default class UserAgentOptions {
if (!filteredOptions.length) filteredOptions = this.defaultBrowserUserAgentOptions;

const withOs = filteredOptions.filter(
x => x.operatingSystemName === userAgent.operatingSystemName,
x => cleanName(x.operatingSystemName) === userAgent.operatingSystemCleanName,
);

if (withOs.length) filteredOptions = withOs;
Expand Down Expand Up @@ -114,8 +114,12 @@ export default class UserAgentOptions {

// eslint-disable-next-line prefer-const
let [osVersionMajor, osVersionMinor, osVersionPatch] = uaOs.version.split('.');
const operatingSystemName = cleanName(uaOs.name || '');
if (operatingSystemName === 'mac-os' && osVersionMajor === '10' && osVersionMinor === '16') {
const operatingSystemCleanName = cleanName(uaOs.name || '');
if (
operatingSystemCleanName === 'mac-os' &&
osVersionMajor === '10' &&
osVersionMinor === '16'
) {
osVersionMajor = '11';
osVersionMinor = undefined;
}
Expand All @@ -128,7 +132,7 @@ export default class UserAgentOptions {
patch: browserVersionPatch,
build: browserVersionBuild,
},
operatingSystemName,
operatingSystemCleanName,
operatingSystemVersion: {
major: osVersionMajor,
minor: osVersionMinor,
Expand Down Expand Up @@ -172,7 +176,7 @@ export default class UserAgentOptions {
const userAgent = {
browserName: cleanName(agent.browserName),
browserVersion: { major, minor, build, patch: String(patch) },
operatingSystemName: cleanName(agent.operatingSystemName),
operatingSystemCleanName: cleanName(agent.operatingSystemName),
operatingSystemVersion: { ...agent.operatingSystemVersion },
uaClientHintsPlatformVersion,
string: UserAgent.parse(agent, patch, uaClientHintsPlatformVersion),
Expand All @@ -191,7 +195,7 @@ export default class UserAgentOptions {
private static canTrustOsVersionForAgentString(agentOption: IUserAgentOption): boolean {
// Chrome 90+ started pegging the OS versions to 10.15.7
if (
agentOption.operatingSystemName === 'mac-os' &&
agentOption.operatingSystemCleanName === 'mac-os' &&
Number(agentOption.browserVersion.major) > 90 &&
agentOption.operatingSystemVersion.major === '10' &&
agentOption.operatingSystemVersion.minor === '15' &&
Expand All @@ -202,7 +206,7 @@ export default class UserAgentOptions {

// windows 11 never shows up in the os version (shows as 10)
if (
agentOption.operatingSystemName === 'windows' &&
agentOption.operatingSystemCleanName === 'windows' &&
agentOption.operatingSystemVersion.major === '10'
) {
return false;
Expand All @@ -218,7 +222,7 @@ export default class UserAgentOptions {
const realOperatingSystem = dataUserAgentOptions.find(
x =>
x.browserId === browserId &&
cleanName(x.operatingSystemName) === userAgent.operatingSystemName &&
cleanName(x.operatingSystemName) === userAgent.operatingSystemCleanName &&
isLeftVersionGreater(x.operatingSystemVersion, userAgent.operatingSystemVersion),
);
if (realOperatingSystem) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ export default function configureSessionTcp(
emulationProfile: IEmulationProfile,
settings: ITcpSettings,
): void {
const { operatingSystemName, operatingSystemVersion } = emulationProfile.userAgentOption;
const tcpSettings = getTcpSettingsForOs(operatingSystemName, operatingSystemVersion);
const { operatingSystemCleanName, operatingSystemVersion } = emulationProfile.userAgentOption;
const tcpSettings = getTcpSettingsForOs(operatingSystemCleanName, operatingSystemVersion);
if (tcpSettings) {
settings.tcpTtl = tcpSettings.ttl;
settings.tcpWindowSize = tcpSettings.windowSize;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ test('should support choosing a specific useragent', async () => {
test('should support choosing a specific OS', async () => {
const options = selectUserAgentOption('~ mac & chrome >= 88', userAgentOptions);
expect(parseInt(options.browserVersion.major, 10)).toBeGreaterThanOrEqual(88);
expect(options.operatingSystemName).toBe('mac-os');
expect(options.operatingSystemCleanName).toBe('mac-os');
});

test('it should find correct browser meta', async () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ test('it should run uninstalled userAgent strings on the closest installed brows
);
});

test('it should run pick an OS version for Chrome 90+ on mac 10.15.17', async () => {
test('it should run pick an OS match for the default chrome on mac', async () => {
const userAgent = `Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/${defaultBrowserEngine.version.major}.0.3987.165 Safari/537.36`;

const browserMeta = DefaultBrowserEmulator.selectBrowserMeta(userAgent);
Expand All @@ -33,5 +33,5 @@ test('it should run pick an OS version for Chrome 90+ on mac 10.15.17', async ()
if (Number(osVersion.major) === 10) {
expect(Number(osVersion.minor)).toBeGreaterThan(15);
}
expect(browserMeta.userAgentOption.operatingSystemName).toBe('mac-os');
expect(browserMeta.userAgentOption.operatingSystemCleanName).toBe('mac-os');
});
2 changes: 1 addition & 1 deletion specification/plugin/IUserAgentOption.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
export default interface IUserAgentOption {
browserName: string;
browserVersion: IVersion;
operatingSystemName: string;
operatingSystemCleanName: string;
operatingSystemVersion: IVersion;
uaClientHintsPlatformVersion: string;
string: string;
Expand Down

0 comments on commit f38248e

Please sign in to comment.