@intuned/runtime-dev 1.3.12-ua.2 → 1.3.12-ua.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/bin/intuned-get-headless-user-agent +4 -0
- package/dist/commands/get-headless-user-agent.d.ts +1 -0
- package/dist/commands/get-headless-user-agent.js +16 -0
- package/dist/common/launchBrowser.d.ts +5 -0
- package/dist/common/launchBrowser.js +34 -22
- package/package.json +3 -1
- /package/dist/runtime/{kvStore.d.ts → store.d.ts} +0 -0
- /package/dist/runtime/{kvStore.js → store.js} +0 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _commander = require("commander");
|
|
4
|
+
var _dotenv = _interopRequireDefault(require("dotenv"));
|
|
5
|
+
var _launchBrowser = require("../common/launchBrowser");
|
|
6
|
+
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
|
7
|
+
_dotenv.default.config();
|
|
8
|
+
_commander.program.description("get headless user agent").action(async () => {
|
|
9
|
+
try {
|
|
10
|
+
console.log(await (0, _launchBrowser.getHeadlessUserAgent)({}));
|
|
11
|
+
} catch (error) {
|
|
12
|
+
console.error("Error getting headless user agent:", error);
|
|
13
|
+
process.exit(1);
|
|
14
|
+
}
|
|
15
|
+
});
|
|
16
|
+
_commander.program.parse(process.argv);
|
|
@@ -23,3 +23,8 @@ export declare function launchChromium(options: LaunchChromiumStandaloneOptions)
|
|
|
23
23
|
export declare function launchChromium(options: LaunchChromiumCdpOptions): Promise<LaunchBrowserResult>;
|
|
24
24
|
export declare function launchBrowser(options: Omit<LaunchChromiumStandaloneOptions, "executablePath"> | LaunchChromiumCdpOptions): Promise<LaunchBrowserResult>;
|
|
25
25
|
export declare function getLocalCdpAddress(port: number): string;
|
|
26
|
+
export declare function getHeadlessUserAgent({ executablePath, args, ignoreDefaultArgs, }: {
|
|
27
|
+
executablePath?: string;
|
|
28
|
+
args?: string[];
|
|
29
|
+
ignoreDefaultArgs?: string[];
|
|
30
|
+
}): Promise<string | undefined>;
|
|
@@ -3,6 +3,7 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
+
exports.getHeadlessUserAgent = getHeadlessUserAgent;
|
|
6
7
|
exports.getLocalCdpAddress = getLocalCdpAddress;
|
|
7
8
|
exports.launchBrowser = launchBrowser;
|
|
8
9
|
exports.launchChromium = launchChromium;
|
|
@@ -87,28 +88,9 @@ async function launchChromium(options) {
|
|
|
87
88
|
}
|
|
88
89
|
}
|
|
89
90
|
const viewport = null;
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
executablePath,
|
|
94
|
-
headless,
|
|
95
|
-
proxy,
|
|
96
|
-
downloadsPath,
|
|
97
|
-
args: extraArgs,
|
|
98
|
-
ignoreDefaultArgs: defaultArgsToIgnore
|
|
99
|
-
});
|
|
100
|
-
const tmpContext = await tmpBrowser.newContext({
|
|
101
|
-
viewport
|
|
102
|
-
});
|
|
103
|
-
const tmpPage = await tmpContext.newPage();
|
|
104
|
-
const ua = await tmpPage.evaluate(() => navigator.userAgent);
|
|
105
|
-
await tmpBrowser.close();
|
|
106
|
-
if (ua) {
|
|
107
|
-
console.log("Detected UA:", ua);
|
|
108
|
-
userAgent = ua.replace("HeadlessChrome", "Chrome");
|
|
109
|
-
console.log("Using UA:", userAgent);
|
|
110
|
-
}
|
|
111
|
-
}
|
|
91
|
+
const userAgent = process.env.PLAYWRIGHT_USER_AGENT_OVERRIDE ?? (await getHeadlessUserAgent({
|
|
92
|
+
executablePath
|
|
93
|
+
}));
|
|
112
94
|
const context = await playwright.chromium.launchPersistentContext(userDataDir, {
|
|
113
95
|
userAgent,
|
|
114
96
|
executablePath,
|
|
@@ -193,4 +175,34 @@ async function waitOnCdpAddress(cdpAddress) {
|
|
|
193
175
|
tcpTimeout: 1000,
|
|
194
176
|
window: 1000
|
|
195
177
|
});
|
|
178
|
+
}
|
|
179
|
+
async function getHeadlessUserAgent({
|
|
180
|
+
executablePath,
|
|
181
|
+
args,
|
|
182
|
+
ignoreDefaultArgs
|
|
183
|
+
}) {
|
|
184
|
+
if (!executablePath) {
|
|
185
|
+
const browserType = getBrowserType();
|
|
186
|
+
if (browserType === "brave") {
|
|
187
|
+
const braveExecutablePath = await getBraveExecutablePath();
|
|
188
|
+
if (await fs.exists(braveExecutablePath)) {
|
|
189
|
+
executablePath = braveExecutablePath;
|
|
190
|
+
}
|
|
191
|
+
}
|
|
192
|
+
}
|
|
193
|
+
const browser = await playwright.chromium.launch({
|
|
194
|
+
headless: true,
|
|
195
|
+
executablePath,
|
|
196
|
+
args,
|
|
197
|
+
ignoreDefaultArgs
|
|
198
|
+
});
|
|
199
|
+
const context = await browser.newContext();
|
|
200
|
+
const page = await context.newPage();
|
|
201
|
+
let userAgent = await page.evaluate(() => navigator.userAgent);
|
|
202
|
+
await browser.close();
|
|
203
|
+
if (!userAgent || typeof userAgent !== "string") {
|
|
204
|
+
return undefined;
|
|
205
|
+
}
|
|
206
|
+
userAgent = userAgent.replace("HeadlessChrome", "Chrome");
|
|
207
|
+
return userAgent;
|
|
196
208
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@intuned/runtime-dev",
|
|
3
|
-
"version": "1.3.12-ua.
|
|
3
|
+
"version": "1.3.12-ua.4",
|
|
4
4
|
"description": "Intuned runtime",
|
|
5
5
|
"exports": {
|
|
6
6
|
".": "./dist/index.js",
|
|
@@ -30,6 +30,7 @@
|
|
|
30
30
|
"intuned-auth-session-load": "vite-node ./src/commands/auth/load.ts",
|
|
31
31
|
"intuned-ts-check": "yarn prepublishOnly && vite-node ./src/commands/ts-check.ts",
|
|
32
32
|
"intuned": "vite-node ./src/commands/intuned-cli/main.ts",
|
|
33
|
+
"intuned-get-headless-user-agent": "vite-node ./src/commands/get-headless-user-agent.ts",
|
|
33
34
|
"build": "rm -rf dist && tsc -p tsconfig.json && yarn copy-dts && babel src --out-dir dist --extensions '.ts' && cp -r ./src/common/assets dist/common/assets",
|
|
34
35
|
"test": "vitest run",
|
|
35
36
|
"test:watch": "vitest",
|
|
@@ -50,6 +51,7 @@
|
|
|
50
51
|
"intuned-browser-start": "bin/intuned-browser-start",
|
|
51
52
|
"intuned-browser-save-state": "bin/intuned-browser-save-state",
|
|
52
53
|
"intuned-ts-check": "bin/intuned-ts-check",
|
|
54
|
+
"intuned-get-headless-user-agent": "bin/intuned-get-headless-user-agent",
|
|
53
55
|
"intuned": "bin/intuned"
|
|
54
56
|
},
|
|
55
57
|
"dependencies": {
|
|
File without changes
|
|
File without changes
|