pagerunner 0.1.1

Browser automation MCP server for AI agents — drives real Chrome with your profiles
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
# Pagerunner Examples

Real-world use cases and code examples for Pagerunner. All examples use the CLI directly; the same commands work through the MCP interface in Claude Code via `/mcp`.

## Table of Contents

1. [Web Scraping]#web-scraping
2. [Form Automation]#form-automation
3. [Content Extraction]#content-extraction
4. [Multi-Step Workflows]#multi-step-workflows
5. [Security Testing]#security-testing
6. [Data Collection]#data-collection
7. [Session Persistence]#session-persistence

---

## Web Scraping

### Example 1: Scrape Product Prices

Fetch product prices from a website with JavaScript rendering:

```bash
#!/bin/bash
# Setup
SESSION_ID=$(pagerunner open-session default | jq -r '.session_id')
TABS=$(pagerunner list-tabs $SESSION_ID | jq -r '.[0].target_id')

# Navigate to product page
pagerunner navigate $SESSION_ID $TABS "https://example.com/products"
pagerunner wait-for $SESSION_ID $TABS --selector ".price-list"

# Extract prices using JavaScript
PRICES=$(pagerunner evaluate $SESSION_ID $TABS '
  Array.from(document.querySelectorAll(".product"))
    .map(el => ({
      name: el.querySelector(".product-name")?.textContent,
      price: parseFloat(el.querySelector(".price")?.textContent || 0),
      url: el.querySelector("a")?.href
    }))
')

echo "$PRICES" | jq '.'

# Cleanup
pagerunner close-session $SESSION_ID
```

**Key Techniques:**
- Return labeled objects (not arrays) to prevent hallucination
- Use `.map()` for consistent structure
- Wait for elements before extracting

### Example 2: Scrape Paginated Content

Handle multi-page scraping with navigation:

```bash
#!/bin/bash
SESSION_ID=$(pagerunner open-session default | jq -r '.session_id')
TARGET_ID=$(pagerunner list-tabs $SESSION_ID | jq -r '.[0].target_id')
pagerunner navigate $SESSION_ID $TARGET_ID "https://example.com/listings?page=1"

RESULTS=()
for PAGE in {1..10}; do
  # Wait for page load
  pagerunner wait-for $SESSION_ID $TARGET_ID --selector ".listing-item"
  
  # Extract current page
  ITEMS=$(pagerunner evaluate $SESSION_ID $TARGET_ID '
    Array.from(document.querySelectorAll(".listing-item"))
      .map(el => ({
        title: el.textContent.trim(),
        url: el.querySelector("a")?.href
      }))
  ')
  RESULTS+=("$ITEMS")
  
  # Go to next page
  NEXT_PAGE=$((PAGE + 1))
  pagerunner navigate $SESSION_ID $TARGET_ID "https://example.com/listings?page=$NEXT_PAGE"
  sleep 1  # Be respectful
done

echo "${RESULTS[@]}" | jq -s 'add'
pagerunner close-session $SESSION_ID
```

---

## Form Automation

### Example 3: Login and Check Account

Automated login with session persistence:

```bash
#!/bin/bash
# Setup
SESSION_ID=$(pagerunner open-session default | jq -r '.session_id')
TARGET_ID=$(pagerunner list-tabs $SESSION_ID | jq -r '.[0].target_id')

# Navigate to login page
pagerunner navigate $SESSION_ID $TARGET_ID "https://app.example.com/login"
pagerunner wait-for $SESSION_ID $TARGET_ID --selector "form"

# Fill login form
pagerunner fill $SESSION_ID $TARGET_ID "[type='email']" "user@example.com"
pagerunner fill $SESSION_ID $TARGET_ID "[type='password']" "password123"
pagerunner click $SESSION_ID $TARGET_ID "button[type='submit']"

# Wait for dashboard
pagerunner wait-for $SESSION_ID $TARGET_ID --url "**/dashboard"

# Extract account info
ACCOUNT=$(pagerunner evaluate $SESSION_ID $TARGET_ID '
  ({
    username: document.querySelector(".username")?.textContent,
    balance: document.querySelector(".balance")?.textContent,
    status: document.querySelector(".status")?.textContent
  })
')

echo "Account Info:" "$ACCOUNT" | jq '.'

# Save session for later use
pagerunner save-snapshot $SESSION_ID $TARGET_ID --origin "https://app.example.com"
pagerunner save-tab-state $SESSION_ID

pagerunner close-session $SESSION_ID
```

