@agent-infra/browser 0.1.6 → 0.2.0-alpha.3
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/README.md +35 -52
- package/README.zh-CN.md +57 -0
- package/dist/actions/index.d.ts +3 -0
- package/dist/actions/index.d.ts.map +1 -0
- package/dist/actions/index.js +46 -0
- package/dist/actions/index.js.map +1 -0
- package/dist/actions/index.mjs +7 -0
- package/dist/actions/key-map.d.ts +28 -0
- package/dist/actions/key-map.d.ts.map +1 -0
- package/dist/actions/key-map.js +409 -0
- package/dist/actions/key-map.js.map +1 -0
- package/dist/actions/key-map.mjs +369 -0
- package/dist/actions/key-map.mjs.map +1 -0
- package/dist/actions/keyboard.d.ts +21 -0
- package/dist/actions/keyboard.d.ts.map +1 -0
- package/dist/actions/keyboard.js +196 -0
- package/dist/actions/keyboard.js.map +1 -0
- package/dist/actions/keyboard.mjs +152 -0
- package/dist/actions/keyboard.mjs.map +1 -0
- package/dist/actions/keyboard.test.d.ts +2 -0
- package/dist/actions/keyboard.test.d.ts.map +1 -0
- package/dist/actions/mouse.d.ts +19 -0
- package/dist/actions/mouse.d.ts.map +1 -0
- package/dist/actions/mouse.js +173 -0
- package/dist/actions/mouse.js.map +1 -0
- package/dist/actions/mouse.mjs +136 -0
- package/dist/actions/mouse.mjs.map +1 -0
- package/dist/browser/base.d.ts +47 -0
- package/dist/browser/base.d.ts.map +1 -0
- package/dist/browser/base.js +156 -0
- package/dist/browser/base.js.map +1 -0
- package/dist/browser/base.mjs +122 -0
- package/dist/browser/base.mjs.map +1 -0
- package/dist/browser/browser.d.ts +23 -0
- package/dist/browser/browser.d.ts.map +1 -0
- package/dist/browser/browser.js +183 -0
- package/dist/browser/browser.js.map +1 -0
- package/dist/browser/browser.mjs +149 -0
- package/dist/browser/browser.mjs.map +1 -0
- package/dist/env.d.ts +4 -0
- package/dist/env.d.ts.map +1 -0
- package/dist/env.js +96 -0
- package/dist/env.js.map +1 -0
- package/dist/env.mjs +62 -0
- package/dist/env.mjs.map +1 -0
- package/dist/index.node.d.ts +7 -0
- package/dist/index.node.d.ts.map +1 -0
- package/dist/index.node.js +106 -0
- package/dist/index.node.js.map +1 -0
- package/dist/index.node.mjs +10 -0
- package/dist/index.web.d.ts +7 -0
- package/dist/index.web.d.ts.map +1 -0
- package/dist/{index.js → index.web.js} +33 -20
- package/dist/index.web.js.map +1 -0
- package/dist/index.web.mjs +10 -0
- package/dist/injected-script/index.d.ts +3 -0
- package/dist/injected-script/index.d.ts.map +1 -0
- package/dist/injected-script/index.js +46 -0
- package/dist/injected-script/index.js.map +1 -0
- package/dist/injected-script/index.mjs +7 -0
- package/dist/injected-script/visibility.d.ts +2 -0
- package/dist/injected-script/visibility.d.ts.map +1 -0
- package/dist/injected-script/visibility.js +66 -0
- package/dist/injected-script/visibility.js.map +1 -0
- package/dist/injected-script/visibility.mjs +32 -0
- package/dist/injected-script/visibility.mjs.map +1 -0
- package/dist/injected-script/webdriver.d.ts +2 -0
- package/dist/injected-script/webdriver.d.ts.map +1 -0
- package/dist/injected-script/webdriver.js +71 -0
- package/dist/injected-script/webdriver.js.map +1 -0
- package/dist/injected-script/webdriver.mjs +37 -0
- package/dist/injected-script/webdriver.mjs.map +1 -0
- package/dist/polyfills/index.d.ts +2 -0
- package/dist/polyfills/index.d.ts.map +1 -0
- package/dist/polyfills/index.js +66 -0
- package/dist/polyfills/index.js.map +1 -0
- package/dist/polyfills/index.mjs +5 -0
- package/dist/polyfills/withResolvers.d.ts +2 -0
- package/dist/polyfills/withResolvers.d.ts.map +1 -0
- package/dist/polyfills/withResolvers.js +37 -0
- package/dist/polyfills/withResolvers.js.map +1 -0
- package/dist/polyfills/withResolvers.mjs +19 -0
- package/dist/polyfills/withResolvers.mjs.map +1 -0
- package/dist/tabs/dialog.d.ts +14 -0
- package/dist/tabs/dialog.d.ts.map +1 -0
- package/dist/tabs/dialog.js +175 -0
- package/dist/tabs/dialog.js.map +1 -0
- package/dist/tabs/dialog.mjs +141 -0
- package/dist/tabs/dialog.mjs.map +1 -0
- package/dist/tabs/index.d.ts +3 -0
- package/dist/tabs/index.d.ts.map +1 -0
- package/dist/tabs/index.js +46 -0
- package/dist/tabs/index.js.map +1 -0
- package/dist/tabs/index.mjs +7 -0
- package/dist/tabs/tab.d.ts +50 -0
- package/dist/tabs/tab.d.ts.map +1 -0
- package/dist/tabs/tab.js +579 -0
- package/dist/tabs/tab.js.map +1 -0
- package/dist/tabs/tab.mjs +545 -0
- package/dist/tabs/tab.mjs.map +1 -0
- package/dist/tabs/tabs.d.ts +21 -0
- package/dist/tabs/tabs.d.ts.map +1 -0
- package/dist/tabs/tabs.js +458 -0
- package/dist/tabs/tabs.js.map +1 -0
- package/dist/tabs/tabs.mjs +424 -0
- package/dist/tabs/tabs.mjs.map +1 -0
- package/dist/types/actions.d.ts +26 -0
- package/dist/types/actions.d.ts.map +1 -0
- package/dist/types/actions.js +24 -0
- package/dist/types/actions.js.map +1 -0
- package/dist/types/browser.d.ts +7 -0
- package/dist/types/browser.d.ts.map +1 -0
- package/dist/types/browser.js +24 -0
- package/dist/types/browser.js.map +1 -0
- package/dist/types/browser.mjs +4 -0
- package/dist/types/dialog.d.ts +7 -0
- package/dist/types/dialog.d.ts.map +1 -0
- package/dist/types/dialog.js +24 -0
- package/dist/types/dialog.js.map +1 -0
- package/dist/types/dialog.mjs +4 -0
- package/dist/types/env.d.ts +8 -0
- package/dist/types/env.d.ts.map +1 -0
- package/dist/{types.js → types/env.js} +1 -1
- package/dist/types/env.js.map +1 -0
- package/dist/types/env.mjs +4 -0
- package/dist/types/index.d.ts +6 -0
- package/dist/types/index.d.ts.map +1 -0
- package/dist/types/index.js +102 -0
- package/dist/types/index.js.map +1 -0
- package/dist/types/index.mjs +9 -0
- package/dist/types/tabs.d.ts +98 -0
- package/dist/types/tabs.d.ts.map +1 -0
- package/dist/types/tabs.js +48 -0
- package/dist/types/tabs.js.map +1 -0
- package/dist/types/tabs.mjs +14 -0
- package/dist/types/tabs.mjs.map +1 -0
- package/dist/utils/iife.d.ts +2 -0
- package/dist/utils/iife.d.ts.map +1 -0
- package/dist/utils/iife.js +48 -0
- package/dist/utils/iife.js.map +1 -0
- package/dist/utils/iife.mjs +14 -0
- package/dist/utils/iife.mjs.map +1 -0
- package/dist/utils/index.d.ts +4 -0
- package/dist/utils/index.d.ts.map +1 -0
- package/dist/utils/index.js +50 -0
- package/dist/utils/index.js.map +1 -0
- package/dist/utils/index.mjs +8 -0
- package/dist/utils/mutex.d.ts +21 -0
- package/dist/utils/mutex.d.ts.map +1 -0
- package/dist/utils/mutex.js +133 -0
- package/dist/utils/mutex.js.map +1 -0
- package/dist/utils/mutex.mjs +99 -0
- package/dist/utils/mutex.mjs.map +1 -0
- package/dist/utils/url.d.ts +7 -0
- package/dist/utils/url.d.ts.map +1 -0
- package/dist/utils/url.js +76 -0
- package/dist/utils/url.js.map +1 -0
- package/dist/utils/url.mjs +42 -0
- package/dist/utils/url.mjs.map +1 -0
- package/package.json +21 -13
- package/dist/base-browser.d.ts +0 -94
- package/dist/base-browser.d.ts.map +0 -1
- package/dist/base-browser.js +0 -189
- package/dist/base-browser.js.map +0 -1
- package/dist/base-browser.mjs +0 -155
- package/dist/base-browser.mjs.map +0 -1
- package/dist/index.d.ts +0 -15
- package/dist/index.d.ts.map +0 -1
- package/dist/index.js.map +0 -1
- package/dist/index.mjs +0 -8
- package/dist/local-browser.d.ts +0 -19
- package/dist/local-browser.d.ts.map +0 -1
- package/dist/local-browser.js +0 -134
- package/dist/local-browser.js.map +0 -1
- package/dist/local-browser.mjs +0 -100
- package/dist/local-browser.mjs.map +0 -1
- package/dist/remote-browser.d.ts +0 -49
- package/dist/remote-browser.d.ts.map +0 -1
- package/dist/remote-browser.js +0 -89
- package/dist/remote-browser.js.map +0 -1
- package/dist/remote-browser.mjs +0 -55
- package/dist/remote-browser.mjs.map +0 -1
- package/dist/types.d.ts +0 -158
- package/dist/types.d.ts.map +0 -1
- package/dist/types.js.map +0 -1
- /package/dist/{types.mjs → types/actions.mjs} +0 -0
package/dist/remote-browser.js
DELETED
|
@@ -1,89 +0,0 @@
|
|
|
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 = (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.wsEndpoint;
|
|
50
|
-
if (!browserWSEndpoint) {
|
|
51
|
-
var _this_options1;
|
|
52
|
-
const cdpEndpoint = (null == (_this_options1 = this.options) ? void 0 : _this_options1.cdpEndpoint) || "http://127.0.0.1:9222/json/version";
|
|
53
|
-
const response = await fetch(cdpEndpoint);
|
|
54
|
-
const { webSocketDebuggerUrl } = await response.json();
|
|
55
|
-
browserWSEndpoint = webSocketDebuggerUrl;
|
|
56
|
-
}
|
|
57
|
-
this.logger.info('Using WebSocket endpoint:', browserWSEndpoint);
|
|
58
|
-
const puppeteerConnectOptions = {
|
|
59
|
-
browserWSEndpoint,
|
|
60
|
-
defaultViewport: (null == options ? void 0 : options.defaultViewport) ?? {
|
|
61
|
-
width: 1280,
|
|
62
|
-
height: 800
|
|
63
|
-
}
|
|
64
|
-
};
|
|
65
|
-
try {
|
|
66
|
-
this.browser = await external_puppeteer_core_namespaceObject.connect(puppeteerConnectOptions);
|
|
67
|
-
await this.setupPageListener();
|
|
68
|
-
this.logger.success('Connected to remote browser successfully');
|
|
69
|
-
} catch (error) {
|
|
70
|
-
this.logger.error('Failed to connect to remote browser:', error);
|
|
71
|
-
throw error;
|
|
72
|
-
}
|
|
73
|
-
}
|
|
74
|
-
async setupPageListener() {
|
|
75
|
-
super.setupPageListener();
|
|
76
|
-
}
|
|
77
|
-
constructor(options){
|
|
78
|
-
super(options), _define_property(this, "options", void 0), this.options = options;
|
|
79
|
-
}
|
|
80
|
-
}
|
|
81
|
-
exports.RemoteBrowser = __webpack_exports__.RemoteBrowser;
|
|
82
|
-
for(var __webpack_i__ in __webpack_exports__)if (-1 === [
|
|
83
|
-
"RemoteBrowser"
|
|
84
|
-
].indexOf(__webpack_i__)) exports[__webpack_i__] = __webpack_exports__[__webpack_i__];
|
|
85
|
-
Object.defineProperty(exports, '__esModule', {
|
|
86
|
-
value: true
|
|
87
|
-
});
|
|
88
|
-
|
|
89
|
-
//# sourceMappingURL=remote-browser.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"remote-browser.js","sources":["webpack://@agent-infra/browser/webpack/runtime/define_property_getters","webpack://@agent-infra/browser/webpack/runtime/has_own_property","webpack://@agent-infra/browser/webpack/runtime/make_namespace_object","webpack://@agent-infra/browser/./src/remote-browser.ts"],"sourcesContent":["__webpack_require__.d = (exports, definition) => {\n\tfor(var key in definition) {\n if(__webpack_require__.o(definition, key) && !__webpack_require__.o(exports, key)) {\n Object.defineProperty(exports, key, { enumerable: true, get: definition[key] });\n }\n }\n};","__webpack_require__.o = (obj, prop) => (Object.prototype.hasOwnProperty.call(obj, prop))","// define __esModule on exports\n__webpack_require__.r = (exports) => {\n\tif(typeof Symbol !== 'undefined' && Symbol.toStringTag) {\n\t\tObject.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });\n\t}\n\tObject.defineProperty(exports, '__esModule', { value: true });\n};","/*\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} [cdpEndpoint] - Remote Chrome DevTools Protocol endpoint\n */\nexport interface RemoteBrowserOptions extends BaseBrowserOptions {\n wsEndpoint?: string;\n /** @default http://localhost:9222/json/version */\n cdpEndpoint?: string;\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 cdpEndpoint =\n this.options?.cdpEndpoint || `http://127.0.0.1:9222/json/version`;\n const response = await fetch(cdpEndpoint);\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 async setupPageListener() {\n super.setupPageListener();\n }\n}\n"],"names":["__webpack_require__","definition","key","Object","obj","prop","Symbol","RemoteBrowser","BaseBrowser","options","_this_options","browserWSEndpoint","_this_options1","cdpEndpoint","response","fetch","webSocketDebuggerUrl","puppeteerConnectOptions","puppeteer","error"],"mappings":";;;;;;;IAAAA,oBAAoB,CAAC,GAAG,CAAC,UAASC;QACjC,IAAI,IAAIC,OAAOD,WACR,IAAGD,oBAAoB,CAAC,CAACC,YAAYC,QAAQ,CAACF,oBAAoB,CAAC,CAAC,UAASE,MACzEC,OAAO,cAAc,CAAC,UAASD,KAAK;YAAE,YAAY;YAAM,KAAKD,UAAU,CAACC,IAAI;QAAC;IAGzF;;;ICNAF,oBAAoB,CAAC,GAAG,CAACI,KAAKC,OAAUF,OAAO,SAAS,CAAC,cAAc,CAAC,IAAI,CAACC,KAAKC;;;ICClFL,oBAAoB,CAAC,GAAG,CAAC;QACxB,IAAG,AAAkB,eAAlB,OAAOM,UAA0BA,OAAO,WAAW,EACrDH,OAAO,cAAc,CAAC,UAASG,OAAO,WAAW,EAAE;YAAE,OAAO;QAAS;QAEtEH,OAAO,cAAc,CAAC,UAAS,cAAc;YAAE,OAAO;QAAK;IAC5D;;;;;;;;;ACHC;;;;;;;;;;AAmCM,MAAMI,sBAAsBC,yCAAAA,WAAWA;IAgB5C,MAAM,OAAOC,OAAuB,EAAiB;YAG3BC;QAFxB,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,2BAA2BD;QAE5C,IAAIE,oBAAoB,QAAAD,CAAAA,gBAAAA,IAAI,CAAC,OAAO,AAAD,IAAXA,KAAAA,IAAAA,cAAc,UAAU;QAEhD,IAAI,CAACC,mBAAmB;gBAEpBC;YADF,MAAMC,cACJD,AAAAA,SAAAA,CAAAA,iBAAAA,IAAI,CAAC,OAAO,AAAD,IAAXA,KAAAA,IAAAA,eAAc,WAAW,AAAD,KAAK;YAC/B,MAAME,WAAW,MAAMC,MAAMF;YAC7B,MAAM,EAAEG,oBAAoB,EAAE,GAAG,MAAMF,SAAS,IAAI;YACpDH,oBAAoBK;QACtB;QAEA,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,6BAA6BL;QAE9C,MAAMM,0BAAoD;YACxDN;YACA,iBAAiBF,AAAAA,CAAAA,QAAAA,UAAAA,KAAAA,IAAAA,QAAS,eAAe,AAAD,KAAK;gBAAE,OAAO;gBAAM,QAAQ;YAAI;QAC1E;QAEA,IAAI;YACF,IAAI,CAAC,OAAO,GAAG,MAAMS,wCAAAA,OAAiB,CAACD;YACvC,MAAM,IAAI,CAAC,iBAAiB;YAC5B,IAAI,CAAC,MAAM,CAAC,OAAO,CAAC;QACtB,EAAE,OAAOE,OAAO;YACd,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,wCAAwCA;YAC1D,MAAMA;QACR;IACF;IAEA,MAAM,oBAAoB;QACxB,KAAK,CAAC;IACR;IA3CA,YAAoBV,OAA8B,CAAE;QAClD,KAAK,CAACA,UAAAA,iBAAAA,IAAAA,EAAAA,WAAAA,KAAAA,IAAAA,IAAAA,CADYA,OAAO,GAAPA;IAEpB;AA0CF"}
|
package/dist/remote-browser.mjs
DELETED
|
@@ -1,55 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Copyright (c) 2025 Bytedance, Inc. and its affiliates.
|
|
3
|
-
* SPDX-License-Identifier: Apache-2.0
|
|
4
|
-
*/
|
|
5
|
-
import { connect } from "puppeteer-core";
|
|
6
|
-
import { BaseBrowser } 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 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.wsEndpoint;
|
|
22
|
-
if (!browserWSEndpoint) {
|
|
23
|
-
var _this_options1;
|
|
24
|
-
const cdpEndpoint = (null == (_this_options1 = this.options) ? void 0 : _this_options1.cdpEndpoint) || "http://127.0.0.1:9222/json/version";
|
|
25
|
-
const response = await fetch(cdpEndpoint);
|
|
26
|
-
const { webSocketDebuggerUrl } = await response.json();
|
|
27
|
-
browserWSEndpoint = webSocketDebuggerUrl;
|
|
28
|
-
}
|
|
29
|
-
this.logger.info('Using WebSocket endpoint:', browserWSEndpoint);
|
|
30
|
-
const puppeteerConnectOptions = {
|
|
31
|
-
browserWSEndpoint,
|
|
32
|
-
defaultViewport: (null == options ? void 0 : options.defaultViewport) ?? {
|
|
33
|
-
width: 1280,
|
|
34
|
-
height: 800
|
|
35
|
-
}
|
|
36
|
-
};
|
|
37
|
-
try {
|
|
38
|
-
this.browser = await connect(puppeteerConnectOptions);
|
|
39
|
-
await this.setupPageListener();
|
|
40
|
-
this.logger.success('Connected to remote browser successfully');
|
|
41
|
-
} catch (error) {
|
|
42
|
-
this.logger.error('Failed to connect to remote browser:', error);
|
|
43
|
-
throw error;
|
|
44
|
-
}
|
|
45
|
-
}
|
|
46
|
-
async setupPageListener() {
|
|
47
|
-
super.setupPageListener();
|
|
48
|
-
}
|
|
49
|
-
constructor(options){
|
|
50
|
-
super(options), _define_property(this, "options", void 0), this.options = options;
|
|
51
|
-
}
|
|
52
|
-
}
|
|
53
|
-
export { RemoteBrowser };
|
|
54
|
-
|
|
55
|
-
//# sourceMappingURL=remote-browser.mjs.map
|
|
@@ -1 +0,0 @@
|
|
|
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} [cdpEndpoint] - Remote Chrome DevTools Protocol endpoint\n */\nexport interface RemoteBrowserOptions extends BaseBrowserOptions {\n wsEndpoint?: string;\n /** @default http://localhost:9222/json/version */\n cdpEndpoint?: string;\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 cdpEndpoint =\n this.options?.cdpEndpoint || `http://127.0.0.1:9222/json/version`;\n const response = await fetch(cdpEndpoint);\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 async setupPageListener() {\n super.setupPageListener();\n }\n}\n"],"names":["RemoteBrowser","BaseBrowser","options","_this_options","browserWSEndpoint","_this_options1","cdpEndpoint","response","fetch","webSocketDebuggerUrl","puppeteerConnectOptions","puppeteer","error"],"mappings":";;;;;;AAGC;;;;;;;;;;AAmCM,MAAMA,sBAAsBC;IAgBjC,MAAM,OAAOC,OAAuB,EAAiB;YAG3BC;QAFxB,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,2BAA2BD;QAE5C,IAAIE,oBAAoB,QAAAD,CAAAA,gBAAAA,IAAI,CAAC,OAAO,AAAD,IAAXA,KAAAA,IAAAA,cAAc,UAAU;QAEhD,IAAI,CAACC,mBAAmB;gBAEpBC;YADF,MAAMC,cACJD,AAAAA,SAAAA,CAAAA,iBAAAA,IAAI,CAAC,OAAO,AAAD,IAAXA,KAAAA,IAAAA,eAAc,WAAW,AAAD,KAAK;YAC/B,MAAME,WAAW,MAAMC,MAAMF;YAC7B,MAAM,EAAEG,oBAAoB,EAAE,GAAG,MAAMF,SAAS,IAAI;YACpDH,oBAAoBK;QACtB;QAEA,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,6BAA6BL;QAE9C,MAAMM,0BAAoD;YACxDN;YACA,iBAAiBF,AAAAA,CAAAA,QAAAA,UAAAA,KAAAA,IAAAA,QAAS,eAAe,AAAD,KAAK;gBAAE,OAAO;gBAAM,QAAQ;YAAI;QAC1E;QAEA,IAAI;YACF,IAAI,CAAC,OAAO,GAAG,MAAMS,QAAkBD;YACvC,MAAM,IAAI,CAAC,iBAAiB;YAC5B,IAAI,CAAC,MAAM,CAAC,OAAO,CAAC;QACtB,EAAE,OAAOE,OAAO;YACd,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,wCAAwCA;YAC1D,MAAMA;QACR;IACF;IAEA,MAAM,oBAAoB;QACxB,KAAK,CAAC;IACR;IA3CA,YAAoBV,OAA8B,CAAE;QAClD,KAAK,CAACA,UAAAA,iBAAAA,IAAAA,EAAAA,WAAAA,KAAAA,IAAAA,IAAAA,CADYA,OAAO,GAAPA;IAEpB;AA0CF"}
|
package/dist/types.d.ts
DELETED
|
@@ -1,158 +0,0 @@
|
|
|
1
|
-
import type { Page, KeyInput, WaitForOptions } from 'puppeteer-core';
|
|
2
|
-
import type { BrowserType } from '@agent-infra/browser-finder';
|
|
3
|
-
/**
|
|
4
|
-
* Options for launching a browser instance
|
|
5
|
-
* @interface LaunchOptions
|
|
6
|
-
*/
|
|
7
|
-
export interface LaunchOptions {
|
|
8
|
-
/**
|
|
9
|
-
* Additional command line arguments to pass to the browser instance.
|
|
10
|
-
*/
|
|
11
|
-
args?: string[];
|
|
12
|
-
/**
|
|
13
|
-
* If true, pipes the browser process stdout and stderr to `process.stdout`
|
|
14
|
-
* and `process.stderr`.
|
|
15
|
-
* @defaultValue `false`
|
|
16
|
-
*/
|
|
17
|
-
dumpio?: boolean;
|
|
18
|
-
/**
|
|
19
|
-
* Whether to run browser in headless mode
|
|
20
|
-
* @default false
|
|
21
|
-
*/
|
|
22
|
-
headless?: boolean;
|
|
23
|
-
/**
|
|
24
|
-
* Browser type, 'chrome' | 'edge' | 'firefox'
|
|
25
|
-
*/
|
|
26
|
-
browserType?: BrowserType;
|
|
27
|
-
/**
|
|
28
|
-
* Maximum time in milliseconds to wait for the browser to start
|
|
29
|
-
* @default 0 (no timeout)
|
|
30
|
-
*/
|
|
31
|
-
timeout?: number;
|
|
32
|
-
/**
|
|
33
|
-
* The viewport dimensions
|
|
34
|
-
* @property {number} width - Viewport width in pixels
|
|
35
|
-
* @property {number} height - Viewport height in pixels
|
|
36
|
-
*/
|
|
37
|
-
defaultViewport?: {
|
|
38
|
-
width: number;
|
|
39
|
-
height: number;
|
|
40
|
-
};
|
|
41
|
-
/**
|
|
42
|
-
* Path to a browser executable to use instead of the automatically detected one
|
|
43
|
-
* If not provided, the system will attempt to find an installed browser
|
|
44
|
-
*/
|
|
45
|
-
executablePath?: string;
|
|
46
|
-
/**
|
|
47
|
-
* Path to a specific browser profile to use
|
|
48
|
-
* Allows using existing browser profiles with cookies, extensions, etc.
|
|
49
|
-
*/
|
|
50
|
-
profilePath?: string;
|
|
51
|
-
/**
|
|
52
|
-
* Proxy server URL, e.g. 'http://proxy.example.com:8080'
|
|
53
|
-
* Used to route browser traffic through a proxy server
|
|
54
|
-
*/
|
|
55
|
-
proxy?: string;
|
|
56
|
-
/**
|
|
57
|
-
* Proxy bypass list, e.g. '*.example.com,*.test.com'
|
|
58
|
-
* Used to bypass the proxy server for specific domains
|
|
59
|
-
*/
|
|
60
|
-
proxyBypassList?: string;
|
|
61
|
-
/**
|
|
62
|
-
* Path to a user data directory.
|
|
63
|
-
* {@link https://chromium.googlesource.com/chromium/src/+/refs/heads/main/docs/user_data_dir.md | see the Chromium docs}
|
|
64
|
-
* for more info.
|
|
65
|
-
*/
|
|
66
|
-
userDataDir?: string;
|
|
67
|
-
}
|
|
68
|
-
/**
|
|
69
|
-
* Options for evaluating JavaScript in a new page
|
|
70
|
-
* @template T - Array of parameters to pass to the page function
|
|
71
|
-
* @template R - Return type of the page function
|
|
72
|
-
* @interface EvaluateOnNewPageOptions
|
|
73
|
-
*/
|
|
74
|
-
export interface EvaluateOnNewPageOptions<T extends any[], R> {
|
|
75
|
-
/**
|
|
76
|
-
* URL to navigate to before evaluating the function
|
|
77
|
-
* The page will load this URL before executing the pageFunction
|
|
78
|
-
*/
|
|
79
|
-
url: string;
|
|
80
|
-
/**
|
|
81
|
-
* Options for waiting for the page to load
|
|
82
|
-
*/
|
|
83
|
-
waitForOptions?: WaitForOptions;
|
|
84
|
-
/**
|
|
85
|
-
* Function to be evaluated in the page context
|
|
86
|
-
* This function runs in the context of the browser page, not Node.js
|
|
87
|
-
* @param {Window} window - The window object of the page
|
|
88
|
-
* @param {...T} args - Additional arguments passed to the function
|
|
89
|
-
* @returns {R} Result of the function execution
|
|
90
|
-
*/
|
|
91
|
-
pageFunction: (window: Window, ...args: T) => R;
|
|
92
|
-
/**
|
|
93
|
-
* Parameters to pass to the page function
|
|
94
|
-
* These values will be serialized and passed to the pageFunction
|
|
95
|
-
*/
|
|
96
|
-
pageFunctionParams: T;
|
|
97
|
-
/**
|
|
98
|
-
* Optional function to execute before page navigation
|
|
99
|
-
* Useful for setting up page configuration before loading the URL
|
|
100
|
-
* @param {Page} page - Puppeteer page instance
|
|
101
|
-
* @returns {void | Promise<void>}
|
|
102
|
-
*/
|
|
103
|
-
beforePageLoad?: (page: Page) => void | Promise<void>;
|
|
104
|
-
/**
|
|
105
|
-
* Optional function to execute after page navigation
|
|
106
|
-
* Useful for setting up page configuration after loading the URL
|
|
107
|
-
* @param {Page} page - Puppeteer page instance
|
|
108
|
-
* @returns {void | Promise<void>}
|
|
109
|
-
*/
|
|
110
|
-
afterPageLoad?: (page: Page) => void | Promise<void>;
|
|
111
|
-
/**
|
|
112
|
-
* Optional function to process the result before returning
|
|
113
|
-
* Can be used to transform or validate the result from page evaluation
|
|
114
|
-
* @param {Page} page - Puppeteer page instance
|
|
115
|
-
* @param {R} result - Result from page function evaluation
|
|
116
|
-
* @returns {R | Promise<R>} Processed result
|
|
117
|
-
*/
|
|
118
|
-
beforeSendResult?: (page: Page, result: R) => R | Promise<R>;
|
|
119
|
-
}
|
|
120
|
-
/**
|
|
121
|
-
* Core browser interface that all browser implementations must implement
|
|
122
|
-
* Defines the standard API for browser automation
|
|
123
|
-
* @interface BrowserInterface
|
|
124
|
-
*/
|
|
125
|
-
export interface BrowserInterface {
|
|
126
|
-
/**
|
|
127
|
-
* Launch a new browser instance
|
|
128
|
-
* @param {LaunchOptions} [options] - Launch configuration options
|
|
129
|
-
* @returns {Promise<void>} Promise resolving when browser is launched
|
|
130
|
-
*/
|
|
131
|
-
launch(options?: LaunchOptions): Promise<void>;
|
|
132
|
-
/**
|
|
133
|
-
* Close the browser instance and all its pages
|
|
134
|
-
* @returns {Promise<void>} Promise resolving when browser is closed
|
|
135
|
-
*/
|
|
136
|
-
close(): Promise<void>;
|
|
137
|
-
/**
|
|
138
|
-
* Create a new page in the browser
|
|
139
|
-
* @returns {Promise<Page>} Promise resolving to the new page instance
|
|
140
|
-
*/
|
|
141
|
-
createPage(): Promise<Page>;
|
|
142
|
-
/**
|
|
143
|
-
* Evaluate a function in a new page context
|
|
144
|
-
* Creates a new page, navigates to URL, executes function, and returns result
|
|
145
|
-
* @template T - Array of parameters to pass to the page function
|
|
146
|
-
* @template R - Return type of the page function
|
|
147
|
-
* @param {EvaluateOnNewPageOptions<T, R>} options - Evaluation options
|
|
148
|
-
* @returns {Promise<R | null>} Promise resolving to the function result or null
|
|
149
|
-
*/
|
|
150
|
-
evaluateOnNewPage<T extends any[], R>(options: EvaluateOnNewPageOptions<T, R>): Promise<R | null>;
|
|
151
|
-
/**
|
|
152
|
-
* Get the currently active page or create one if none exists
|
|
153
|
-
* @returns {Promise<Page>} Promise resolving to the active page instance
|
|
154
|
-
*/
|
|
155
|
-
getActivePage(): Promise<Page>;
|
|
156
|
-
}
|
|
157
|
-
export { Page, KeyInput };
|
|
158
|
-
//# sourceMappingURL=types.d.ts.map
|
package/dist/types.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAE,IAAI,EAAE,QAAQ,EAAE,cAAc,EAAE,MAAM,gBAAgB,CAAC;AACrE,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,6BAA6B,CAAC;AAE/D;;;GAGG;AACH,MAAM,WAAW,aAAa;IAC5B;;OAEG;IACH,IAAI,CAAC,EAAE,MAAM,EAAE,CAAC;IAChB;;;;OAIG;IACH,MAAM,CAAC,EAAE,OAAO,CAAC;IACjB;;;OAGG;IACH,QAAQ,CAAC,EAAE,OAAO,CAAC;IAEnB;;OAEG;IACH,WAAW,CAAC,EAAE,WAAW,CAAC;IAE1B;;;OAGG;IACH,OAAO,CAAC,EAAE,MAAM,CAAC;IAEjB;;;;OAIG;IACH,eAAe,CAAC,EAAE;QAChB,KAAK,EAAE,MAAM,CAAC;QACd,MAAM,EAAE,MAAM,CAAC;KAChB,CAAC;IAEF;;;OAGG;IACH,cAAc,CAAC,EAAE,MAAM,CAAC;IAExB;;;OAGG;IACH,WAAW,CAAC,EAAE,MAAM,CAAC;IAErB;;;OAGG;IACH,KAAK,CAAC,EAAE,MAAM,CAAC;IAEf;;;OAGG;IACH,eAAe,CAAC,EAAE,MAAM,CAAC;IAEzB;;;;OAIG;IACH,WAAW,CAAC,EAAE,MAAM,CAAC;CACtB;AAED;;;;;GAKG;AACH,MAAM,WAAW,wBAAwB,CAAC,CAAC,SAAS,GAAG,EAAE,EAAE,CAAC;IAC1D;;;OAGG;IACH,GAAG,EAAE,MAAM,CAAC;IAEZ;;OAEG;IACH,cAAc,CAAC,EAAE,cAAc,CAAC;IAEhC;;;;;;OAMG;IACH,YAAY,EAAE,CAAC,MAAM,EAAE,MAAM,EAAE,GAAG,IAAI,EAAE,CAAC,KAAK,CAAC,CAAC;IAEhD;;;OAGG;IACH,kBAAkB,EAAE,CAAC,CAAC;IAEtB;;;;;OAKG;IACH,cAAc,CAAC,EAAE,CAAC,IAAI,EAAE,IAAI,KAAK,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IAEtD;;;;;OAKG;IACH,aAAa,CAAC,EAAE,CAAC,IAAI,EAAE,IAAI,KAAK,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IAErD;;;;;;OAMG;IACH,gBAAgB,CAAC,EAAE,CAAC,IAAI,EAAE,IAAI,EAAE,MAAM,EAAE,CAAC,KAAK,CAAC,GAAG,OAAO,CAAC,CAAC,CAAC,CAAC;CAC9D;AAED;;;;GAIG;AACH,MAAM,WAAW,gBAAgB;IAC/B;;;;OAIG;IACH,MAAM,CAAC,OAAO,CAAC,EAAE,aAAa,GAAG,OAAO,CAAC,IAAI,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,QAAQ,EAAE,CAAC"}
|
package/dist/types.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"types.js","sources":["webpack://@agent-infra/browser/webpack/runtime/make_namespace_object"],"sourcesContent":["// define __esModule on exports\n__webpack_require__.r = (exports) => {\n\tif(typeof Symbol !== 'undefined' && Symbol.toStringTag) {\n\t\tObject.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });\n\t}\n\tObject.defineProperty(exports, '__esModule', { value: true });\n};"],"names":["__webpack_require__","Symbol","Object"],"mappings":";;;;;;;IACAA,oBAAoB,CAAC,GAAG,CAAC;QACxB,IAAG,AAAkB,eAAlB,OAAOC,UAA0BA,OAAO,WAAW,EACrDC,OAAO,cAAc,CAAC,UAASD,OAAO,WAAW,EAAE;YAAE,OAAO;QAAS;QAEtEC,OAAO,cAAc,CAAC,UAAS,cAAc;YAAE,OAAO;QAAK;IAC5D"}
|
|
File without changes
|