@intuned/runtime-dev 1.3.12-ua.3 → 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.
|
@@ -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,7 +88,9 @@ async function launchChromium(options) {
|
|
|
87
88
|
}
|
|
88
89
|
}
|
|
89
90
|
const viewport = null;
|
|
90
|
-
const userAgent = process.env.PLAYWRIGHT_USER_AGENT_OVERRIDE ??
|
|
91
|
+
const userAgent = process.env.PLAYWRIGHT_USER_AGENT_OVERRIDE ?? (await getHeadlessUserAgent({
|
|
92
|
+
executablePath
|
|
93
|
+
}));
|
|
91
94
|
const context = await playwright.chromium.launchPersistentContext(userDataDir, {
|
|
92
95
|
userAgent,
|
|
93
96
|
executablePath,
|
|
@@ -172,4 +175,34 @@ async function waitOnCdpAddress(cdpAddress) {
|
|
|
172
175
|
tcpTimeout: 1000,
|
|
173
176
|
window: 1000
|
|
174
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;
|
|
175
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": {
|