### Example 4: Fill Complex Forms with Custom Fields

Handle forms with special input types (React, Vue, etc.):

```bash
#!/bin/bash
SESSION_ID=$(pagerunner open-session default | jq -r '.session_id')
TARGET_ID=$(pagerunner list-tabs $SESSION_ID | jq -r '.[0].target_id')

pagerunner navigate $SESSION_ID $TARGET_ID "https://example.com/signup"

# Basic text inputs
pagerunner fill $SESSION_ID $TARGET_ID "#firstName" "John"
pagerunner fill $SESSION_ID $TARGET_ID "#lastName" "Doe"
pagerunner fill $SESSION_ID $TARGET_ID "#email" "john@example.com"

# Dropdown select
pagerunner select $SESSION_ID $TARGET_ID "#country" "US"

# Radio button (click the input)
pagerunner click $SESSION_ID $TARGET_ID "#plan-pro"

# Checkbox
pagerunner click $SESSION_ID $TARGET_ID "#agree-terms"

# Rich text editor / React input (use fill which triggers synthetic events)
pagerunner fill $SESSION_ID $TARGET_ID "[data-testid='message']" "My message"

# Submit
pagerunner click $SESSION_ID $TARGET_ID "button[type='submit']"

# Wait for success
pagerunner wait-for $SESSION_ID $TARGET_ID --selector ".success-message"

pagerunner close-session $SESSION_ID
```

---

## Content Extraction

### Example 5: Extract Structured Data from Dynamic Page

Use evaluate to extract and structure nested data:

```bash
#!/bin/bash
SESSION_ID=$(pagerunser open-session default | jq -r '.session_id')
TARGET_ID=$(pagerunner list-tabs $SESSION_ID | jq -r '.[0].target_id')

pagerunner navigate $SESSION_ID $TARGET_ID "https://example.com/articles"
pagerunner wait-for $SESSION_ID $TARGET_ID --selector ".article"

# Extract with proper structure
ARTICLES=$(pagerunner evaluate $SESSION_ID $TARGET_ID '
  Array.from(document.querySelectorAll(".article"))
    .map(article => ({
      id: article.getAttribute("data-id"),
      title: article.querySelector("h2")?.textContent.trim(),
      author: article.querySelector(".author")?.textContent.trim(),
      published_date: article.querySelector("[data-date]")?.getAttribute("data-date"),
      excerpt: article.querySelector(".excerpt")?.textContent.trim(),
      tags: Array.from(article.querySelectorAll(".tag")).map(t => t.textContent.trim()),
      link: article.querySelector("a")?.href,
      likes: parseInt(article.querySelector(".like-count")?.textContent || 0),
      comments: parseInt(article.querySelector(".comment-count")?.textContent || 0)
    }))
')

echo "$ARTICLES" | jq '.'

pagerunner close-session $SESSION_ID
```

### Example 6: Get Page Content with Anonymization

Extract content with PII automatically anonymized:

```bash
#!/bin/bash
# Enable anonymization to strip PII before content reaches LLM
SESSION_ID=$(pagerunner open-session default --anonymize | jq -r '.session_id')
TARGET_ID=$(pagerunner list-tabs $SESSION_ID | jq -r '.[0].target_id')

pagerunner navigate $SESSION_ID $TARGET_ID "https://example.com/user-profile"
pagerunner wait-for $SESSION_ID $TARGET_ID --selector ".profile"

# This content will have PII stripped (EMAIL → [EMAIL], PHONE → [PHONE], etc.)
CONTENT=$(pagerunner get-content $SESSION_ID $TARGET_ID)

echo "Content (anonymized):"
echo "$CONTENT"

pagerunner close-session $SESSION_ID
```

---

## Multi-Step Workflows

### Example 7: Complete E-Commerce Purchase Workflow

Full checkout process with error handling:

