diff --git a/.gitignore b/.gitignore index 8a090a7..d435a7f 100644 --- a/.gitignore +++ b/.gitignore @@ -2,3 +2,5 @@ /public/ /dist/ /screenshots/ +coverage/ +screenshots/ diff --git a/coverage/browser.ts.html b/coverage/browser.ts.html index dd2f915..115b455 100644 --- a/coverage/browser.ts.html +++ b/coverage/browser.ts.html @@ -23,30 +23,30 @@
| 1 2 @@ -270,13 +270,13 @@ -6x -6x -6x +7x +7x +7x -6x +7x @@ -284,43 +284,43 @@ - - - - - - - - - - - 1x - - - - +1x -12x + +1x + + + +2x +1x +1x +1x +1x + + + + +44x 12x - +32x -1x -1x - +9x +9x +8x -1x -1x - - +3x +3x +2x +2x @@ -329,8 +329,8 @@ -1x -1x +4x +4x @@ -346,111 +346,67 @@ -1x -1x -1x - +4x +4x +4x +3x -1x +4x +4x + + + +4x +4x +3x + + + +2x +2x 1x -1x -1x - - - - -1x -1x - - - - -1x -1x - - - - -1x -1x - - - - -1x +2x +2x 1x -1x +3x +3x +2x + + + +3x +3x + + + +3x 1x - +2x -1x -1x +5x +5x -14x -14x +28x +28x -1x - +4x +3x -1x - - - -1x - - - -1x - - - -1x - - - -1x - - - -1x - - - -1x - - - -1x - - - -1x - - - -1x - - - -1x - - - -1x +2x 1x @@ -458,6 +414,50 @@ +2x +1x + + +2x +1x + + +2x +1x + + +2x +1x + + +2x +1x + + +2x +1x + + +2x +1x + + +2x +1x + + +2x +1x + + +1x +1x + + +2x +1x + + @@ -485,44 +485,44 @@ export class ClaudeBrowser { }; } - async launch(): Promise<void> { - this.browser = await webkit.launch({ headless: this.options.headless }); - this.context = await this.browser.newContext({ + async launch(): Promise<void> { + this.browser = await webkit.launch({ headless: this.options.headless }); + this.context = await this.browser.newContext({ viewport: { width: this.options.width, height: this.options.height, }, }); - this.page = await this.context.newPage(); + this.page = await this.context.newPage(); } async close(): Promise<void> { - Iif (this.browser) { - await this.browser.close(); - this.browser = null; - this.context = null; - this.page = null; + if (this.browser) { + await this.browser.close(); + this.browser = null; + this.context = null; + this.page = null; } } private ensurePage(): Page { - Eif (!this.page) { + if (!this.page) { throw new Error('Browser not launched. Call launch() first.'); } - return this.page; + return this.page; } async goto(url: string): Promise<{ url: string; title: string }> { const page = this.ensurePage(); await page.goto(url, { waitUntil: 'networkidle' }); - return { url: page.url(), title: await page.title() }; + return { url: page.url(), title: await page.title() }; } async click(selector: string): Promise<{ url: string }> { const page = this.ensurePage(); await page.click(selector); - await page.waitForLoadState('networkidle').catch(() => {}); - return { url: page.url() }; + await page.waitForLoadState('networkidle').catch(() => {}); + return { url: page.url() }; } async type(selector: string, text: string): Promise<void> { @@ -551,7 +551,7 @@ export class ClaudeBrowser { const page = this.ensurePage(); const resolvedPath = resolve(path || 'screenshot.png'); const buffer = await page.screenshot({ path: resolvedPath, fullPage }); - return { path: resolvedPath, buffer }; + return { path: resolvedPath, buffer }; } async getUrl(): Promise<{ url: string; title: string }> { @@ -562,25 +562,25 @@ export class ClaudeBrowser { async getHtml(full = false): Promise<string> { const page = this.ensurePage(); const html = await page.content(); - return full ? html : html.slice(0, 10000); + return full ? html : html.slice(0, 10000); } async back(): Promise<{ url: string }> { const page = this.ensurePage(); await page.goBack(); - return { url: page.url() }; + return { url: page.url() }; } async forward(): Promise<{ url: string }> { const page = this.ensurePage(); await page.goForward(); - return { url: page.url() }; + return { url: page.url() }; } async reload(): Promise<{ url: string }> { const page = this.ensurePage(); await page.reload(); - return { url: page.url() }; + return { url: page.url() }; } async wait(ms = 1000): Promise<void> { @@ -589,10 +589,10 @@ export class ClaudeBrowser { } async newPage(): Promise<void> { - Eif (!this.context) { + if (!this.context) { throw new Error('Browser not launched. Call launch() first.'); } - this.page = await this.context.newPage(); + this.page = await this.context.newPage(); } async eval(script: string): Promise<unknown> { @@ -605,11 +605,11 @@ export class ClaudeBrowser { switch (cmd.cmd) { case 'goto': { const result = await this.goto(cmd.url); - return { ok: true, ...result }; + return { ok: true, ...result }; } case 'click': { const result = await this.click(cmd.selector); - return { ok: true, ...result }; + return { ok: true, ...result }; } case 'type': { await this.type(cmd.selector, cmd.text); @@ -617,39 +617,39 @@ export class ClaudeBrowser { } case 'query': { const elements = await this.query(cmd.selector); - return { ok: true, count: elements.length, elements }; + return { ok: true, count: elements.length, elements }; } case 'screenshot': { const result = await this.screenshot(cmd.path, cmd.fullPage); - return { ok: true, path: result.path }; + return { ok: true, path: result.path }; } case 'url': { const result = await this.getUrl(); - return { ok: true, ...result }; + return { ok: true, ...result }; } case 'html': { const html = await this.getHtml(cmd.full); - return { ok: true, html }; + return { ok: true, html }; } case 'back': { const result = await this.back(); - return { ok: true, ...result }; + return { ok: true, ...result }; } case 'forward': { const result = await this.forward(); - return { ok: true, ...result }; + return { ok: true, ...result }; } case 'reload': { const result = await this.reload(); - return { ok: true, ...result }; + return { ok: true, ...result }; } case 'wait': { await this.wait(cmd.ms); - return { ok: true }; + return { ok: true }; } case 'newpage': { await this.newPage(); - return { ok: true }; + return { ok: true }; } case 'close': { await this.close(); @@ -657,7 +657,7 @@ export class ClaudeBrowser { } case 'eval': { const result = await this.eval(cmd.script); - return { ok: true, result }; + return { ok: true, result }; } default: { const _exhaustive: never = cmd; @@ -676,7 +676,7 @@ export class ClaudeBrowser { |