Skip to content
5 changes: 4 additions & 1 deletion .claude/settings.local.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
{
"permissions": {
"allow": [
"Bash(find:*)"
"Bash(find:*)",
"Bash(touch:*)",
"Bash(gh pr checks:*)",
"Bash(grep:*)"
],
"deny": []
}
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ jobs:
name: Test
runs-on: ubuntu-latest
container:
image: mcr.microsoft.com/playwright:v1.48.0-noble
image: mcr.microsoft.com/playwright:v1.52.0-noble

strategy:
matrix:
Expand Down
23 changes: 23 additions & 0 deletions internal/client/browser_pool.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"fmt"
"log/slog"
"sync"
"testing"
"time"

"github.com/playwright-community/playwright-go"
Expand Down Expand Up @@ -213,6 +214,12 @@ func (p *BrowserPool) RenderPage(ctx context.Context, targetURL string) (string,
}
defer page.Close()

// Setup debug handlers if running in test mode
var consoleLogs, networkLogs []string
if testing.Testing() {
consoleLogs, networkLogs = SetupPageDebugHandlers(page)
}

// Set timeout
page.SetDefaultTimeout(float64(p.config.Timeout.Milliseconds()))

Expand All @@ -234,12 +241,28 @@ func (p *BrowserPool) RenderPage(ctx context.Context, targetURL string) (string,
Timeout: playwright.Float(float64(p.config.Timeout.Milliseconds())),
})
if err != nil {
// Log debug info when running in test mode
if testing.Testing() && (len(consoleLogs) > 0 || len(networkLogs) > 0) {
p.logger.Error("Navigation failed with debug info",
"url", targetURL,
"error", err,
"console_logs", consoleLogs,
"network_logs", networkLogs)
}
return "", fmt.Errorf("failed to navigate to URL %s: %w", targetURL, err)
}

// Get the final HTML content
content, err := page.Content()
if err != nil {
// Log debug info when running in test mode
if testing.Testing() && (len(consoleLogs) > 0 || len(networkLogs) > 0) {
p.logger.Error("Failed to get content with debug info",
"url", targetURL,
"error", err,
"console_logs", consoleLogs,
"network_logs", networkLogs)
}
return "", fmt.Errorf("failed to get page content: %w", err)
}

Expand Down
21 changes: 8 additions & 13 deletions internal/client/browser_pool_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package client
import (
"context"
"log/slog"
"os"
"testing"
"time"
)
Expand All @@ -23,7 +22,7 @@ func TestNewBrowserPool(t *testing.T) {
Enabled: true,
BrowserType: "chromium",
Headless: true,
Timeout: 30 * time.Second,
Timeout: 60 * time.Second,
}

pool2, err := NewBrowserPool(config, logger)
Expand All @@ -39,7 +38,7 @@ func TestBrowserPool_AcquireContext(t *testing.T) {
Enabled: true,
BrowserType: "chromium",
Headless: true,
Timeout: 30 * time.Second,
Timeout: 60 * time.Second,
}

pool, err := NewBrowserPool(config, logger)
Expand Down Expand Up @@ -79,17 +78,12 @@ func TestBrowserPool_AcquireContext(t *testing.T) {
}

func TestBrowserPool_RenderPage(t *testing.T) {
// Skip this test in CI environment due to missing dependencies
if os.Getenv("CI") == "true" {
t.Skip("Skipping browser test in CI environment")
}

logger := slog.Default()
config := &JSConfig{
Enabled: true,
BrowserType: "chromium",
Headless: true,
Timeout: 30 * time.Second,
Timeout: 60 * time.Second,
}

pool, err := NewBrowserPool(config, logger)
Expand All @@ -102,6 +96,7 @@ func TestBrowserPool_RenderPage(t *testing.T) {
ctx := context.Background()
content, err := pool.RenderPage(ctx, "https://example.com")
if err != nil {
// The browser pool now logs debug info automatically
t.Fatalf("Failed to render page: %v", err)
}

Expand All @@ -121,7 +116,7 @@ func TestBrowserPool_GetPoolStats(t *testing.T) {
Enabled: true,
BrowserType: "chromium",
Headless: true,
Timeout: 30 * time.Second,
Timeout: 60 * time.Second,
WaitFor: "networkidle",
}

Expand Down Expand Up @@ -161,7 +156,7 @@ func TestBrowserPool_ConcurrentAccess(t *testing.T) {
Enabled: true,
BrowserType: "chromium",
Headless: true,
Timeout: 30 * time.Second,
Timeout: 60 * time.Second,
WaitFor: "networkidle",
}

Expand Down Expand Up @@ -208,7 +203,7 @@ func TestBrowserPool_Close(t *testing.T) {
Enabled: true,
BrowserType: "chromium",
Headless: true,
Timeout: 30 * time.Second,
Timeout: 60 * time.Second,
WaitFor: "networkidle",
}

Expand Down Expand Up @@ -242,7 +237,7 @@ func TestBrowserContext_ReleaseContext(t *testing.T) {
Enabled: true,
BrowserType: "chromium",
Headless: true,
Timeout: 30 * time.Second,
Timeout: 60 * time.Second,
WaitFor: "networkidle",
}

Expand Down
21 changes: 5 additions & 16 deletions internal/client/js_client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package client
import (
"context"
"log/slog"
"os"
"testing"
"time"
)
Expand All @@ -23,7 +22,7 @@ func TestNewJSClient(t *testing.T) {
Enabled: true,
BrowserType: "chromium",
Headless: true,
Timeout: 30 * time.Second,
Timeout: 60 * time.Second,
WaitFor: "networkidle",
}

Expand All @@ -35,17 +34,12 @@ func TestNewJSClient(t *testing.T) {
}

func TestJSClient_RenderPage(t *testing.T) {
// Skip this test in CI environment due to missing dependencies
if os.Getenv("CI") == "true" {
t.Skip("Skipping browser test in CI environment")
}

logger := slog.Default()
config := &JSConfig{
Enabled: true,
BrowserType: "chromium",
Headless: true,
Timeout: 30 * time.Second,
Timeout: 60 * time.Second,
WaitFor: "networkidle",
}

Expand Down Expand Up @@ -73,17 +67,12 @@ func TestJSClient_RenderPage(t *testing.T) {
}

func TestJSClient_Get(t *testing.T) {
// Skip this test in CI environment due to missing dependencies
if os.Getenv("CI") == "true" {
t.Skip("Skipping browser test in CI environment")
}

logger := slog.Default()
config := &JSConfig{
Enabled: true,
BrowserType: "chromium",
Headless: true,
Timeout: 30 * time.Second,
Timeout: 60 * time.Second,
WaitFor: "networkidle",
}

Expand Down Expand Up @@ -127,7 +116,7 @@ func TestJSClient_GetPoolStats(t *testing.T) {
Enabled: true,
BrowserType: "chromium",
Headless: true,
Timeout: 30 * time.Second,
Timeout: 60 * time.Second,
WaitFor: "networkidle",
}

Expand Down Expand Up @@ -157,7 +146,7 @@ func TestJSClient_Disabled(t *testing.T) {
Enabled: false,
BrowserType: "chromium",
Headless: true,
Timeout: 30 * time.Second,
Timeout: 60 * time.Second,
}

client, err := NewJSClient(config, logger)
Expand Down
Loading