```bash
#!/bin/bash
set -e

SESSION_ID=$(pagerunner open-session default | jq -r '.session_id')
TARGET_ID=$(pagerunner list-tabs $SESSION_ID | jq -r '.[0].target_id')

echo "Starting checkout workflow..."

# Navigate to store
pagerunner navigate $SESSION_ID $TARGET_ID "https://shop.example.com"
pagerunner wait-for $SESSION_ID $TARGET_ID --selector ".product"

# Add item to cart
pagerunner click $SESSION_ID $TARGET_ID "[data-product-id='12345'] .add-to-cart"
pagerunner wait-for $SESSION_ID $TARGET_ID --ms 1000

# Go to cart
pagerunner click $SESSION_ID $TARGET_ID ".cart-link"
pagerunner wait-for $SESSION_ID $TARGET_ID --selector ".checkout-button"

# Proceed to checkout
pagerunner click $SESSION_ID $TARGET_ID ".checkout-button"
pagerunner wait-for $SESSION_ID $TARGET_ID --selector "form.checkout"

# Fill shipping address
pagerunner fill $SESSION_ID $TARGET_ID "#address" "123 Main St"
pagerunner fill $SESSION_ID $TARGET_ID "#city" "Springfield"
pagerunner select $SESSION_ID $TARGET_ID "#state" "IL"
pagerunner fill $SESSION_ID $TARGET_ID "#zip" "62701"

# Continue to payment
pagerunner click $SESSION_ID $TARGET_ID ".next-step"
pagerunner wait-for $SESSION_ID $TARGET_ID --selector ".payment-form"

# Fill payment info (note: never use real credit cards)
# In production, use anonymization and tokens
pagerunner fill $SESSION_ID $TARGET_ID "#card-number" "4111111111111111"
pagerunner fill $SESSION_ID $TARGET_ID "#expiry" "12/25"
pagerunner fill $SESSION_ID $TARGET_ID "#cvc" "123"

# Agree and submit
pagerunner click $SESSION_ID $TARGET_ID "#agree-terms"
pagerunner click $SESSION_ID $TARGET_ID ".place-order"

# Confirm order
pagerunner wait-for $SESSION_ID $TARGET_ID --url "**/order-confirmation/**"
ORDER_NUM=$(pagerunner evaluate $SESSION_ID $TARGET_ID 'document.querySelector(".order-number")?.textContent')

echo "Order placed: $ORDER_NUM"

# Save confirmation
pagerunner screenshot $SESSION_ID $TARGET_ID --base64 > order_confirmation.json

pagerunner close-session $SESSION_ID
```

### Example 8: Data Migration Between Systems

Fetch data from source, transform, and push to destination:

```bash
#!/bin/bash
SESSION_ID=$(pagerunner open-session default | jq -r '.session_id')
TARGET_ID=$(pagerunner list-tabs $SESSION_ID | jq -r '.[0].target_id')

# Source: Old system
pagerunner navigate $SESSION_ID $TARGET_ID "https://old-system.example.com/export"
pagerunner wait-for $SESSION_ID $TARGET_ID --selector ".data-table"

# Extract data
SOURCE_DATA=$(pagerunner evaluate $SESSION_ID $TARGET_ID '
  Array.from(document.querySelectorAll("tr"))
    .slice(1) // skip header
    .map(row => ({
      id: row.cells[0].textContent.trim(),
      name: row.cells[1].textContent.trim(),
      value: row.cells[2].textContent.trim()
    }))
')

echo "Extracted $($SOURCE_DATA | jq 'length') records"

# Destination: New system
pagerunner navigate $SESSION_ID $TARGET_ID "https://new-system.example.com/import"
pagerunner wait-for $SESSION_ID $TARGET_ID --selector "form"

# Fill import form
pagerunner fill $SESSION_ID $TARGET_ID "#json-input" "$SOURCE_DATA"
pagerunner click $SESSION_ID $TARGET_ID ".import-button"

# Verify import
pagerunner wait-for $SESSION_ID $TARGET_ID --selector ".success-message"
RESULT=$(pagerunner get-content $SESSION_ID $TARGET_ID)

if [[ $RESULT == *"imported"* ]]; then
  echo "✓ Import successful"
else
  echo "✗ Import failed"
fi

pagerunner close-session $SESSION_ID
```

---

## Security Testing

### Example 9: Test Your Site's Anti-Bot Measures

Verify your security controls are working:

