@agent-infra/browser 0.0.1
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/LICENSE +201 -0
- package/README.md +74 -0
- package/dist/base-browser.d.ts +89 -0
- package/dist/base-browser.d.ts.map +1 -0
- package/dist/base-browser.js +146 -0
- package/dist/base-browser.js.map +1 -0
- package/dist/base-browser.mjs +114 -0
- package/dist/base-browser.mjs.map +1 -0
- package/dist/browser-finder.d.ts +59 -0
- package/dist/browser-finder.d.ts.map +1 -0
- package/dist/browser-finder.js +148 -0
- package/dist/browser-finder.js.map +1 -0
- package/dist/browser-finder.mjs +116 -0
- package/dist/browser-finder.mjs.map +1 -0
- package/dist/browser-finder.test.d.ts +2 -0
- package/dist/browser-finder.test.d.ts.map +1 -0
- package/dist/index.d.ts +17 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +101 -0
- package/dist/index.mjs +9 -0
- package/dist/local-browser.d.ts +23 -0
- package/dist/local-browser.d.ts.map +1 -0
- package/dist/local-browser.js +110 -0
- package/dist/local-browser.js.map +1 -0
- package/dist/local-browser.mjs +78 -0
- package/dist/local-browser.mjs.map +1 -0
- package/dist/remote-browser.d.ts +49 -0
- package/dist/remote-browser.d.ts.map +1 -0
- package/dist/remote-browser.js +85 -0
- package/dist/remote-browser.js.map +1 -0
- package/dist/remote-browser.mjs +53 -0
- package/dist/remote-browser.mjs.map +1 -0
- package/dist/types.d.ts +132 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +38 -0
- package/dist/types.mjs +7 -0
- package/package.json +39 -0
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) 2025 Bytedance, Inc. and its affiliates.
|
|
3
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
4
|
+
*/
|
|
5
|
+
"use strict";
|
|
6
|
+
var __webpack_require__ = {};
|
|
7
|
+
(()=>{
|
|
8
|
+
__webpack_require__.d = (exports1, definition)=>{
|
|
9
|
+
for(var key in definition)if (__webpack_require__.o(definition, key) && !__webpack_require__.o(exports1, key)) Object.defineProperty(exports1, key, {
|
|
10
|
+
enumerable: true,
|
|
11
|
+
get: definition[key]
|
|
12
|
+
});
|
|
13
|
+
};
|
|
14
|
+
})();
|
|
15
|
+
(()=>{
|
|
16
|
+
__webpack_require__.o = (obj, prop)=>Object.prototype.hasOwnProperty.call(obj, prop);
|
|
17
|
+
})();
|
|
18
|
+
(()=>{
|
|
19
|
+
__webpack_require__.r = function(exports1) {
|
|
20
|
+
if ('undefined' != typeof Symbol && Symbol.toStringTag) Object.defineProperty(exports1, Symbol.toStringTag, {
|
|
21
|
+
value: 'Module'
|
|
22
|
+
});
|
|
23
|
+
Object.defineProperty(exports1, '__esModule', {
|
|
24
|
+
value: true
|
|
25
|
+
});
|
|
26
|
+
};
|
|
27
|
+
})();
|
|
28
|
+
var __webpack_exports__ = {};
|
|
29
|
+
__webpack_require__.r(__webpack_exports__);
|
|
30
|
+
__webpack_require__.d(__webpack_exports__, {
|
|
31
|
+
LocalBrowser: ()=>LocalBrowser
|
|
32
|
+
});
|
|
33
|
+
const external_puppeteer_core_namespaceObject = require("puppeteer-core");
|
|
34
|
+
const external_browser_finder_js_namespaceObject = require("./browser-finder.js");
|
|
35
|
+
const external_base_browser_js_namespaceObject = require("./base-browser.js");
|
|
36
|
+
function _define_property(obj, key, value) {
|
|
37
|
+
if (key in obj) Object.defineProperty(obj, key, {
|
|
38
|
+
value: value,
|
|
39
|
+
enumerable: true,
|
|
40
|
+
configurable: true,
|
|
41
|
+
writable: true
|
|
42
|
+
});
|
|
43
|
+
else obj[key] = value;
|
|
44
|
+
return obj;
|
|
45
|
+
}
|
|
46
|
+
class LocalBrowser extends external_base_browser_js_namespaceObject.BaseBrowser {
|
|
47
|
+
async launch(options = {}) {
|
|
48
|
+
var _options_defaultViewport, _options_defaultViewport1;
|
|
49
|
+
this.logger.info('Launching browser with options:', options);
|
|
50
|
+
const executablePath = (null == options ? void 0 : options.executablePath) || this.browserFinder.findBrowser().executable;
|
|
51
|
+
this.logger.info('Using executable path:', executablePath);
|
|
52
|
+
const viewportWidth = (null == options ? void 0 : null === (_options_defaultViewport = options.defaultViewport) || void 0 === _options_defaultViewport ? void 0 : _options_defaultViewport.width) ?? 1280;
|
|
53
|
+
const viewportHeight = (null == options ? void 0 : null === (_options_defaultViewport1 = options.defaultViewport) || void 0 === _options_defaultViewport1 ? void 0 : _options_defaultViewport1.height) ?? 800;
|
|
54
|
+
const puppeteerLaunchOptions = {
|
|
55
|
+
executablePath,
|
|
56
|
+
headless: (null == options ? void 0 : options.headless) ?? false,
|
|
57
|
+
defaultViewport: {
|
|
58
|
+
width: viewportWidth,
|
|
59
|
+
height: viewportHeight
|
|
60
|
+
},
|
|
61
|
+
args: [
|
|
62
|
+
'--no-sandbox',
|
|
63
|
+
'--mute-audio',
|
|
64
|
+
'--disable-gpu',
|
|
65
|
+
'--disable-http2',
|
|
66
|
+
'--disable-blink-features=AutomationControlled',
|
|
67
|
+
'--disable-infobars',
|
|
68
|
+
'--disable-background-timer-throttling',
|
|
69
|
+
'--disable-popup-blocking',
|
|
70
|
+
'--disable-backgrounding-occluded-windows',
|
|
71
|
+
'--disable-renderer-backgrounding',
|
|
72
|
+
'--disable-window-activation',
|
|
73
|
+
'--disable-focus-on-load',
|
|
74
|
+
'--no-default-browser-check',
|
|
75
|
+
'--disable-web-security',
|
|
76
|
+
'--disable-features=IsolateOrigins,site-per-process',
|
|
77
|
+
'--disable-site-isolation-trials',
|
|
78
|
+
`--window-size=${viewportWidth},${viewportHeight + 90}`,
|
|
79
|
+
(null == options ? void 0 : options.proxy) ? `--proxy-server=${options.proxy}` : '',
|
|
80
|
+
(null == options ? void 0 : options.profilePath) ? `--profile-directory=${options.profilePath}` : ''
|
|
81
|
+
].filter(Boolean),
|
|
82
|
+
ignoreDefaultArgs: [
|
|
83
|
+
'--enable-automation'
|
|
84
|
+
],
|
|
85
|
+
timeout: options.timeout ?? 0,
|
|
86
|
+
downloadBehavior: {
|
|
87
|
+
policy: 'deny'
|
|
88
|
+
}
|
|
89
|
+
};
|
|
90
|
+
this.logger.info('Launch options:', puppeteerLaunchOptions);
|
|
91
|
+
try {
|
|
92
|
+
this.browser = await external_puppeteer_core_namespaceObject.launch(puppeteerLaunchOptions);
|
|
93
|
+
await this.setupPageListener();
|
|
94
|
+
this.logger.success('Browser launched successfully');
|
|
95
|
+
} catch (error) {
|
|
96
|
+
this.logger.error('Failed to launch browser:', error);
|
|
97
|
+
throw error;
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
constructor(...args){
|
|
101
|
+
super(...args), _define_property(this, "browserFinder", new external_browser_finder_js_namespaceObject.BrowserFinder());
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
var __webpack_export_target__ = exports;
|
|
105
|
+
for(var __webpack_i__ in __webpack_exports__)__webpack_export_target__[__webpack_i__] = __webpack_exports__[__webpack_i__];
|
|
106
|
+
if (__webpack_exports__.__esModule) Object.defineProperty(__webpack_export_target__, '__esModule', {
|
|
107
|
+
value: true
|
|
108
|
+
});
|
|
109
|
+
|
|
110
|
+
//# sourceMappingURL=local-browser.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"local-browser.js","sources":["webpack://@agent-infra/browser/./src/local-browser.ts"],"sourcesContent":["/*\n * Copyright (c) 2025 Bytedance, Inc. and its affiliates.\n * SPDX-License-Identifier: Apache-2.0\n */\nimport * as puppeteer from 'puppeteer-core';\nimport { LaunchOptions } from './types';\nimport { BrowserFinder } from './browser-finder';\nimport { BaseBrowser } from './base-browser';\n\n/**\n * LocalBrowser class for controlling locally installed browsers\n * Extends the BaseBrowser with functionality specific to managing local browser instances\n * @extends BaseBrowser\n */\nexport class LocalBrowser extends BaseBrowser {\n /**\n * Browser finder instance to detect and locate installed browsers\n * @private\n */\n private browserFinder = new BrowserFinder();\n\n /**\n * Launches a local browser instance with specified options\n * Automatically detects installed browsers if no executable path is provided\n * @param {LaunchOptions} options - Configuration options for launching the browser\n * @returns {Promise<void>} Promise that resolves when the browser is successfully launched\n * @throws {Error} If the browser cannot be launched\n */\n async launch(options: LaunchOptions = {}): Promise<void> {\n this.logger.info('Launching browser with options:', options);\n\n const executablePath =\n options?.executablePath || this.browserFinder.findBrowser().executable;\n\n this.logger.info('Using executable path:', executablePath);\n\n const viewportWidth = options?.defaultViewport?.width ?? 1280;\n const viewportHeight = options?.defaultViewport?.height ?? 800;\n\n const puppeteerLaunchOptions: puppeteer.LaunchOptions = {\n executablePath,\n headless: options?.headless ?? false,\n defaultViewport: {\n width: viewportWidth,\n height: viewportHeight,\n },\n args: [\n '--no-sandbox',\n '--mute-audio',\n '--disable-gpu',\n '--disable-http2',\n '--disable-blink-features=AutomationControlled',\n '--disable-infobars',\n '--disable-background-timer-throttling',\n '--disable-popup-blocking',\n '--disable-backgrounding-occluded-windows',\n '--disable-renderer-backgrounding',\n '--disable-window-activation',\n '--disable-focus-on-load',\n '--no-default-browser-check', // disable default browser check\n '--disable-web-security', // disable CORS\n '--disable-features=IsolateOrigins,site-per-process',\n '--disable-site-isolation-trials',\n `--window-size=${viewportWidth},${viewportHeight + 90}`,\n options?.proxy ? `--proxy-server=${options.proxy}` : '',\n options?.profilePath\n ? `--profile-directory=${options.profilePath}`\n : '',\n ].filter(Boolean),\n ignoreDefaultArgs: ['--enable-automation'],\n timeout: options.timeout ?? 0,\n downloadBehavior: {\n policy: 'deny',\n },\n };\n\n this.logger.info('Launch options:', puppeteerLaunchOptions);\n\n try {\n this.browser = await puppeteer.launch(puppeteerLaunchOptions);\n await this.setupPageListener();\n this.logger.success('Browser launched successfully');\n } catch (error) {\n this.logger.error('Failed to launch browser:', error);\n throw error;\n }\n }\n}\n"],"names":["LocalBrowser","BaseBrowser","options","_options_defaultViewport","_options_defaultViewport1","executablePath","viewportWidth","viewportHeight","puppeteerLaunchOptions","Boolean","puppeteer","error","BrowserFinder"],"mappings":";;;;;;;;;;;;;;;;;;;;;;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,IAAAA,QAAS,WAAW,AAAD,IACf,CAAC,oBAAoB,EAAEA,QAAQ,WAAW,EAAE,GAC5C;aACL,CAAC,MAAM,CAACO;YACT,mBAAmB;gBAAC;aAAsB;YAC1C,SAASP,QAAQ,OAAO,IAAI;YAC5B,kBAAkB;gBAChB,QAAQ;YACV;QACF;QAEA,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,mBAAmBM;QAEpC,IAAI;YACF,IAAI,CAAC,OAAO,GAAG,MAAME,wCAAAA,MAAgB,CAACF;YACtC,MAAM,IAAI,CAAC,iBAAiB;YAC5B,IAAI,CAAC,MAAM,CAAC,OAAO,CAAC;QACtB,EAAE,OAAOG,OAAO;YACd,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,6BAA6BA;YAC/C,MAAMA;QACR;IACF;;QAxEK,gBAKL,uBAAQ,iBAAgB,IAAIC,2CAAAA,aAAaA;;AAoE3C"}
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) 2025 Bytedance, Inc. and its affiliates.
|
|
3
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
4
|
+
*/
|
|
5
|
+
import * as __WEBPACK_EXTERNAL_MODULE_puppeteer_core_17481843__ from "puppeteer-core";
|
|
6
|
+
import * as __WEBPACK_EXTERNAL_MODULE__browser_finder_mjs_e776194b__ from "./browser-finder.mjs";
|
|
7
|
+
import * as __WEBPACK_EXTERNAL_MODULE__base_browser_mjs_64d751a3__ from "./base-browser.mjs";
|
|
8
|
+
function _define_property(obj, key, value) {
|
|
9
|
+
if (key in obj) Object.defineProperty(obj, key, {
|
|
10
|
+
value: value,
|
|
11
|
+
enumerable: true,
|
|
12
|
+
configurable: true,
|
|
13
|
+
writable: true
|
|
14
|
+
});
|
|
15
|
+
else obj[key] = value;
|
|
16
|
+
return obj;
|
|
17
|
+
}
|
|
18
|
+
class LocalBrowser extends __WEBPACK_EXTERNAL_MODULE__base_browser_mjs_64d751a3__.BaseBrowser {
|
|
19
|
+
async launch(options = {}) {
|
|
20
|
+
var _options_defaultViewport, _options_defaultViewport1;
|
|
21
|
+
this.logger.info('Launching browser with options:', options);
|
|
22
|
+
const executablePath = (null == options ? void 0 : options.executablePath) || this.browserFinder.findBrowser().executable;
|
|
23
|
+
this.logger.info('Using executable path:', executablePath);
|
|
24
|
+
const viewportWidth = (null == options ? void 0 : null === (_options_defaultViewport = options.defaultViewport) || void 0 === _options_defaultViewport ? void 0 : _options_defaultViewport.width) ?? 1280;
|
|
25
|
+
const viewportHeight = (null == options ? void 0 : null === (_options_defaultViewport1 = options.defaultViewport) || void 0 === _options_defaultViewport1 ? void 0 : _options_defaultViewport1.height) ?? 800;
|
|
26
|
+
const puppeteerLaunchOptions = {
|
|
27
|
+
executablePath,
|
|
28
|
+
headless: (null == options ? void 0 : options.headless) ?? false,
|
|
29
|
+
defaultViewport: {
|
|
30
|
+
width: viewportWidth,
|
|
31
|
+
height: viewportHeight
|
|
32
|
+
},
|
|
33
|
+
args: [
|
|
34
|
+
'--no-sandbox',
|
|
35
|
+
'--mute-audio',
|
|
36
|
+
'--disable-gpu',
|
|
37
|
+
'--disable-http2',
|
|
38
|
+
'--disable-blink-features=AutomationControlled',
|
|
39
|
+
'--disable-infobars',
|
|
40
|
+
'--disable-background-timer-throttling',
|
|
41
|
+
'--disable-popup-blocking',
|
|
42
|
+
'--disable-backgrounding-occluded-windows',
|
|
43
|
+
'--disable-renderer-backgrounding',
|
|
44
|
+
'--disable-window-activation',
|
|
45
|
+
'--disable-focus-on-load',
|
|
46
|
+
'--no-default-browser-check',
|
|
47
|
+
'--disable-web-security',
|
|
48
|
+
'--disable-features=IsolateOrigins,site-per-process',
|
|
49
|
+
'--disable-site-isolation-trials',
|
|
50
|
+
`--window-size=${viewportWidth},${viewportHeight + 90}`,
|
|
51
|
+
(null == options ? void 0 : options.proxy) ? `--proxy-server=${options.proxy}` : '',
|
|
52
|
+
(null == options ? void 0 : options.profilePath) ? `--profile-directory=${options.profilePath}` : ''
|
|
53
|
+
].filter(Boolean),
|
|
54
|
+
ignoreDefaultArgs: [
|
|
55
|
+
'--enable-automation'
|
|
56
|
+
],
|
|
57
|
+
timeout: options.timeout ?? 0,
|
|
58
|
+
downloadBehavior: {
|
|
59
|
+
policy: 'deny'
|
|
60
|
+
}
|
|
61
|
+
};
|
|
62
|
+
this.logger.info('Launch options:', puppeteerLaunchOptions);
|
|
63
|
+
try {
|
|
64
|
+
this.browser = await __WEBPACK_EXTERNAL_MODULE_puppeteer_core_17481843__.launch(puppeteerLaunchOptions);
|
|
65
|
+
await this.setupPageListener();
|
|
66
|
+
this.logger.success('Browser launched successfully');
|
|
67
|
+
} catch (error) {
|
|
68
|
+
this.logger.error('Failed to launch browser:', error);
|
|
69
|
+
throw error;
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
constructor(...args){
|
|
73
|
+
super(...args), _define_property(this, "browserFinder", new __WEBPACK_EXTERNAL_MODULE__browser_finder_mjs_e776194b__.BrowserFinder());
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
export { LocalBrowser };
|
|
77
|
+
|
|
78
|
+
//# sourceMappingURL=local-browser.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"local-browser.mjs","sources":["webpack://@agent-infra/browser/./src/local-browser.ts"],"sourcesContent":["/*\n * Copyright (c) 2025 Bytedance, Inc. and its affiliates.\n * SPDX-License-Identifier: Apache-2.0\n */\nimport * as puppeteer from 'puppeteer-core';\nimport { LaunchOptions } from './types';\nimport { BrowserFinder } from './browser-finder';\nimport { BaseBrowser } from './base-browser';\n\n/**\n * LocalBrowser class for controlling locally installed browsers\n * Extends the BaseBrowser with functionality specific to managing local browser instances\n * @extends BaseBrowser\n */\nexport class LocalBrowser extends BaseBrowser {\n /**\n * Browser finder instance to detect and locate installed browsers\n * @private\n */\n private browserFinder = new BrowserFinder();\n\n /**\n * Launches a local browser instance with specified options\n * Automatically detects installed browsers if no executable path is provided\n * @param {LaunchOptions} options - Configuration options for launching the browser\n * @returns {Promise<void>} Promise that resolves when the browser is successfully launched\n * @throws {Error} If the browser cannot be launched\n */\n async launch(options: LaunchOptions = {}): Promise<void> {\n this.logger.info('Launching browser with options:', options);\n\n const executablePath =\n options?.executablePath || this.browserFinder.findBrowser().executable;\n\n this.logger.info('Using executable path:', executablePath);\n\n const viewportWidth = options?.defaultViewport?.width ?? 1280;\n const viewportHeight = options?.defaultViewport?.height ?? 800;\n\n const puppeteerLaunchOptions: puppeteer.LaunchOptions = {\n executablePath,\n headless: options?.headless ?? false,\n defaultViewport: {\n width: viewportWidth,\n height: viewportHeight,\n },\n args: [\n '--no-sandbox',\n '--mute-audio',\n '--disable-gpu',\n '--disable-http2',\n '--disable-blink-features=AutomationControlled',\n '--disable-infobars',\n '--disable-background-timer-throttling',\n '--disable-popup-blocking',\n '--disable-backgrounding-occluded-windows',\n '--disable-renderer-backgrounding',\n '--disable-window-activation',\n '--disable-focus-on-load',\n '--no-default-browser-check', // disable default browser check\n '--disable-web-security', // disable CORS\n '--disable-features=IsolateOrigins,site-per-process',\n '--disable-site-isolation-trials',\n `--window-size=${viewportWidth},${viewportHeight + 90}`,\n options?.proxy ? `--proxy-server=${options.proxy}` : '',\n options?.profilePath\n ? `--profile-directory=${options.profilePath}`\n : '',\n ].filter(Boolean),\n ignoreDefaultArgs: ['--enable-automation'],\n timeout: options.timeout ?? 0,\n downloadBehavior: {\n policy: 'deny',\n },\n };\n\n this.logger.info('Launch options:', puppeteerLaunchOptions);\n\n try {\n this.browser = await puppeteer.launch(puppeteerLaunchOptions);\n await this.setupPageListener();\n this.logger.success('Browser launched successfully');\n } catch (error) {\n this.logger.error('Failed to launch browser:', error);\n throw error;\n }\n }\n}\n"],"names":["LocalBrowser","BaseBrowser","options","_options_defaultViewport","_options_defaultViewport1","executablePath","viewportWidth","viewportHeight","puppeteerLaunchOptions","Boolean","puppeteer","error","BrowserFinder"],"mappings":";;;;;;;AAGC;;;;;;;;;;AAWM,MA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AoB,EAAEA,QAAQ,WAAW,EAAE,GAC5C;aACL,CAAC,MAAM,CAACO;YACT,mBAAmB;gBAAC;aAAsB;YAC1C,SAASP,QAAQ,OAAO,IAAI;YAC5B,kBAAkB;gBAChB,QAAQ;YACV;QACF;QAEA,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,mBAAmBM;QAEpC,IAAI;YACF,IAAI,CAAC,OAAO,GAAG,MAAME,oDAAAA,MAAgB,CAACF;YACtC,MAAM,IAAI,CAAC,iBAAiB;YAC5B,IAAI,CAAC,MAAM,CAAC,OAAO,CAAC;QACtB,EAAE,OAAOG,OAAO;YACd,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,6BAA6BA;YAC/C,MAAMA;QACR;IACF;;QAxEK,gBAKL,uBAAQ,iBAAgB,IAAIC,yDAAAA,aAAaA;;AAoE3C"}
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import { BaseBrowser, BaseBrowserOptions } from './base-browser';
|
|
2
|
+
import { LaunchOptions } from './types';
|
|
3
|
+
/**
|
|
4
|
+
* Configuration options for RemoteBrowser
|
|
5
|
+
* @extends BaseBrowserOptions
|
|
6
|
+
* @interface RemoteBrowserOptions
|
|
7
|
+
* @property {string} [wsEndpoint] - WebSocket endpoint URL for direct connection
|
|
8
|
+
* @property {string} [host] - Remote host address (default: 'localhost')
|
|
9
|
+
* @property {number} [port] - Remote debugging port (default: 9222)
|
|
10
|
+
*/
|
|
11
|
+
export interface RemoteBrowserOptions extends BaseBrowserOptions {
|
|
12
|
+
wsEndpoint?: string;
|
|
13
|
+
host?: string;
|
|
14
|
+
port?: number;
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* RemoteBrowser class for connecting to remote browser instances
|
|
18
|
+
*
|
|
19
|
+
* Currently, this RemoteBrowser is not production ready,
|
|
20
|
+
* mainly because it still relies on `puppeteer-core`,
|
|
21
|
+
* which can only run on Node.js.
|
|
22
|
+
*
|
|
23
|
+
* At the same time, Chrome instances built with
|
|
24
|
+
* `--remote-debugging-address` on Linux have security risks
|
|
25
|
+
*
|
|
26
|
+
* @see https://issues.chromium.org/issues/41487252
|
|
27
|
+
* @see https://issues.chromium.org/issues/40261787
|
|
28
|
+
* @see https://github.com/pyppeteer/pyppeteer/pull/379
|
|
29
|
+
* @see https://stackoverflow.com/questions/72760355/chrome-remote-debugging-not-working-computer-to-computer
|
|
30
|
+
*
|
|
31
|
+
* @extends BaseBrowser
|
|
32
|
+
*/
|
|
33
|
+
export declare class RemoteBrowser extends BaseBrowser {
|
|
34
|
+
private options?;
|
|
35
|
+
/**
|
|
36
|
+
* Creates a new RemoteBrowser instance
|
|
37
|
+
* @param {RemoteBrowserOptions} [options] - Configuration options for remote browser connection
|
|
38
|
+
*/
|
|
39
|
+
constructor(options?: RemoteBrowserOptions | undefined);
|
|
40
|
+
/**
|
|
41
|
+
* Connects to a remote browser instance using WebSocket
|
|
42
|
+
* If no WebSocket endpoint is provided, attempts to discover it using the DevTools Protocol
|
|
43
|
+
* @param {LaunchOptions} [options] - Launch configuration options
|
|
44
|
+
* @returns {Promise<void>} Promise that resolves when connected to the remote browser
|
|
45
|
+
* @throws {Error} If connection to the remote browser fails
|
|
46
|
+
*/
|
|
47
|
+
launch(options?: LaunchOptions): Promise<void>;
|
|
48
|
+
}
|
|
49
|
+
//# sourceMappingURL=remote-browser.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"remote-browser.d.ts","sourceRoot":"","sources":["../src/remote-browser.ts"],"names":[],"mappings":"AAKA,OAAO,EAAE,WAAW,EAAE,kBAAkB,EAAE,MAAM,gBAAgB,CAAC;AACjE,OAAO,EAAE,aAAa,EAAE,MAAM,SAAS,CAAC;AAExC;;;;;;;GAOG;AACH,MAAM,WAAW,oBAAqB,SAAQ,kBAAkB;IAC9D,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,IAAI,CAAC,EAAE,MAAM,CAAC;CACf;AAED;;;;;;;;;;;;;;;;GAgBG;AACH,qBAAa,aAAc,SAAQ,WAAW;IAKhC,OAAO,CAAC,OAAO,CAAC;IAJ5B;;;OAGG;gBACiB,OAAO,CAAC,EAAE,oBAAoB,YAAA;IAIlD;;;;;;OAMG;IACG,MAAM,CAAC,OAAO,CAAC,EAAE,aAAa,GAAG,OAAO,CAAC,IAAI,CAAC;CA6BrD"}
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) 2025 Bytedance, Inc. and its affiliates.
|
|
3
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
4
|
+
*/
|
|
5
|
+
"use strict";
|
|
6
|
+
var __webpack_require__ = {};
|
|
7
|
+
(()=>{
|
|
8
|
+
__webpack_require__.d = (exports1, definition)=>{
|
|
9
|
+
for(var key in definition)if (__webpack_require__.o(definition, key) && !__webpack_require__.o(exports1, key)) Object.defineProperty(exports1, key, {
|
|
10
|
+
enumerable: true,
|
|
11
|
+
get: definition[key]
|
|
12
|
+
});
|
|
13
|
+
};
|
|
14
|
+
})();
|
|
15
|
+
(()=>{
|
|
16
|
+
__webpack_require__.o = (obj, prop)=>Object.prototype.hasOwnProperty.call(obj, prop);
|
|
17
|
+
})();
|
|
18
|
+
(()=>{
|
|
19
|
+
__webpack_require__.r = function(exports1) {
|
|
20
|
+
if ('undefined' != typeof Symbol && Symbol.toStringTag) Object.defineProperty(exports1, Symbol.toStringTag, {
|
|
21
|
+
value: 'Module'
|
|
22
|
+
});
|
|
23
|
+
Object.defineProperty(exports1, '__esModule', {
|
|
24
|
+
value: true
|
|
25
|
+
});
|
|
26
|
+
};
|
|
27
|
+
})();
|
|
28
|
+
var __webpack_exports__ = {};
|
|
29
|
+
__webpack_require__.r(__webpack_exports__);
|
|
30
|
+
__webpack_require__.d(__webpack_exports__, {
|
|
31
|
+
RemoteBrowser: ()=>RemoteBrowser
|
|
32
|
+
});
|
|
33
|
+
const external_puppeteer_core_namespaceObject = require("puppeteer-core");
|
|
34
|
+
const external_base_browser_js_namespaceObject = require("./base-browser.js");
|
|
35
|
+
function _define_property(obj, key, value) {
|
|
36
|
+
if (key in obj) Object.defineProperty(obj, key, {
|
|
37
|
+
value: value,
|
|
38
|
+
enumerable: true,
|
|
39
|
+
configurable: true,
|
|
40
|
+
writable: true
|
|
41
|
+
});
|
|
42
|
+
else obj[key] = value;
|
|
43
|
+
return obj;
|
|
44
|
+
}
|
|
45
|
+
class RemoteBrowser extends external_base_browser_js_namespaceObject.BaseBrowser {
|
|
46
|
+
async launch(options) {
|
|
47
|
+
var _this_options;
|
|
48
|
+
this.logger.info('Browser Launch options:', options);
|
|
49
|
+
let browserWSEndpoint = null === (_this_options = this.options) || void 0 === _this_options ? void 0 : _this_options.wsEndpoint;
|
|
50
|
+
if (!browserWSEndpoint) {
|
|
51
|
+
var _this_options1, _this_options2;
|
|
52
|
+
const host = (null === (_this_options1 = this.options) || void 0 === _this_options1 ? void 0 : _this_options1.host) || 'localhost';
|
|
53
|
+
const port = (null === (_this_options2 = this.options) || void 0 === _this_options2 ? void 0 : _this_options2.port) || 9222;
|
|
54
|
+
const response = await fetch(`http://${host}:${port}/json/version`);
|
|
55
|
+
const { webSocketDebuggerUrl } = await response.json();
|
|
56
|
+
browserWSEndpoint = webSocketDebuggerUrl;
|
|
57
|
+
}
|
|
58
|
+
this.logger.info('Using WebSocket endpoint:', browserWSEndpoint);
|
|
59
|
+
const puppeteerConnectOptions = {
|
|
60
|
+
browserWSEndpoint,
|
|
61
|
+
defaultViewport: (null == options ? void 0 : options.defaultViewport) ?? {
|
|
62
|
+
width: 1280,
|
|
63
|
+
height: 800
|
|
64
|
+
}
|
|
65
|
+
};
|
|
66
|
+
try {
|
|
67
|
+
this.browser = await external_puppeteer_core_namespaceObject.connect(puppeteerConnectOptions);
|
|
68
|
+
await this.setupPageListener();
|
|
69
|
+
this.logger.success('Connected to remote browser successfully');
|
|
70
|
+
} catch (error) {
|
|
71
|
+
this.logger.error('Failed to connect to remote browser:', error);
|
|
72
|
+
throw error;
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
constructor(options){
|
|
76
|
+
super(options), _define_property(this, "options", void 0), this.options = options;
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
var __webpack_export_target__ = exports;
|
|
80
|
+
for(var __webpack_i__ in __webpack_exports__)__webpack_export_target__[__webpack_i__] = __webpack_exports__[__webpack_i__];
|
|
81
|
+
if (__webpack_exports__.__esModule) Object.defineProperty(__webpack_export_target__, '__esModule', {
|
|
82
|
+
value: true
|
|
83
|
+
});
|
|
84
|
+
|
|
85
|
+
//# sourceMappingURL=remote-browser.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"remote-browser.js","sources":["webpack://@agent-infra/browser/./src/remote-browser.ts"],"sourcesContent":["/*\n * Copyright (c) 2025 Bytedance, Inc. and its affiliates.\n * SPDX-License-Identifier: Apache-2.0\n */\nimport * as puppeteer from 'puppeteer-core';\nimport { BaseBrowser, BaseBrowserOptions } from './base-browser';\nimport { LaunchOptions } from './types';\n\n/**\n * Configuration options for RemoteBrowser\n * @extends BaseBrowserOptions\n * @interface RemoteBrowserOptions\n * @property {string} [wsEndpoint] - WebSocket endpoint URL for direct connection\n * @property {string} [host] - Remote host address (default: 'localhost')\n * @property {number} [port] - Remote debugging port (default: 9222)\n */\nexport interface RemoteBrowserOptions extends BaseBrowserOptions {\n wsEndpoint?: string;\n host?: string;\n port?: number;\n}\n\n/**\n * RemoteBrowser class for connecting to remote browser instances\n *\n * Currently, this RemoteBrowser is not production ready,\n * mainly because it still relies on `puppeteer-core`,\n * which can only run on Node.js.\n *\n * At the same time, Chrome instances built with\n * `--remote-debugging-address` on Linux have security risks\n *\n * @see https://issues.chromium.org/issues/41487252\n * @see https://issues.chromium.org/issues/40261787\n * @see https://github.com/pyppeteer/pyppeteer/pull/379\n * @see https://stackoverflow.com/questions/72760355/chrome-remote-debugging-not-working-computer-to-computer\n *\n * @extends BaseBrowser\n */\nexport class RemoteBrowser extends BaseBrowser {\n /**\n * Creates a new RemoteBrowser instance\n * @param {RemoteBrowserOptions} [options] - Configuration options for remote browser connection\n */\n constructor(private options?: RemoteBrowserOptions) {\n super(options);\n }\n\n /**\n * Connects to a remote browser instance using WebSocket\n * If no WebSocket endpoint is provided, attempts to discover it using the DevTools Protocol\n * @param {LaunchOptions} [options] - Launch configuration options\n * @returns {Promise<void>} Promise that resolves when connected to the remote browser\n * @throws {Error} If connection to the remote browser fails\n */\n async launch(options?: LaunchOptions): Promise<void> {\n this.logger.info('Browser Launch options:', options);\n\n let browserWSEndpoint = this.options?.wsEndpoint;\n\n if (!browserWSEndpoint) {\n const host = this.options?.host || 'localhost';\n const port = this.options?.port || 9222;\n const response = await fetch(`http://${host}:${port}/json/version`);\n const { webSocketDebuggerUrl } = await response.json();\n browserWSEndpoint = webSocketDebuggerUrl;\n }\n\n this.logger.info('Using WebSocket endpoint:', browserWSEndpoint);\n\n const puppeteerConnectOptions: puppeteer.ConnectOptions = {\n browserWSEndpoint,\n defaultViewport: options?.defaultViewport ?? { width: 1280, height: 800 },\n };\n\n try {\n this.browser = await puppeteer.connect(puppeteerConnectOptions);\n await this.setupPageListener();\n this.logger.success('Connected to remote browser successfully');\n } catch (error) {\n this.logger.error('Failed to connect to remote browser:', error);\n throw error;\n }\n }\n}\n"],"names":["RemoteBrowser","BaseBrowser","options","_this_options","browserWSEndpoint","_this_options1","_this_options2","host","port","response","fetch","webSocketDebuggerUrl","puppeteerConnectOptions","puppeteer","error"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAGC;;;;;;;;;;AAoCM,MAAMA,sBAAsBC,yCAAAA,WAAWA;IAgB5C,MAAM,OAAOC,OAAuB,EAAiB;YAG3BC;QAFxB,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,2BAA2BD;QAE5C,IAAIE,oBAAoB,AAAY,SAAZD,CAAAA,gBAAAA,IAAI,CAAC,OAAO,AAAD,KAAX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* Copyright (c) 2025 Bytedance, Inc. and its affiliates.
|
|
3
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
4
|
+
*/
|
|
5
|
+
import * as __WEBPACK_EXTERNAL_MODULE_puppeteer_core_17481843__ from "puppeteer-core";
|
|
6
|
+
import * as __WEBPACK_EXTERNAL_MODULE__base_browser_mjs_64d751a3__ from "./base-browser.mjs";
|
|
7
|
+
function _define_property(obj, key, value) {
|
|
8
|
+
if (key in obj) Object.defineProperty(obj, key, {
|
|
9
|
+
value: value,
|
|
10
|
+
enumerable: true,
|
|
11
|
+
configurable: true,
|
|
12
|
+
writable: true
|
|
13
|
+
});
|
|
14
|
+
else obj[key] = value;
|
|
15
|
+
return obj;
|
|
16
|
+
}
|
|
17
|
+
class RemoteBrowser extends __WEBPACK_EXTERNAL_MODULE__base_browser_mjs_64d751a3__.BaseBrowser {
|
|
18
|
+
async launch(options) {
|
|
19
|
+
var _this_options;
|
|
20
|
+
this.logger.info('Browser Launch options:', options);
|
|
21
|
+
let browserWSEndpoint = null === (_this_options = this.options) || void 0 === _this_options ? void 0 : _this_options.wsEndpoint;
|
|
22
|
+
if (!browserWSEndpoint) {
|
|
23
|
+
var _this_options1, _this_options2;
|
|
24
|
+
const host = (null === (_this_options1 = this.options) || void 0 === _this_options1 ? void 0 : _this_options1.host) || 'localhost';
|
|
25
|
+
const port = (null === (_this_options2 = this.options) || void 0 === _this_options2 ? void 0 : _this_options2.port) || 9222;
|
|
26
|
+
const response = await fetch(`http://${host}:${port}/json/version`);
|
|
27
|
+
const { webSocketDebuggerUrl } = await response.json();
|
|
28
|
+
browserWSEndpoint = webSocketDebuggerUrl;
|
|
29
|
+
}
|
|
30
|
+
this.logger.info('Using WebSocket endpoint:', browserWSEndpoint);
|
|
31
|
+
const puppeteerConnectOptions = {
|
|
32
|
+
browserWSEndpoint,
|
|
33
|
+
defaultViewport: (null == options ? void 0 : options.defaultViewport) ?? {
|
|
34
|
+
width: 1280,
|
|
35
|
+
height: 800
|
|
36
|
+
}
|
|
37
|
+
};
|
|
38
|
+
try {
|
|
39
|
+
this.browser = await __WEBPACK_EXTERNAL_MODULE_puppeteer_core_17481843__.connect(puppeteerConnectOptions);
|
|
40
|
+
await this.setupPageListener();
|
|
41
|
+
this.logger.success('Connected to remote browser successfully');
|
|
42
|
+
} catch (error) {
|
|
43
|
+
this.logger.error('Failed to connect to remote browser:', error);
|
|
44
|
+
throw error;
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
constructor(options){
|
|
48
|
+
super(options), _define_property(this, "options", void 0), this.options = options;
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
export { RemoteBrowser };
|
|
52
|
+
|
|
53
|
+
//# sourceMappingURL=remote-browser.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"remote-browser.mjs","sources":["webpack://@agent-infra/browser/./src/remote-browser.ts"],"sourcesContent":["/*\n * Copyright (c) 2025 Bytedance, Inc. and its affiliates.\n * SPDX-License-Identifier: Apache-2.0\n */\nimport * as puppeteer from 'puppeteer-core';\nimport { BaseBrowser, BaseBrowserOptions } from './base-browser';\nimport { LaunchOptions } from './types';\n\n/**\n * Configuration options for RemoteBrowser\n * @extends BaseBrowserOptions\n * @interface RemoteBrowserOptions\n * @property {string} [wsEndpoint] - WebSocket endpoint URL for direct connection\n * @property {string} [host] - Remote host address (default: 'localhost')\n * @property {number} [port] - Remote debugging port (default: 9222)\n */\nexport interface RemoteBrowserOptions extends BaseBrowserOptions {\n wsEndpoint?: string;\n host?: string;\n port?: number;\n}\n\n/**\n * RemoteBrowser class for connecting to remote browser instances\n *\n * Currently, this RemoteBrowser is not production ready,\n * mainly because it still relies on `puppeteer-core`,\n * which can only run on Node.js.\n *\n * At the same time, Chrome instances built with\n * `--remote-debugging-address` on Linux have security risks\n *\n * @see https://issues.chromium.org/issues/41487252\n * @see https://issues.chromium.org/issues/40261787\n * @see https://github.com/pyppeteer/pyppeteer/pull/379\n * @see https://stackoverflow.com/questions/72760355/chrome-remote-debugging-not-working-computer-to-computer\n *\n * @extends BaseBrowser\n */\nexport class RemoteBrowser extends BaseBrowser {\n /**\n * Creates a new RemoteBrowser instance\n * @param {RemoteBrowserOptions} [options] - Configuration options for remote browser connection\n */\n constructor(private options?: RemoteBrowserOptions) {\n super(options);\n }\n\n /**\n * Connects to a remote browser instance using WebSocket\n * If no WebSocket endpoint is provided, attempts to discover it using the DevTools Protocol\n * @param {LaunchOptions} [options] - Launch configuration options\n * @returns {Promise<void>} Promise that resolves when connected to the remote browser\n * @throws {Error} If connection to the remote browser fails\n */\n async launch(options?: LaunchOptions): Promise<void> {\n this.logger.info('Browser Launch options:', options);\n\n let browserWSEndpoint = this.options?.wsEndpoint;\n\n if (!browserWSEndpoint) {\n const host = this.options?.host || 'localhost';\n const port = this.options?.port || 9222;\n const response = await fetch(`http://${host}:${port}/json/version`);\n const { webSocketDebuggerUrl } = await response.json();\n browserWSEndpoint = webSocketDebuggerUrl;\n }\n\n this.logger.info('Using WebSocket endpoint:', browserWSEndpoint);\n\n const puppeteerConnectOptions: puppeteer.ConnectOptions = {\n browserWSEndpoint,\n defaultViewport: options?.defaultViewport ?? { width: 1280, height: 800 },\n };\n\n try {\n this.browser = await puppeteer.connect(puppeteerConnectOptions);\n await this.setupPageListener();\n this.logger.success('Connected to remote browser successfully');\n } catch (error) {\n this.logger.error('Failed to connect to remote browser:', error);\n throw error;\n }\n }\n}\n"],"names":["RemoteBrowser","BaseBrowser","options","_this_options","browserWSEndpoint","_this_options1","_this_options2","host","port","response","fetch","webSocketDebuggerUrl","puppeteerConnectOptions","puppeteer","error"],"mappings":";;;;;;AAGC;;;;;;;;;;AAoCM,MAAMA,sBAAsBC,uDAAAA,WAAWA;IAgB5C,MAAM,OAAOC,OAAuB,EAAiB;YAG3BC;QAFxB,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,2BAA2BD;QAE5C,IAAIE,oBAAoB,AAAY,SAAZD,CAAAA,gBAAAA,IAAI,CAAC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1,132 @@
|
|
|
1
|
+
import { Page, WaitForOptions } from 'puppeteer-core';
|
|
2
|
+
/**
|
|
3
|
+
* Options for launching a browser instance
|
|
4
|
+
* @interface LaunchOptions
|
|
5
|
+
*/
|
|
6
|
+
export interface LaunchOptions {
|
|
7
|
+
/**
|
|
8
|
+
* Whether to run browser in headless mode
|
|
9
|
+
* @default false
|
|
10
|
+
*/
|
|
11
|
+
headless?: boolean;
|
|
12
|
+
/**
|
|
13
|
+
* Maximum time in milliseconds to wait for the browser to start
|
|
14
|
+
* @default 0 (no timeout)
|
|
15
|
+
*/
|
|
16
|
+
timeout?: number;
|
|
17
|
+
/**
|
|
18
|
+
* The viewport dimensions
|
|
19
|
+
* @property {number} width - Viewport width in pixels
|
|
20
|
+
* @property {number} height - Viewport height in pixels
|
|
21
|
+
*/
|
|
22
|
+
defaultViewport?: {
|
|
23
|
+
width: number;
|
|
24
|
+
height: number;
|
|
25
|
+
};
|
|
26
|
+
/**
|
|
27
|
+
* Path to a browser executable to use instead of the automatically detected one
|
|
28
|
+
* If not provided, the system will attempt to find an installed browser
|
|
29
|
+
*/
|
|
30
|
+
executablePath?: string;
|
|
31
|
+
/**
|
|
32
|
+
* Path to a specific browser profile to use
|
|
33
|
+
* Allows using existing browser profiles with cookies, extensions, etc.
|
|
34
|
+
*/
|
|
35
|
+
profilePath?: string;
|
|
36
|
+
/**
|
|
37
|
+
* Proxy server URL, e.g. 'http://proxy.example.com:8080'
|
|
38
|
+
* Used to route browser traffic through a proxy server
|
|
39
|
+
*/
|
|
40
|
+
proxy?: string;
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* Options for evaluating JavaScript in a new page
|
|
44
|
+
* @template T - Array of parameters to pass to the page function
|
|
45
|
+
* @template R - Return type of the page function
|
|
46
|
+
* @interface EvaluateOnNewPageOptions
|
|
47
|
+
*/
|
|
48
|
+
export interface EvaluateOnNewPageOptions<T extends any[], R> {
|
|
49
|
+
/**
|
|
50
|
+
* URL to navigate to before evaluating the function
|
|
51
|
+
* The page will load this URL before executing the pageFunction
|
|
52
|
+
*/
|
|
53
|
+
url: string;
|
|
54
|
+
/**
|
|
55
|
+
* Options for waiting for the page to load
|
|
56
|
+
*/
|
|
57
|
+
waitForOptions?: WaitForOptions;
|
|
58
|
+
/**
|
|
59
|
+
* Function to be evaluated in the page context
|
|
60
|
+
* This function runs in the context of the browser page, not Node.js
|
|
61
|
+
* @param {Window} window - The window object of the page
|
|
62
|
+
* @param {...T} args - Additional arguments passed to the function
|
|
63
|
+
* @returns {R} Result of the function execution
|
|
64
|
+
*/
|
|
65
|
+
pageFunction: (window: Window, ...args: T) => R;
|
|
66
|
+
/**
|
|
67
|
+
* Parameters to pass to the page function
|
|
68
|
+
* These values will be serialized and passed to the pageFunction
|
|
69
|
+
*/
|
|
70
|
+
pageFunctionParams: T;
|
|
71
|
+
/**
|
|
72
|
+
* Optional function to execute before page navigation
|
|
73
|
+
* Useful for setting up page configuration before loading the URL
|
|
74
|
+
* @param {Page} page - Puppeteer page instance
|
|
75
|
+
* @returns {void | Promise<void>}
|
|
76
|
+
*/
|
|
77
|
+
beforePageLoad?: (page: Page) => void | Promise<void>;
|
|
78
|
+
/**
|
|
79
|
+
* Optional function to execute after page navigation
|
|
80
|
+
* Useful for setting up page configuration after loading the URL
|
|
81
|
+
* @param {Page} page - Puppeteer page instance
|
|
82
|
+
* @returns {void | Promise<void>}
|
|
83
|
+
*/
|
|
84
|
+
afterPageLoad?: (page: Page) => void | Promise<void>;
|
|
85
|
+
/**
|
|
86
|
+
* Optional function to process the result before returning
|
|
87
|
+
* Can be used to transform or validate the result from page evaluation
|
|
88
|
+
* @param {Page} page - Puppeteer page instance
|
|
89
|
+
* @param {R} result - Result from page function evaluation
|
|
90
|
+
* @returns {R | Promise<R>} Processed result
|
|
91
|
+
*/
|
|
92
|
+
beforeSendResult?: (page: Page, result: R) => R | Promise<R>;
|
|
93
|
+
}
|
|
94
|
+
/**
|
|
95
|
+
* Core browser interface that all browser implementations must implement
|
|
96
|
+
* Defines the standard API for browser automation
|
|
97
|
+
* @interface BrowserInterface
|
|
98
|
+
*/
|
|
99
|
+
export interface BrowserInterface {
|
|
100
|
+
/**
|
|
101
|
+
* Launch a new browser instance
|
|
102
|
+
* @param {LaunchOptions} [options] - Launch configuration options
|
|
103
|
+
* @returns {Promise<void>} Promise resolving when browser is launched
|
|
104
|
+
*/
|
|
105
|
+
launch(options?: LaunchOptions): Promise<void>;
|
|
106
|
+
/**
|
|
107
|
+
* Close the browser instance and all its pages
|
|
108
|
+
* @returns {Promise<void>} Promise resolving when browser is closed
|
|
109
|
+
*/
|
|
110
|
+
close(): Promise<void>;
|
|
111
|
+
/**
|
|
112
|
+
* Create a new page in the browser
|
|
113
|
+
* @returns {Promise<Page>} Promise resolving to the new page instance
|
|
114
|
+
*/
|
|
115
|
+
createPage(): Promise<Page>;
|
|
116
|
+
/**
|
|
117
|
+
* Evaluate a function in a new page context
|
|
118
|
+
* Creates a new page, navigates to URL, executes function, and returns result
|
|
119
|
+
* @template T - Array of parameters to pass to the page function
|
|
120
|
+
* @template R - Return type of the page function
|
|
121
|
+
* @param {EvaluateOnNewPageOptions<T, R>} options - Evaluation options
|
|
122
|
+
* @returns {Promise<R | null>} Promise resolving to the function result or null
|
|
123
|
+
*/
|
|
124
|
+
evaluateOnNewPage<T extends any[], R>(options: EvaluateOnNewPageOptions<T, R>): Promise<R | null>;
|
|
125
|
+
/**
|
|
126
|
+
* Get the currently active page or create one if none exists
|
|
127
|
+
* @returns {Promise<Page>} Promise resolving to the active page instance
|
|
128
|
+
*/
|
|
129
|
+
getActivePage(): Promise<Page>;
|
|
130
|
+
}
|
|
131
|
+
export { Page };
|
|
132
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAKA,OAAO,EAAE,IAAI,EAAE,cAAc,EAAE,MAAM,gBAAgB,CAA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I,CAAC,CAAC;IAE/C;;;OAGG;IACH,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC,CAAC;IAEvB;;;OAGG;IACH,UAAU,IAAI,OAAO,CAAC,IAAI,CAAC,CAAC;IAE5B;;;;;;;OAOG;IACH,iBAAiB,CAAC,CAAC,SAAS,GAAG,EAAE,EAAE,CAAC,EAClC,OAAO,EAAE,wBAAwB,CAAC,CAAC,EAAE,CAAC,CAAC,GACtC,OAAO,CAAC,CAAC,GAAG,IAAI,CAAC,CAAC;IAErB;;;OAGG;IACH,aAAa,IAAI,OAAO,CAAC,IAAI,CAAC,CAAC;CAChC;AAED,OAAO,EAAE,IAAI,EAAE,CAAC"}
|
package/dist/types.js
ADDED
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) 2025 Bytedance, Inc. and its affiliates.
|
|
3
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
4
|
+
*/
|
|
5
|
+
"use strict";
|
|
6
|
+
var __webpack_require__ = {};
|
|
7
|
+
(()=>{
|
|
8
|
+
__webpack_require__.d = (exports1, definition)=>{
|
|
9
|
+
for(var key in definition)if (__webpack_require__.o(definition, key) && !__webpack_require__.o(exports1, key)) Object.defineProperty(exports1, key, {
|
|
10
|
+
enumerable: true,
|
|
11
|
+
get: definition[key]
|
|
12
|
+
});
|
|
13
|
+
};
|
|
14
|
+
})();
|
|
15
|
+
(()=>{
|
|
16
|
+
__webpack_require__.o = (obj, prop)=>Object.prototype.hasOwnProperty.call(obj, prop);
|
|
17
|
+
})();
|
|
18
|
+
(()=>{
|
|
19
|
+
__webpack_require__.r = function(exports1) {
|
|
20
|
+
if ('undefined' != typeof Symbol && Symbol.toStringTag) Object.defineProperty(exports1, Symbol.toStringTag, {
|
|
21
|
+
value: 'Module'
|
|
22
|
+
});
|
|
23
|
+
Object.defineProperty(exports1, '__esModule', {
|
|
24
|
+
value: true
|
|
25
|
+
});
|
|
26
|
+
};
|
|
27
|
+
})();
|
|
28
|
+
var __webpack_exports__ = {};
|
|
29
|
+
__webpack_require__.r(__webpack_exports__);
|
|
30
|
+
__webpack_require__.d(__webpack_exports__, {
|
|
31
|
+
Page: ()=>external_puppeteer_core_namespaceObject.Page
|
|
32
|
+
});
|
|
33
|
+
const external_puppeteer_core_namespaceObject = require("puppeteer-core");
|
|
34
|
+
var __webpack_export_target__ = exports;
|
|
35
|
+
for(var __webpack_i__ in __webpack_exports__)__webpack_export_target__[__webpack_i__] = __webpack_exports__[__webpack_i__];
|
|
36
|
+
if (__webpack_exports__.__esModule) Object.defineProperty(__webpack_export_target__, '__esModule', {
|
|
37
|
+
value: true
|
|
38
|
+
});
|
package/dist/types.mjs
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) 2025 Bytedance, Inc. and its affiliates.
|
|
3
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
4
|
+
*/
|
|
5
|
+
import * as __WEBPACK_EXTERNAL_MODULE_puppeteer_core_17481843__ from "puppeteer-core";
|
|
6
|
+
var __webpack_exports__Page = __WEBPACK_EXTERNAL_MODULE_puppeteer_core_17481843__.Page;
|
|
7
|
+
export { __webpack_exports__Page as Page };
|