@eko-ai/eko-nodejs 2.1.6 → 2.1.7-alpha.2

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/dist/index.d.ts CHANGED
@@ -1,3 +1,5 @@
1
+ import { getCdpWsEndpoint } from "./utils";
2
+ export { getCdpWsEndpoint };
1
3
  export { BrowserAgent } from "./browser";
2
4
  export { FileAgent } from "./file";
3
5
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,WAAW,CAAC;AACzC,OAAO,EAAE,SAAS,EAAE,MAAM,QAAQ,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,MAAM,SAAS,CAAC;AAE3C,OAAO,EAAE,gBAAgB,EAAE,CAAC;AAC5B,OAAO,EAAE,YAAY,EAAE,MAAM,WAAW,CAAC;AACzC,OAAO,EAAE,SAAS,EAAE,MAAM,QAAQ,CAAC"}
package/dist/index.esm.js CHANGED
@@ -1,4 +1,4 @@
1
- import { BaseBrowserLabelsAgent, BaseFileAgent } from '@eko-ai/eko';
1
+ import { Log, BaseBrowserLabelsAgent, BaseFileAgent } from '@eko-ai/eko';
2
2
  import { chromium } from 'playwright';
3
3
  import * as fs from 'fs/promises';
4
4
  import * as path$1 from 'path';
@@ -11,6 +11,14 @@ import { EventEmitter } from 'node:events';
11
11
  import Stream from 'node:stream';
12
12
  import { StringDecoder } from 'node:string_decoder';
13
13
 
14
+ async function getCdpWsEndpoint(port) {
15
+ // Example => ws://localhost:9222/devtools/browser/{session-id}
16
+ const response = await fetch(`http://localhost:${port}/json/version`);
17
+ const browserInfo = await response.json();
18
+ Log.info("browserInfo: ", browserInfo);
19
+ return browserInfo.webSocketDebuggerUrl;
20
+ }
21
+
14
22
  class BrowserAgent extends BaseBrowserLabelsAgent {
15
23
  constructor() {
16
24
  super(...arguments);
@@ -22,6 +30,12 @@ class BrowserAgent extends BaseBrowserLabelsAgent {
22
30
  setHeadless(headless) {
23
31
  this.headless = headless;
24
32
  }
33
+ setCdpWsEndpoint(cdpWsEndpoint) {
34
+ this.cdpWsEndpoint = cdpWsEndpoint;
35
+ }
36
+ setOptions(options) {
37
+ this.options = options;
38
+ }
25
39
  async screenshot(agentContext) {
26
40
  let page = await this.currentPage();
27
41
  let screenshotBuffer = await page.screenshot({
@@ -167,17 +181,28 @@ class BrowserAgent extends BaseBrowserLabelsAgent {
167
181
  return new Promise((resolve) => setTimeout(() => resolve(), time));
168
182
  }
169
183
  async getBrowserContext() {
170
- if (!this.browser) {
171
- this.current_page = null;
172
- this.browser_context = null;
173
- this.browser = await chromium.launch({
174
- headless: this.headless,
175
- args: ["--no-sandbox"],
176
- });
177
- }
178
184
  if (!this.browser_context) {
179
185
  this.current_page = null;
180
- this.browser_context = await this.browser.newContext();
186
+ this.browser_context = null;
187
+ if (this.cdpWsEndpoint) {
188
+ this.browser = await chromium.connectOverCDP(this.cdpWsEndpoint, this.options);
189
+ this.browser_context = await this.browser.newContext();
190
+ }
191
+ else if (this.userDataDir) {
192
+ this.browser_context = await chromium.launchPersistentContext(this.userDataDir, {
193
+ headless: this.headless,
194
+ // channel: 'chrome',
195
+ ...this.options,
196
+ });
197
+ }
198
+ else {
199
+ this.browser = await chromium.launch({
200
+ headless: this.headless,
201
+ args: ["--no-sandbox"],
202
+ ...this.options,
203
+ });
204
+ this.browser_context = await this.browser.newContext();
205
+ }
181
206
  // Anti-crawling detection website:
182
207
  // https://bot.sannysoft.com/
183
208
  let init_script = await this.initScript();
@@ -8202,5 +8227,5 @@ class FileAgent extends BaseFileAgent {
8202
8227
  }
8203
8228
  }
8204
8229
 
8205
- export { BrowserAgent, FileAgent };
8230
+ export { BrowserAgent, FileAgent, getCdpWsEndpoint };
8206
8231
  //# sourceMappingURL=index.esm.js.map