```bash
#!/bin/bash
# Use stealth mode to test anti-bot detection
SESSION_ID=$(pagerunner open-session default --stealth | jq -r '.session_id')
TARGET_ID=$(pagerunner list-tabs $SESSION_ID | jq -r '.[0].target_id')

# Navigate normally
pagerunner navigate $SESSION_ID $TARGET_ID "https://mysite.example.com"
pagerunner wait-for $SESSION_ID $TARGET_ID --ms 2000

# Check for anti-bot challenges
BLOCKED=$(pagerunner evaluate $SESSION_ID $TARGET_ID '
  ({
    has_captcha: !!document.querySelector("[data-captcha]"),
    has_challenge: !!document.querySelector(".challenge-modal"),
    detected_webdriver: window.navigator.webdriver,
    detected_automation: !!window.__automation__,
    custom_checks: document.querySelector("[data-automation-detected]")?.textContent
  })
')

echo "Anti-bot Test Results:"
echo "$BLOCKED" | jq '.'

pagerunner close-session $SESSION_ID
```

### Example 10: Validate HTTPS and Security Headers

Check SSL and security configurations:

```bash
#!/bin/bash
SESSION_ID=$(pagerunner open-session default | jq -r '.session_id')
TARGET_ID=$(pagerunner list-tabs $SESSION_ID | jq -r '.[0].target_id')

pagerunner navigate $SESSION_ID $TARGET_ID "https://example.com"

# Check security headers via JavaScript (Network tab unavailable via CDP)
SECURITY=$(pagerunner evaluate $SESSION_ID $TARGET_ID '
  ({
    url: window.location.href,
    protocol: window.location.protocol,
    is_https: window.location.protocol === "https:",
    cert_pinning_header: document.querySelector("link[rel=pin-cert]")?.href,
    // Note: Most security headers are sent in response headers
    // Access via Service Worker or network monitoring (not shown here)
  })
')

echo "$SECURITY" | jq '.'

pagerunner close-session $SESSION_ID
```

---

## Data Collection

### Example 11: Market Research Data Collection

Gather competitive intelligence with proper attribution:

```bash
#!/bin/bash
SESSION_ID=$(pagerunner open-session default | jq -r '.session_id')
TARGET_ID=$(pagerunner list-tabs $SESSION_ID | jq -r '.[0].target_id')

COMPETITORS=("competitor-a.com" "competitor-b.com" "competitor-c.com")
RESULTS=()

for COMPETITOR in "${COMPETITORS[@]}"; do
  echo "Analyzing $COMPETITOR..."
  
  pagerunner navigate $SESSION_ID $TARGET_ID "https://$COMPETITOR/pricing"
  pagerunner wait-for $SESSION_ID $TARGET_ID --selector ".pricing-tier"
  
  PRICING=$(pagerunner evaluate $SESSION_ID $TARGET_ID '
    Array.from(document.querySelectorAll(".pricing-tier"))
      .map(tier => ({
        name: tier.querySelector(".tier-name")?.textContent.trim(),
        price: tier.querySelector(".price")?.textContent.trim(),
        features: Array.from(tier.querySelectorAll(".feature"))
          .map(f => f.textContent.trim())
      }))
  ')
  
  RESULTS+=("{\"competitor\": \"$COMPETITOR\", \"data\": $PRICING}")
done

echo "Market Research Results:"
echo "${RESULTS[@]}" | jq -s 'add'

pagerunner close-session $SESSION_ID
```

---

## Session Persistence

### Example 12: Reuse Sessions Across Multiple Operations

Keep a session open for multiple related operations:

```bash
#!/bin/bash

# Open session once
SESSION_ID=$(pagerunner open-session "work-profile" | jq -r '.session_id')

# Operation 1: Check email
TARGET_ID=$(pagerunner list-tabs $SESSION_ID | jq -r '.[0].target_id')
pagerunner navigate $SESSION_ID $TARGET_ID "https://mail.example.com"
pagerunner wait-for $SESSION_ID $TARGET_ID --selector ".inbox"
EMAIL_COUNT=$(pagerunner evaluate $SESSION_ID $TARGET_ID 'document.querySelectorAll(".email").length')
echo "Inbox: $EMAIL_COUNT emails"

# Operation 2: Check calendar
pagerunner navigate $SESSION_ID $TARGET_ID "https://calendar.example.com"
pagerunner wait-for $SESSION_ID $TARGET_ID --selector ".calendar"
TODAY_EVENTS=$(pagerunner evaluate $SESSION_ID $TARGET_ID '
  Array.from(document.querySelectorAll("[data-date*=today]"))
    .map(e => ({title: e.textContent, time: e.getAttribute("data-time")}))
')
echo "Today events:" "$TODAY_EVENTS" | jq '.'

# Operation 3: Update profile
pagerunner navigate $SESSION_ID $TARGET_ID "https://settings.example.com/profile"
pagerunner fill $SESSION_ID $TARGET_ID "#status" "Available"
pagerunner click $SESSION_ID $TARGET_ID ".save-button"

# Keep the session open for more work
echo "Session $SESSION_ID is ready for more operations"
echo "Use: pagerunner close-session $SESSION_ID"
```

