Skip to content

Commit 51dada5

Browse files
committed
fix: updated some things to work with Slab
1 parent 0a2187c commit 51dada5

File tree

9 files changed

+34
-34
lines changed

9 files changed

+34
-34
lines changed

core-interfaces/IBrowserEmulator.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@ import INewDocumentInjectedScript from './INewDocumentInjectedScript';
44
import IWindowFraming from "./IWindowFraming";
55

66
export default interface IBrowserEmulator {
7-
readonly navigatorUserAgent: string;
8-
readonly navigatorPlatform: string;
7+
readonly userAgentString: string;
8+
readonly osPlatform: string;
99
readonly windowFramingBase: IWindowFraming;
1010
readonly windowFraming: IWindowFraming;
1111
readonly canPolyfill: boolean;

core/lib/Session.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ export default class Session {
7474
log.warn('BrowserEmulators.PolyfillNotSupported', {
7575
sessionId: this.id,
7676
browserEmulatorId,
77-
userAgent: this.browserEmulator.navigatorUserAgent,
77+
userAgentString: this.browserEmulator.userAgentString,
7878
runtimeOs: Os.platform(),
7979
});
8080
}
@@ -102,7 +102,7 @@ export default class Session {
102102
);
103103
this.mitmRequestSession = new RequestSession(
104104
this.id,
105-
this.browserEmulator.navigatorUserAgent,
105+
this.browserEmulator.userAgentString,
106106
this.upstreamProxyUrl,
107107
this.browserEmulator.networkInterceptorDelegate,
108108
);
@@ -112,8 +112,8 @@ export default class Session {
112112
const browserEmulator = this.browserEmulator;
113113
return {
114114
locale: browserEmulator.locale,
115-
userAgent: browserEmulator.navigatorUserAgent,
116-
platform: browserEmulator.navigatorPlatform,
115+
userAgent: browserEmulator.userAgentString,
116+
platform: browserEmulator.osPlatform,
117117
proxyPassword: this.id,
118118
viewport: this.viewport,
119119
timezoneId: this.timezoneId,

core/test/tab.test.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -68,16 +68,16 @@ describe('basic Tab tests', () => {
6868
});
6969

7070
it('can wait for another tab', async () => {
71-
let useragent1: string;
72-
let useragent2: string;
71+
let userAgentString1: string;
72+
let userAgentString2: string;
7373
koaServer.get('/tabTest', ctx => {
74-
useragent1 = ctx.get('user-agent');
74+
userAgentString1 = ctx.get('user-agent');
7575
ctx.body = `<body>
7676
<a target="_blank" href="/tabTestDest">Nothing really here</a>
7777
</body>`;
7878
});
7979
koaServer.get('/tabTestDest', ctx => {
80-
useragent2 = ctx.get('user-agent');
80+
userAgentString2 = ctx.get('user-agent');
8181
ctx.body = `<body><h1 id="newTabHeader">You are here</h1></body>`;
8282
});
8383
const meta = await Core.createTab();
@@ -104,7 +104,7 @@ describe('basic Tab tests', () => {
104104
'textContent',
105105
]);
106106
expect(header.value).toBe('You are here');
107-
expect(useragent1).toBe(useragent2);
107+
expect(userAgentString1).toBe(userAgentString2);
108108
await newTabCore.closeTab();
109109
});
110110
});

emulate-browsers/base/lib/modifyHeaders.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import { pickRandom } from '@secret-agent/commons/utils';
77
const { log } = Log(module);
88

99
export default function modifyHeaders(
10-
userAgent: string,
10+
userAgentString: string,
1111
headerProfiles: IResourceHeaderDefaults,
1212
hasCustomLocale: boolean,
1313
resource: IResourceToModify,
@@ -17,7 +17,7 @@ export default function modifyHeaders(
1717
const { headers, lowerHeaders } = resource;
1818
if (!defaultOrder || (resource.isClientHttp2 && resource.isServerHttp2)) {
1919
for (const [header, value] of Object.entries(headers)) {
20-
if (header.match(/user-agent/i) && value !== userAgent) {
20+
if (header.match(/user-agent/i) && value !== userAgentString) {
2121
headers[header] = value;
2222
}
2323
}
@@ -41,8 +41,8 @@ export default function modifyHeaders(
4141
}
4242
}
4343

44-
if (headerName.match(/user-agent/i) && value !== userAgent) {
45-
value = userAgent;
44+
if (headerName.match(/user-agent/i) && value !== userAgentString) {
45+
value = userAgentString;
4646
}
4747
if (value) {
4848
headerList.push([headerName, value]);

emulate-browsers/chrome-80/index.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -50,8 +50,8 @@ export default class Chrome80 {
5050
return this._locale;
5151
}
5252

53-
public readonly navigatorUserAgent: string;
54-
public readonly navigatorPlatform: string;
53+
public readonly userAgentString: string;
54+
public readonly osPlatform: string;
5555

5656
public readonly networkInterceptorDelegate: INetworkInterceptorDelegate;
5757
public userProfile: IUserProfile;
@@ -69,8 +69,8 @@ export default class Chrome80 {
6969
(this.constructor as any).userAgentOptions as IUserAgentOption[],
7070
);
7171
const windowNavigator = windowNavigatorData.get(userAgentOption.operatingSystemId);
72-
this.navigatorPlatform = windowNavigator.navigator.platform._$value;
73-
this.navigatorUserAgent = userAgentOption.string;
72+
this.osPlatform = windowNavigator.navigator.platform._$value;
73+
this.userAgentString = userAgentOption.string;
7474
this.canPolyfill = !!domDiffsData.get(userAgentOption.operatingSystemId);
7575
this.windowFraming = windowFramingData.get(userAgentOption.operatingSystemId);
7676

emulate-browsers/chrome-83/index.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -50,8 +50,8 @@ export default class Chrome83 {
5050
return this._locale;
5151
}
5252

53-
public readonly navigatorUserAgent: string;
54-
public readonly navigatorPlatform: string;
53+
public readonly userAgentString: string;
54+
public readonly osPlatform: string;
5555

5656
public readonly networkInterceptorDelegate: INetworkInterceptorDelegate;
5757
public userProfile: IUserProfile;
@@ -69,8 +69,8 @@ export default class Chrome83 {
6969
(this.constructor as any).userAgentOptions as IUserAgentOption[],
7070
);
7171
const windowNavigator = windowNavigatorData.get(userAgentOption.operatingSystemId);
72-
this.navigatorPlatform = windowNavigator.navigator.platform._$value;
73-
this.navigatorUserAgent = userAgentOption.string;
72+
this.osPlatform = windowNavigator.navigator.platform._$value;
73+
this.userAgentString = userAgentOption.string;
7474
this.canPolyfill = !!domDiffsData.get(userAgentOption.operatingSystemId);
7575
this.windowFraming = windowFramingData.get(userAgentOption.operatingSystemId);
7676

emulate-browsers/safari-13/index.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -60,8 +60,8 @@ export default class Safari13 {
6060
return this._locale;
6161
}
6262

63-
public readonly navigatorUserAgent: string;
64-
public readonly navigatorPlatform: string;
63+
public readonly userAgentString: string;
64+
public readonly osPlatform: string;
6565

6666
public cookieJar = new CookieJar(null, { rejectPublicSuffixes: false });
6767
// track sites per safari ITP that are considered to have "first party user interaction"
@@ -106,8 +106,8 @@ export default class Safari13 {
106106
(this.constructor as any).userAgentOptions as IUserAgentOption[],
107107
);
108108
const windowNavigator = windowNavigatorData.get(userAgentOption.operatingSystemId);
109-
this.navigatorPlatform = windowNavigator.navigator.platform._$value;
110-
this.navigatorUserAgent = userAgentOption.string;
109+
this.osPlatform = windowNavigator.navigator.platform._$value;
110+
this.userAgentString = userAgentOption.string;
111111
this.userAgentVersion = userAgentOption.version;
112112
this.windowFraming = windowFramingData.get(userAgentOption.operatingSystemId);
113113

full-client/test/tab.test.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -52,8 +52,8 @@ describe('Multi-tab scenarios', () => {
5252
// @ts-ignore
5353
const browserEmulator = core.session.browserEmulator;
5454
// make sure user agent is wired up
55-
const userAgent = await agent.getJsValue('navigator.userAgent');
56-
expect(userAgent.value).toBe(browserEmulator.navigatorUserAgent);
55+
const navigatorAgent = await agent.getJsValue('navigator.userAgent');
56+
expect(navigatorAgent.value).toBe(browserEmulator.userAgentString);
5757

5858
// make sure polyfills ran
5959
const csi = await agent.getJsValue<any>('chrome.csi()');
@@ -154,8 +154,8 @@ describe('Multi-tab scenarios', () => {
154154
// @ts-ignore
155155
const browserEmulator = core.session.browserEmulator;
156156
// make sure user agent is wired up
157-
const userAgent = await agent.getJsValue('navigator.userAgent');
158-
expect(userAgent.value).toBe(browserEmulator.navigatorUserAgent);
157+
const navigatorAgent = await agent.getJsValue('navigator.userAgent');
158+
expect(navigatorAgent.value).toBe(browserEmulator.userAgentString);
159159

160160
// make sure polyfills ran
161161
const csi = await agent.getJsValue<any>('chrome.csi()');
@@ -206,8 +206,8 @@ document.querySelector('a').addEventListener('click', event => {
206206
// @ts-ignore
207207
const browserEmulator = core.session.browserEmulator;
208208
// make sure user agent is wired up
209-
const userAgent = await agent.getJsValue('navigator.userAgent');
210-
expect(userAgent.value).toBe(browserEmulator.navigatorUserAgent);
209+
const navigatorAgent = await agent.getJsValue('navigator.userAgent');
210+
expect(navigatorAgent.value).toBe(browserEmulator.userAgentString);
211211

212212
await agent.closeTab(newTab);
213213
});

mitm/handlers/RequestSession.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ export default class RequestSession extends TypedEventEmitter<IRequestSessionEve
5858

5959
constructor(
6060
readonly sessionId: string,
61-
readonly useragent: string,
61+
readonly userAgentString: string,
6262
readonly upstreamProxyUrl?: string,
6363
readonly networkInterceptorDelegate: INetworkInterceptorDelegate = { http: {} },
6464
) {

0 commit comments

Comments
 (0)