Skip to content

Commit 1dd550a

Browse files
Merge pull request #137 from pinanks/DOT-3925
Dot 3925
2 parents 4b77151 + d60a217 commit 1dd550a

File tree

7 files changed

+118
-61
lines changed

7 files changed

+118
-61
lines changed

package.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,10 @@
2121
"author": "LambdaTest <[email protected]>",
2222
"license": "MIT",
2323
"dependencies": {
24-
"@playwright/browser-chromium": "^1.45.3",
25-
"@playwright/browser-firefox": "^1.45.3",
26-
"@playwright/browser-webkit": "^1.45.3",
27-
"@playwright/test": "^1.45.3",
24+
"@playwright/browser-chromium": "^1.47.2",
25+
"@playwright/browser-firefox": "^1.47.2",
26+
"@playwright/browser-webkit": "^1.47.2",
27+
"@playwright/test": "^1.47.2",
2828
"@types/cross-spawn": "^6.0.4",
2929
"@types/node": "^20.8.9",
3030
"@types/which": "^3.0.2",

pnpm-lock.yaml

Lines changed: 31 additions & 43 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/lib/constants.ts

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,66 @@ export default {
4747
EDGE_CHANNEL: 'msedge',
4848
WEBKIT: 'webkit',
4949

50+
// discovery browser launch arguments
51+
LAUNCH_ARGS: [
52+
// disable the translate popup and optimization downloads
53+
'--disable-features=Translate,OptimizationGuideModelDownloading',
54+
// disable several subsystems which run network requests in the background
55+
'--disable-background-networking',
56+
// disable task throttling of timer tasks from background pages
57+
'--disable-background-timer-throttling',
58+
// disable backgrounding renderer processes
59+
'--disable-renderer-backgrounding',
60+
// disable backgrounding renderers for occluded windows (reduce nondeterminism)
61+
'--disable-backgrounding-occluded-windows',
62+
// disable crash reporting
63+
'--disable-breakpad',
64+
// disable client side phishing detection
65+
'--disable-client-side-phishing-detection',
66+
// disable default component extensions with background pages for performance
67+
'--disable-component-extensions-with-background-pages',
68+
// disable installation of default apps on first run
69+
'--disable-default-apps',
70+
// work-around for environments where a small /dev/shm partition causes crashes
71+
'--disable-dev-shm-usage',
72+
// disable extensions
73+
'--disable-extensions',
74+
// disable hang monitor dialogs in renderer processes
75+
'--disable-hang-monitor',
76+
// disable inter-process communication flooding protection for javascript
77+
'--disable-ipc-flooding-protection',
78+
// disable web notifications and the push API
79+
'--disable-notifications',
80+
// disable the prompt when a POST request causes page navigation
81+
'--disable-prompt-on-repost',
82+
// disable syncing browser data with google accounts
83+
'--disable-sync',
84+
// disable site-isolation to make network requests easier to intercept
85+
'--disable-site-isolation-trials',
86+
// disable the first run tasks, whether or not it's actually the first run
87+
'--no-first-run',
88+
// disable the sandbox for all process types that are normally sandboxed
89+
'--no-sandbox',
90+
// specify a consistent encryption backend across platforms
91+
'--password-store=basic',
92+
// use a mock keychain on Mac to prevent blocking permissions dialogs
93+
'--use-mock-keychain',
94+
// enable remote debugging on the first available port
95+
'--remote-debugging-port=0',
96+
// sets navigator.webdriver to false
97+
'--disable-blink-features=AutomationControlled',
98+
// disable UA-CH feature
99+
`--disable-features=UserAgentClientHint`,
100+
],
101+
102+
// discovery request headers
103+
REQUEST_HEADERS: {
104+
// `HeadlessChrome` is added to sec-ch-ua, `--disable-features=UserAgentClientHint` doesn't seem to work
105+
'sec-ch-ua':'"Chromium";v="129", "Not=A?Brand";v="8"',
106+
'sec-ch-ua-mobile': '"?0"',
107+
'sec-ch-ua-platform': '"Windows"'
108+
},
109+
50110
// user agents
51111
CHROME_USER_AGENT: 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/123.0.6312.107 Safari/537.3',
52112
FIREFOX_USER_AGENT: 'Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:112.0) Gecko/20100101 Firefox/112.0',

src/lib/env.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,22 +4,22 @@ export default (): Env => {
44
const {
55
PROJECT_TOKEN = '',
66
SMARTUI_CLIENT_API_URL = 'https://api.lambdatest.com/visualui/1.0',
7-
LT_SDK_DEBUG,
87
SMARTUI_GIT_INFO_FILEPATH,
8+
SMARTUI_DO_NOT_USE_CAPTURED_COOKIES,
99
HTTP_PROXY,
1010
HTTPS_PROXY,
1111
GITHUB_ACTIONS,
1212
FIGMA_TOKEN,
1313
LT_USERNAME,
1414
LT_ACCESS_KEY,
15+
LT_SDK_DEBUG,
1516
BASELINE_BRANCH,
1617
CURRENT_BRANCH
1718
} = process.env
1819

1920
return {
2021
PROJECT_TOKEN,
2122
SMARTUI_CLIENT_API_URL,
22-
LT_SDK_DEBUG,
2323
SMARTUI_GIT_INFO_FILEPATH,
2424
HTTP_PROXY,
2525
HTTPS_PROXY,
@@ -29,5 +29,7 @@ export default (): Env => {
2929
LT_ACCESS_KEY,
3030
BASELINE_BRANCH,
3131
CURRENT_BRANCH,
32+
LT_SDK_DEBUG: LT_SDK_DEBUG === 'true',
33+
SMARTUI_DO_NOT_USE_CAPTURED_COOKIES: SMARTUI_DO_NOT_USE_CAPTURED_COOKIES === 'true'
3234
}
3335
}

src/lib/logger.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ export function updateLogContext(newContext: LogContext) {
1717

1818
const logLevel = (): string => {
1919
let env: Env = getEnv();
20-
return (env.LT_SDK_DEBUG === 'true') ? 'debug' : 'info';
20+
return (env.LT_SDK_DEBUG) ? 'debug' : 'info';
2121
}
2222

2323
// Create a Winston logger

src/lib/processSnapshot.ts

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,10 @@ async function processSnapshot(snapshot: Snapshot, ctx: Context): Promise<Record
8080
updateLogContext({ task: 'discovery' });
8181
ctx.log.debug(`Processing snapshot ${snapshot.name} ${snapshot.url}`);
8282

83-
let launchOptions: Record<string, any> = { headless: true }
83+
let launchOptions: Record<string, any> = {
84+
headless: true,
85+
args: constants.LAUNCH_ARGS
86+
}
8487
let contextOptions: Record<string, any> = {
8588
javaScriptEnabled: ctx.config.cliEnableJavaScript,
8689
userAgent: constants.CHROME_USER_AGENT,
@@ -92,8 +95,8 @@ async function processSnapshot(snapshot: Snapshot, ctx: Context): Promise<Record
9295
}
9396
const context = await ctx.browser.newContext(contextOptions);
9497
ctx.log.debug(`Browser context created with options ${JSON.stringify(contextOptions)}`);
95-
// Setting the cookies in playwright context
96-
if (snapshot.dom.cookies) {
98+
// Setting cookies in playwright context
99+
if (!ctx.env.SMARTUI_DO_NOT_USE_CAPTURED_COOKIES && snapshot.dom.cookies) {
97100
const domainName = new URL(snapshot.url).hostname;
98101
ctx.log.debug(`Setting cookies for domain: ${domainName}`);
99102

@@ -135,7 +138,13 @@ async function processSnapshot(snapshot: Snapshot, ctx: Context): Promise<Record
135138
await page.route('**/*', async (route, request) => {
136139
const requestUrl = request.url()
137140
const requestHostname = new URL(requestUrl).hostname;
138-
let requestOptions: Record<string, any> = { timeout: REQUEST_TIMEOUT }
141+
let requestOptions: Record<string, any> = {
142+
timeout: REQUEST_TIMEOUT,
143+
headers: {
144+
...await request.allHeaders(),
145+
...constants.REQUEST_HEADERS
146+
}
147+
}
139148

140149
try {
141150
// abort audio/video media requests
@@ -149,10 +158,7 @@ async function processSnapshot(snapshot: Snapshot, ctx: Context): Promise<Record
149158
if (ctx.config.basicAuthorization) {
150159
ctx.log.debug(`Adding basic authorization to the headers for root url`);
151160
let token = Buffer.from(`${ctx.config.basicAuthorization.username}:${ctx.config.basicAuthorization.password}`).toString('base64');
152-
requestOptions.headers = {
153-
...request.headers(),
154-
Authorization: `Basic ${token}`
155-
};
161+
requestOptions.headers.Authorization = `Basic ${token}`;
156162
}
157163

158164
// get response

src/types.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -52,14 +52,15 @@ export interface Context {
5252
export interface Env {
5353
PROJECT_TOKEN: string;
5454
SMARTUI_CLIENT_API_URL: string;
55-
LT_SDK_DEBUG: string | undefined;
55+
SMARTUI_DO_NOT_USE_CAPTURED_COOKIES: boolean;
5656
SMARTUI_GIT_INFO_FILEPATH: string | undefined;
5757
HTTP_PROXY: string | undefined;
5858
HTTPS_PROXY: string | undefined;
5959
GITHUB_ACTIONS: string | undefined;
6060
FIGMA_TOKEN: string | undefined;
61-
LT_USERNAME: string | undefined;
62-
LT_ACCESS_KEY: string | undefined;
61+
LT_USERNAME : string | undefined;
62+
LT_ACCESS_KEY : string | undefined;
63+
LT_SDK_DEBUG: boolean;
6364
BASELINE_BRANCH: string | undefined;
6465
CURRENT_BRANCH: string | undefined;
6566
}

0 commit comments

Comments
 (0)