### Example 13: Save and Restore Session State

Persist credentials and state for reuse:

```bash
#!/bin/bash

# First time: login and save state
echo "=== First Run: Login and Save ==="
SESSION_ID=$(pagerunner open-session personal | jq -r '.session_id')
TARGET_ID=$(pagerunner list-tabs $SESSION_ID | jq -r '.[0].target_id')

pagerunner navigate $SESSION_ID $TARGET_ID "https://app.example.com"
pagerunner fill $SESSION_ID $TARGET_ID "[type='email']" "user@example.com"
pagerunner fill $SESSION_ID $TARGET_ID "[type='password']" "password"
pagerunner click $SESSION_ID $TARGET_ID "button[type='submit']"
pagerunner wait-for $SESSION_ID $TARGET_ID --url "**/dashboard"

# Save cookies and storage
pagerunner save-snapshot $SESSION_ID $TARGET_ID --origin "https://app.example.com"
pagerunner save-tab-state $SESSION_ID

echo "Session state saved"
pagerunner close-session $SESSION_ID

# Second time: restore state (no login needed)
echo "=== Second Run: Restore State ==="
SESSION_ID=$(pagerunner open-session personal | jq -r '.session_id')
TARGET_ID=$(pagerunner list-tabs $SESSION_ID | jq -r '.[0].target_id')

pagerunner navigate $SESSION_ID $TARGET_ID "https://app.example.com"
pagerunner restore-snapshot $SESSION_ID $TARGET_ID "https://app.example.com"
pagerunner restore-tab-state $SESSION_ID

# Already logged in!
CONTENT=$(pagerunner get-content $SESSION_ID $TARGET_ID)
echo "Logged in successfully: $CONTENT" | head -20

pagerunner close-session $SESSION_ID
```

---

## Tips & Best Practices

### Use Labeled Objects in `evaluate()`

❌ **Bad** (causes hallucination):
```javascript
// Returns [25, 2] → LLM guesses what these numbers mean
Array.from(divs).map(d => [d.views, d.likes])
```

✅ **Good** (prevents hallucination):
```javascript
// Returns {views: 25, likes: 2} → unambiguous
Array.from(divs).map(d => ({views: d.views, likes: d.likes}))
```

### Always Wait Before Extracting

```bash
pagerunner navigate $SESSION_ID $TARGET_ID "https://example.com"
pagerunner wait-for $SESSION_ID $TARGET_ID --selector ".loaded"  # Wait for rendering
CONTENT=$(pagerunner get-content $SESSION_ID $TARGET_ID)
```

### Handle Network Changes Gracefully

```bash
# Navigate with implicit wait for network idle
pagerunner navigate $SESSION_ID $TARGET_ID "https://example.com"

# If content depends on dynamic loading, wait explicitly
pagerunner wait-for $SESSION_ID $TARGET_ID --selector ".dynamic-content"

# Only then extract
DATA=$(pagerunner evaluate $SESSION_ID $TARGET_ID '...')
```

### Monitor Audit Logs

```bash
# Real-time monitoring during automation
tail -f ~/.pagerunner/audit.log | jq '.[] | {tool: .tool, error: .error}'

# Replay a session
pagerunner audit --session $SESSION_ID
```

### Use Anonymization for Sensitive Data

```bash
# Enable when working with PII
SESSION_ID=$(pagerunner open-session my-profile --anonymize | jq -r '.session_id')

# Content will be auto-anonymized: john@example.com → [EMAIL:a3f9b2]
```

---

**Ready to automate your workflows?** Start with a simple test, then build up to complex multi-step scenarios. Join us on [GitHub](https://github.com/Enreign/pagerunner) for more examples and to share your use cases!