@eko-ai/eko-nodejs 4.0.9-alpha.1 → 4.1.0
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/browser.d.ts +25 -8
- package/dist/browser.d.ts.map +1 -1
- package/dist/{index.cjs.js → index.cjs} +85 -45
- package/dist/index.cjs.map +1 -0
- package/dist/index.esm.js +79 -43
- package/dist/index.esm.js.map +1 -1
- package/package.json +8 -7
- package/dist/index.cjs.js.map +0 -1
package/dist/index.esm.js
CHANGED
|
@@ -2408,6 +2408,7 @@ function requirePuppeteerExtraPluginStealth () {
|
|
|
2408
2408
|
var puppeteerExtraPluginStealthExports = requirePuppeteerExtraPluginStealth();
|
|
2409
2409
|
var StealthPlugin = /*@__PURE__*/getDefaultExportFromCjs(puppeteerExtraPluginStealthExports);
|
|
2410
2410
|
|
|
2411
|
+
var tabId = 1000;
|
|
2411
2412
|
class BrowserAgent extends BaseBrowserLabelsAgent {
|
|
2412
2413
|
constructor() {
|
|
2413
2414
|
super(...arguments);
|
|
@@ -2415,6 +2416,8 @@ class BrowserAgent extends BaseBrowserLabelsAgent {
|
|
|
2415
2416
|
this.browser_context = null;
|
|
2416
2417
|
this.current_page = null;
|
|
2417
2418
|
this.headless = false;
|
|
2419
|
+
this.pageMap = new Map();
|
|
2420
|
+
this.activePage = null;
|
|
2418
2421
|
}
|
|
2419
2422
|
setHeadless(headless) {
|
|
2420
2423
|
this.headless = headless;
|
|
@@ -2436,12 +2439,12 @@ class BrowserAgent extends BaseBrowserLabelsAgent {
|
|
|
2436
2439
|
const page = await this.currentPage();
|
|
2437
2440
|
const screenshotBuffer = await page.screenshot({
|
|
2438
2441
|
fullPage: false,
|
|
2439
|
-
type:
|
|
2442
|
+
type: 'jpeg',
|
|
2440
2443
|
quality: 60,
|
|
2441
2444
|
});
|
|
2442
|
-
const base64 = screenshotBuffer.toString(
|
|
2445
|
+
const base64 = screenshotBuffer.toString('base64');
|
|
2443
2446
|
return {
|
|
2444
|
-
imageType:
|
|
2447
|
+
imageType: 'image/jpeg',
|
|
2445
2448
|
imageBase64: base64,
|
|
2446
2449
|
};
|
|
2447
2450
|
}
|
|
@@ -2453,45 +2456,67 @@ class BrowserAgent extends BaseBrowserLabelsAgent {
|
|
|
2453
2456
|
title: await page.title(),
|
|
2454
2457
|
};
|
|
2455
2458
|
}
|
|
2459
|
+
async loadTabs() {
|
|
2460
|
+
return await this.get_all_tabs(undefined);
|
|
2461
|
+
}
|
|
2462
|
+
getPageMap() {
|
|
2463
|
+
return this.pageMap;
|
|
2464
|
+
}
|
|
2456
2465
|
async get_all_tabs(agentContext) {
|
|
2457
2466
|
if (!this.browser_context) {
|
|
2458
2467
|
return [];
|
|
2459
2468
|
}
|
|
2460
2469
|
const result = [];
|
|
2461
|
-
const pages =
|
|
2470
|
+
const pages = this.browser_context.pages();
|
|
2462
2471
|
for (let i = 0; i < pages.length; i++) {
|
|
2463
2472
|
let page = pages[i];
|
|
2473
|
+
let pageInfo = this.pageMap.get(page);
|
|
2474
|
+
if (!pageInfo) {
|
|
2475
|
+
pageInfo = {
|
|
2476
|
+
tabId: tabId++,
|
|
2477
|
+
lastAccessed: Date.now(),
|
|
2478
|
+
};
|
|
2479
|
+
this.pageMap.set(page, pageInfo);
|
|
2480
|
+
}
|
|
2464
2481
|
result.push({
|
|
2465
|
-
tabId:
|
|
2482
|
+
tabId: pageInfo.tabId,
|
|
2466
2483
|
url: page.url(),
|
|
2467
2484
|
title: await page.title(),
|
|
2485
|
+
lastAccessed: pageInfo.lastAccessed,
|
|
2486
|
+
active: page === this.activePage,
|
|
2468
2487
|
});
|
|
2469
2488
|
}
|
|
2470
2489
|
return result;
|
|
2471
2490
|
}
|
|
2472
2491
|
async switch_tab(agentContext, tabId) {
|
|
2473
2492
|
if (!this.browser_context) {
|
|
2474
|
-
throw new Error(
|
|
2493
|
+
throw new Error('tabId does not exist: ' + tabId);
|
|
2475
2494
|
}
|
|
2476
|
-
|
|
2477
|
-
|
|
2478
|
-
|
|
2479
|
-
|
|
2495
|
+
let switchPage = null;
|
|
2496
|
+
this.pageMap.forEach((pageInfo, page) => {
|
|
2497
|
+
if (pageInfo.tabId === tabId) {
|
|
2498
|
+
switchPage = page;
|
|
2499
|
+
return;
|
|
2500
|
+
}
|
|
2501
|
+
});
|
|
2502
|
+
if (!switchPage) {
|
|
2503
|
+
throw new Error('tabId does not exist: ' + tabId);
|
|
2480
2504
|
}
|
|
2481
|
-
this.current_page =
|
|
2505
|
+
this.current_page = switchPage;
|
|
2506
|
+
this.activePage = switchPage;
|
|
2482
2507
|
return {
|
|
2483
2508
|
tabId: tabId,
|
|
2484
|
-
url:
|
|
2485
|
-
title: await
|
|
2509
|
+
url: switchPage.url(),
|
|
2510
|
+
title: await switchPage.title(),
|
|
2486
2511
|
};
|
|
2487
2512
|
}
|
|
2488
2513
|
async input_text(agentContext, index, text, enter) {
|
|
2489
2514
|
try {
|
|
2490
2515
|
const elementHandle = await this.get_element(index, true);
|
|
2491
|
-
await elementHandle.fill(
|
|
2516
|
+
await elementHandle.fill('');
|
|
2492
2517
|
await elementHandle.fill(text);
|
|
2493
2518
|
if (enter) {
|
|
2494
|
-
await elementHandle.press(
|
|
2519
|
+
await elementHandle.press('Enter');
|
|
2495
2520
|
await this.sleep(200);
|
|
2496
2521
|
}
|
|
2497
2522
|
}
|
|
@@ -2540,13 +2565,13 @@ class BrowserAgent extends BaseBrowserLabelsAgent {
|
|
|
2540
2565
|
await this.autoLoadCookies(url);
|
|
2541
2566
|
await this.autoLoadLocalStorage(page, url);
|
|
2542
2567
|
await page.goto(url, {
|
|
2543
|
-
waitUntil:
|
|
2568
|
+
waitUntil: 'domcontentloaded',
|
|
2544
2569
|
timeout: 10000,
|
|
2545
2570
|
});
|
|
2546
|
-
await page.waitForLoadState(
|
|
2571
|
+
await page.waitForLoadState('networkidle', { timeout: 5000 });
|
|
2547
2572
|
}
|
|
2548
2573
|
catch (e) {
|
|
2549
|
-
if ((e +
|
|
2574
|
+
if ((e + '').indexOf('Timeout') == -1) {
|
|
2550
2575
|
throw e;
|
|
2551
2576
|
}
|
|
2552
2577
|
}
|
|
@@ -2555,11 +2580,11 @@ class BrowserAgent extends BaseBrowserLabelsAgent {
|
|
|
2555
2580
|
}
|
|
2556
2581
|
async currentPage() {
|
|
2557
2582
|
if (this.current_page == null) {
|
|
2558
|
-
throw new Error(
|
|
2583
|
+
throw new Error('There is no page, please call navigate_to first');
|
|
2559
2584
|
}
|
|
2560
2585
|
const page = this.current_page;
|
|
2561
2586
|
try {
|
|
2562
|
-
await page.waitForLoadState(
|
|
2587
|
+
await page.waitForLoadState('domcontentloaded', { timeout: 10000 });
|
|
2563
2588
|
}
|
|
2564
2589
|
catch (e) { }
|
|
2565
2590
|
return page;
|
|
@@ -2569,12 +2594,12 @@ class BrowserAgent extends BaseBrowserLabelsAgent {
|
|
|
2569
2594
|
return await page.evaluateHandle((params) => {
|
|
2570
2595
|
let element = window.get_highlight_element(params.index);
|
|
2571
2596
|
if (element && params.findInput) {
|
|
2572
|
-
if (element.tagName !=
|
|
2573
|
-
element.tagName !=
|
|
2597
|
+
if (element.tagName != 'INPUT' &&
|
|
2598
|
+
element.tagName != 'TEXTAREA' &&
|
|
2574
2599
|
element.childElementCount != 0) {
|
|
2575
2600
|
element =
|
|
2576
|
-
element.querySelector(
|
|
2577
|
-
element.querySelector(
|
|
2601
|
+
element.querySelector('input') ||
|
|
2602
|
+
element.querySelector('textarea') ||
|
|
2578
2603
|
element;
|
|
2579
2604
|
}
|
|
2580
2605
|
}
|
|
@@ -2598,7 +2623,7 @@ class BrowserAgent extends BaseBrowserLabelsAgent {
|
|
|
2598
2623
|
else if (this.userDataDir) {
|
|
2599
2624
|
this.browser_context = (await chromium.launchPersistentContext(this.userDataDir, {
|
|
2600
2625
|
headless: this.headless,
|
|
2601
|
-
channel:
|
|
2626
|
+
channel: 'chrome',
|
|
2602
2627
|
args: this.getChromiumArgs(),
|
|
2603
2628
|
...this.options,
|
|
2604
2629
|
}));
|
|
@@ -2622,16 +2647,24 @@ class BrowserAgent extends BaseBrowserLabelsAgent {
|
|
|
2622
2647
|
if (init_script.content || init_script.path) {
|
|
2623
2648
|
this.browser_context.addInitScript(init_script);
|
|
2624
2649
|
}
|
|
2625
|
-
this.browser_context.on(
|
|
2626
|
-
|
|
2650
|
+
this.browser_context.on('page', async (page) => {
|
|
2651
|
+
this.activePage = page;
|
|
2652
|
+
this.pageMap.set(page, {
|
|
2653
|
+
tabId: tabId++,
|
|
2654
|
+
lastAccessed: Date.now(),
|
|
2655
|
+
});
|
|
2656
|
+
page.on('framenavigated', async (frame) => {
|
|
2627
2657
|
if (frame === page.mainFrame()) {
|
|
2628
2658
|
const url = frame.url();
|
|
2629
|
-
if (url.startsWith(
|
|
2659
|
+
if (url.startsWith('http')) {
|
|
2630
2660
|
await this.autoLoadCookies(url);
|
|
2631
2661
|
await this.autoLoadLocalStorage(page, url);
|
|
2632
2662
|
}
|
|
2633
2663
|
}
|
|
2634
2664
|
});
|
|
2665
|
+
page.on('close', () => {
|
|
2666
|
+
this.pageMap.delete(page);
|
|
2667
|
+
});
|
|
2635
2668
|
});
|
|
2636
2669
|
}
|
|
2637
2670
|
if (this.cookies) {
|
|
@@ -2648,7 +2681,7 @@ class BrowserAgent extends BaseBrowserLabelsAgent {
|
|
|
2648
2681
|
}
|
|
2649
2682
|
}
|
|
2650
2683
|
catch (e) {
|
|
2651
|
-
Log.error(
|
|
2684
|
+
Log.error('Failed to auto load cookies: ' + url, e);
|
|
2652
2685
|
}
|
|
2653
2686
|
}
|
|
2654
2687
|
async autoLoadLocalStorage(page, url) {
|
|
@@ -2661,12 +2694,12 @@ class BrowserAgent extends BaseBrowserLabelsAgent {
|
|
|
2661
2694
|
}
|
|
2662
2695
|
}
|
|
2663
2696
|
catch (e) {
|
|
2664
|
-
Log.error(
|
|
2697
|
+
Log.error('Failed to inject localStorage: ' + url, e);
|
|
2665
2698
|
}
|
|
2666
2699
|
}, localStorageData);
|
|
2667
2700
|
}
|
|
2668
2701
|
catch (e) {
|
|
2669
|
-
Log.error(
|
|
2702
|
+
Log.error('Failed to auto load localStorage: ' + url, e);
|
|
2670
2703
|
}
|
|
2671
2704
|
}
|
|
2672
2705
|
async loadCookiesWithUrl(url) {
|
|
@@ -2677,18 +2710,18 @@ class BrowserAgent extends BaseBrowserLabelsAgent {
|
|
|
2677
2710
|
}
|
|
2678
2711
|
getChromiumArgs() {
|
|
2679
2712
|
return [
|
|
2680
|
-
|
|
2681
|
-
|
|
2682
|
-
|
|
2683
|
-
|
|
2684
|
-
|
|
2685
|
-
|
|
2686
|
-
|
|
2687
|
-
|
|
2688
|
-
|
|
2689
|
-
|
|
2690
|
-
|
|
2691
|
-
|
|
2713
|
+
'--no-sandbox',
|
|
2714
|
+
'--remote-allow-origins=*',
|
|
2715
|
+
'--disable-dev-shm-usage',
|
|
2716
|
+
'--disable-popup-blocking',
|
|
2717
|
+
'--ignore-ssl-errors',
|
|
2718
|
+
'--ignore-certificate-errors',
|
|
2719
|
+
'--ignore-certificate-errors-spki-list',
|
|
2720
|
+
'--disable-blink-features=AutomationControlled',
|
|
2721
|
+
'--disable-infobars',
|
|
2722
|
+
'--disable-notifications',
|
|
2723
|
+
'--disable-web-security',
|
|
2724
|
+
'--disable-features=IsolateOrigins,site-per-process',
|
|
2692
2725
|
];
|
|
2693
2726
|
}
|
|
2694
2727
|
getUserAgent() {
|
|
@@ -2704,6 +2737,9 @@ class BrowserAgent extends BaseBrowserLabelsAgent {
|
|
|
2704
2737
|
async initScript() {
|
|
2705
2738
|
return {};
|
|
2706
2739
|
}
|
|
2740
|
+
async getActivePage() {
|
|
2741
|
+
return this.activePage;
|
|
2742
|
+
}
|
|
2707
2743
|
}
|
|
2708
2744
|
|
|
2709
2745
|
class SimpleStdioMcpClient {
|