agent-browser 0.3.1 → 0.3.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/bin/agent-browser +13 -2
- package/bin/agent-browser-darwin-arm64 +0 -0
- package/bin/agent-browser-darwin-x64 +0 -0
- package/bin/agent-browser-linux-arm64 +0 -0
- package/bin/agent-browser-linux-x64 +0 -0
- package/package.json +6 -1
- package/.prettierrc +0 -7
- package/AGENTS.md +0 -26
- package/benchmark/benchmark.ts +0 -521
- package/benchmark/run.ts +0 -322
- package/cli/Cargo.lock +0 -114
- package/cli/Cargo.toml +0 -17
- package/cli/src/main.rs +0 -332
- package/docker/Dockerfile.build +0 -31
- package/docker/docker-compose.yml +0 -68
- package/src/actions.ts +0 -1670
- package/src/browser.test.ts +0 -157
- package/src/browser.ts +0 -686
- package/src/cli-light.ts +0 -457
- package/src/client.ts +0 -150
- package/src/daemon.ts +0 -187
- package/src/index.ts +0 -1185
- package/src/protocol.test.ts +0 -216
- package/src/protocol.ts +0 -852
- package/src/snapshot.ts +0 -380
- package/src/types.ts +0 -913
- package/tsconfig.json +0 -28
- package/vitest.config.ts +0 -9
package/src/browser.test.ts
DELETED
|
@@ -1,157 +0,0 @@
|
|
|
1
|
-
import { describe, it, expect, beforeAll, afterAll } from 'vitest';
|
|
2
|
-
import { BrowserManager } from './browser.js';
|
|
3
|
-
|
|
4
|
-
describe('BrowserManager', () => {
|
|
5
|
-
let browser: BrowserManager;
|
|
6
|
-
|
|
7
|
-
beforeAll(async () => {
|
|
8
|
-
browser = new BrowserManager();
|
|
9
|
-
await browser.launch({ headless: true });
|
|
10
|
-
});
|
|
11
|
-
|
|
12
|
-
afterAll(async () => {
|
|
13
|
-
await browser.close();
|
|
14
|
-
});
|
|
15
|
-
|
|
16
|
-
describe('launch and close', () => {
|
|
17
|
-
it('should report as launched', () => {
|
|
18
|
-
expect(browser.isLaunched()).toBe(true);
|
|
19
|
-
});
|
|
20
|
-
|
|
21
|
-
it('should have a page', () => {
|
|
22
|
-
const page = browser.getPage();
|
|
23
|
-
expect(page).toBeDefined();
|
|
24
|
-
});
|
|
25
|
-
});
|
|
26
|
-
|
|
27
|
-
describe('navigation', () => {
|
|
28
|
-
it('should navigate to URL', async () => {
|
|
29
|
-
const page = browser.getPage();
|
|
30
|
-
await page.goto('https://example.com');
|
|
31
|
-
expect(page.url()).toBe('https://example.com/');
|
|
32
|
-
});
|
|
33
|
-
|
|
34
|
-
it('should get page title', async () => {
|
|
35
|
-
const page = browser.getPage();
|
|
36
|
-
const title = await page.title();
|
|
37
|
-
expect(title).toBe('Example Domain');
|
|
38
|
-
});
|
|
39
|
-
});
|
|
40
|
-
|
|
41
|
-
describe('element interaction', () => {
|
|
42
|
-
it('should find element by selector', async () => {
|
|
43
|
-
const page = browser.getPage();
|
|
44
|
-
const heading = await page.locator('h1').textContent();
|
|
45
|
-
expect(heading).toBe('Example Domain');
|
|
46
|
-
});
|
|
47
|
-
|
|
48
|
-
it('should check element visibility', async () => {
|
|
49
|
-
const page = browser.getPage();
|
|
50
|
-
const isVisible = await page.locator('h1').isVisible();
|
|
51
|
-
expect(isVisible).toBe(true);
|
|
52
|
-
});
|
|
53
|
-
|
|
54
|
-
it('should count elements', async () => {
|
|
55
|
-
const page = browser.getPage();
|
|
56
|
-
const count = await page.locator('p').count();
|
|
57
|
-
expect(count).toBeGreaterThan(0);
|
|
58
|
-
});
|
|
59
|
-
});
|
|
60
|
-
|
|
61
|
-
describe('screenshots', () => {
|
|
62
|
-
it('should take screenshot as buffer', async () => {
|
|
63
|
-
const page = browser.getPage();
|
|
64
|
-
const buffer = await page.screenshot();
|
|
65
|
-
expect(buffer).toBeInstanceOf(Buffer);
|
|
66
|
-
expect(buffer.length).toBeGreaterThan(0);
|
|
67
|
-
});
|
|
68
|
-
});
|
|
69
|
-
|
|
70
|
-
describe('evaluate', () => {
|
|
71
|
-
it('should evaluate JavaScript', async () => {
|
|
72
|
-
const page = browser.getPage();
|
|
73
|
-
const result = await page.evaluate(() => document.title);
|
|
74
|
-
expect(result).toBe('Example Domain');
|
|
75
|
-
});
|
|
76
|
-
|
|
77
|
-
it('should evaluate with arguments', async () => {
|
|
78
|
-
const page = browser.getPage();
|
|
79
|
-
const result = await page.evaluate((x: number) => x * 2, 5);
|
|
80
|
-
expect(result).toBe(10);
|
|
81
|
-
});
|
|
82
|
-
});
|
|
83
|
-
|
|
84
|
-
describe('tabs', () => {
|
|
85
|
-
it('should create new tab', async () => {
|
|
86
|
-
const result = await browser.newTab();
|
|
87
|
-
expect(result.index).toBe(1);
|
|
88
|
-
expect(result.total).toBe(2);
|
|
89
|
-
});
|
|
90
|
-
|
|
91
|
-
it('should list tabs', async () => {
|
|
92
|
-
const tabs = await browser.listTabs();
|
|
93
|
-
expect(tabs.length).toBe(2);
|
|
94
|
-
});
|
|
95
|
-
|
|
96
|
-
it('should close tab', async () => {
|
|
97
|
-
// Switch to second tab and close it
|
|
98
|
-
const page = browser.getPage();
|
|
99
|
-
const tabs = await browser.listTabs();
|
|
100
|
-
if (tabs.length > 1) {
|
|
101
|
-
const result = await browser.closeTab(1);
|
|
102
|
-
expect(result.remaining).toBe(1);
|
|
103
|
-
}
|
|
104
|
-
});
|
|
105
|
-
});
|
|
106
|
-
|
|
107
|
-
describe('context operations', () => {
|
|
108
|
-
it('should get cookies from context', async () => {
|
|
109
|
-
const page = browser.getPage();
|
|
110
|
-
const cookies = await page.context().cookies();
|
|
111
|
-
expect(Array.isArray(cookies)).toBe(true);
|
|
112
|
-
});
|
|
113
|
-
|
|
114
|
-
it('should set and get cookies', async () => {
|
|
115
|
-
const page = browser.getPage();
|
|
116
|
-
const context = page.context();
|
|
117
|
-
await context.addCookies([{ name: 'test', value: 'value', url: 'https://example.com' }]);
|
|
118
|
-
const cookies = await context.cookies();
|
|
119
|
-
const testCookie = cookies.find((c) => c.name === 'test');
|
|
120
|
-
expect(testCookie?.value).toBe('value');
|
|
121
|
-
});
|
|
122
|
-
|
|
123
|
-
it('should clear cookies', async () => {
|
|
124
|
-
const page = browser.getPage();
|
|
125
|
-
const context = page.context();
|
|
126
|
-
await context.clearCookies();
|
|
127
|
-
const cookies = await context.cookies();
|
|
128
|
-
expect(cookies.length).toBe(0);
|
|
129
|
-
});
|
|
130
|
-
});
|
|
131
|
-
|
|
132
|
-
describe('storage via evaluate', () => {
|
|
133
|
-
it('should set and get localStorage', async () => {
|
|
134
|
-
const page = browser.getPage();
|
|
135
|
-
await page.evaluate(() => localStorage.setItem('testKey', 'testValue'));
|
|
136
|
-
const value = await page.evaluate(() => localStorage.getItem('testKey'));
|
|
137
|
-
expect(value).toBe('testValue');
|
|
138
|
-
});
|
|
139
|
-
|
|
140
|
-
it('should clear localStorage', async () => {
|
|
141
|
-
const page = browser.getPage();
|
|
142
|
-
await page.evaluate(() => localStorage.clear());
|
|
143
|
-
const value = await page.evaluate(() => localStorage.getItem('testKey'));
|
|
144
|
-
expect(value).toBeNull();
|
|
145
|
-
});
|
|
146
|
-
});
|
|
147
|
-
|
|
148
|
-
describe('viewport', () => {
|
|
149
|
-
it('should set viewport', async () => {
|
|
150
|
-
await browser.setViewport(1920, 1080);
|
|
151
|
-
const page = browser.getPage();
|
|
152
|
-
const size = page.viewportSize();
|
|
153
|
-
expect(size?.width).toBe(1920);
|
|
154
|
-
expect(size?.height).toBe(1080);
|
|
155
|
-
});
|
|
156
|
-
});
|
|
157
|
-
});
|