craftdriver 1.0.3 → 1.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.
Files changed (63) hide show
  1. package/CHANGELOG.md +25 -3
  2. package/README.md +80 -160
  3. package/dist/lib/browser.d.ts +22 -0
  4. package/dist/lib/browser.d.ts.map +1 -1
  5. package/dist/lib/browser.js +14 -1
  6. package/dist/lib/browser.js.map +1 -1
  7. package/dist/lib/chrome.d.ts +15 -3
  8. package/dist/lib/chrome.d.ts.map +1 -1
  9. package/dist/lib/chrome.js +4 -2
  10. package/dist/lib/chrome.js.map +1 -1
  11. package/dist/lib/driver.d.ts.map +1 -1
  12. package/dist/lib/driver.js +2 -0
  13. package/dist/lib/driver.js.map +1 -1
  14. package/dist/lib/driverManager.d.ts +31 -0
  15. package/dist/lib/driverManager.d.ts.map +1 -1
  16. package/dist/lib/driverManager.js +165 -31
  17. package/dist/lib/driverManager.js.map +1 -1
  18. package/dist/lib/firefox.d.ts +4 -3
  19. package/dist/lib/firefox.d.ts.map +1 -1
  20. package/dist/lib/firefox.js.map +1 -1
  21. package/dist/lib/http.d.ts +1 -1
  22. package/dist/lib/http.d.ts.map +1 -1
  23. package/dist/lib/http.js +35 -7
  24. package/dist/lib/http.js.map +1 -1
  25. package/dist/lib/timing.d.ts +13 -0
  26. package/dist/lib/timing.d.ts.map +1 -1
  27. package/dist/lib/timing.js +13 -0
  28. package/dist/lib/timing.js.map +1 -1
  29. package/dist/lib/types.d.ts +2 -0
  30. package/dist/lib/types.d.ts.map +1 -1
  31. package/docs/agents.md +92 -0
  32. package/docs/api-reference.md +108 -46
  33. package/docs/browser-api.md +2 -1
  34. package/docs/browser-context.md +4 -7
  35. package/docs/browser-logs.md +158 -0
  36. package/docs/cli.md +26 -26
  37. package/docs/driver-configuration.md +103 -4
  38. package/docs/element-api.md +37 -6
  39. package/docs/emulation.md +6 -2
  40. package/docs/index.md +64 -0
  41. package/docs/keyboard-mouse.md +28 -10
  42. package/docs/mobile-emulation.md +5 -2
  43. package/docs/network.md +203 -0
  44. package/docs/public/craftdriver-mark.svg +15 -0
  45. package/docs/public/social-card.svg +27 -0
  46. package/docs/recipes/accessibility-gate.md +53 -0
  47. package/docs/recipes/console-error-gate.md +57 -0
  48. package/docs/recipes/file-upload-download.md +58 -0
  49. package/docs/recipes/login-once-reuse-session.md +73 -0
  50. package/docs/recipes/mobile-flow-with-network-and-logs.md +57 -0
  51. package/docs/recipes/mock-api-and-assert-network.md +60 -0
  52. package/docs/recipes/multi-user-contexts.md +58 -0
  53. package/docs/recipes/trace-failing-test.md +64 -0
  54. package/docs/recipes/virtual-clock-time-sensitive-ui.md +60 -0
  55. package/docs/recipes/vitest-browser-lifecycle.md +56 -0
  56. package/docs/recipes.md +33 -0
  57. package/docs/selectors.md +22 -1
  58. package/docs/session-management.md +18 -1
  59. package/docs/standards.md +40 -0
  60. package/docs/why-craftdriver.md +28 -0
  61. package/docs/zero-config-drivers.md +64 -0
  62. package/package.json +19 -5
  63. package/docs/bidi-features.md +0 -470
@@ -1,11 +1,14 @@
1
1
  # Session Management
2
2
 
3
- Craftdriver supports Playwright-style session persistence, allowing you to save and restore browser state including cookies and localStorage. This is perfect for:
3
+ CraftDriver supports Playwright-style session persistence, allowing you to save and restore browser state including cookies and localStorage. This is perfect for:
4
4
 
5
5
  - **Skipping login in tests** - Log in once, reuse session across test runs
6
6
  - **Sharing auth state** - Generate auth state in setup, use in parallel tests
7
7
  - **Debugging** - Capture session state at any point
8
8
 
9
+ Session management is the user-facing feature. Under the hood, CraftDriver uses
10
+ the best available WebDriver transport for the browser you launched.
11
+
9
12
  ## Saving Session State
10
13
 
11
14
  ```typescript
@@ -51,6 +54,15 @@ The saved file contains:
51
54
  await browser.loadState('./session.json');
52
55
  ```
53
56
 
57
+ ## Working With State Objects
58
+
59
+ Use the state object directly when you do not want to write a file:
60
+
61
+ ```typescript
62
+ const state = await browser.storage.getState();
63
+ await browser.storage.setState(state);
64
+ ```
65
+
54
66
  ## Launching with Pre-loaded State
55
67
 
56
68
  The most common pattern - launch a browser with existing session:
@@ -89,6 +101,11 @@ const cookies = await browser.storage.getCookies();
89
101
  // Get cookies for specific domain
90
102
  const domainCookies = await browser.storage.getCookies({ domain: 'example.com' });
91
103
 
104
+ // Set multiple cookies
105
+ await browser.storage.setCookies([
106
+ { name: 'theme', value: 'dark', domain: 'example.com', path: '/' },
107
+ ]);
108
+
92
109
  // Clear all cookies
93
110
  await browser.storage.clearCookies();
94
111
 
@@ -0,0 +1,40 @@
1
+ # WebDriver Standards
2
+
3
+ CraftDriver is built on W3C WebDriver protocols:
4
+
5
+ - **WebDriver Classic** for broadly supported browser automation commands
6
+ - **WebDriver BiDi** for modern bidirectional browser capabilities
7
+
8
+ That protocol choice is the center of the project. CraftDriver tries to provide a modern developer experience without making browser-private protocols the foundation of user code.
9
+
10
+ ## Classic And BiDi Together
11
+
12
+ | Protocol | Used for |
13
+ | ----------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------- |
14
+ | WebDriver Classic | Stable navigation, element actions, browser sessions, window operations, and widely supported commands. |
15
+ | WebDriver BiDi | Network interception, console and page errors, screenshots, storage, contexts, init scripts, downloads, tracing, and other event-driven capabilities. |
16
+
17
+ CraftDriver picks the practical protocol path behind a single public API. You call `browser.click()`, `browser.navigateTo()`, `browser.network.mock()`, or `browser.startTrace()`; the library handles the transport details.
18
+
19
+ ## Why It Matters
20
+
21
+ Standards-based automation gives projects a few useful properties:
22
+
23
+ - browser behavior can converge across engines instead of depending on a single vendor protocol
24
+ - Firefox support is a first-class target, not an afterthought
25
+ - protocol errors can be mapped into stable CraftDriver error codes
26
+ - browser control can be exposed safely to CLIs and MCP tools
27
+
28
+ ## Honest Limits
29
+
30
+ WebDriver BiDi is still evolving. Some capabilities are browser-specific today, especially around emulation and mobile behavior. CraftDriver documents those limits instead of silently pretending every browser supports every feature.
31
+
32
+ Use these pages when you need exact capability details:
33
+
34
+ - [Network Mocking And Request Waiting](./network.md)
35
+ - [Console Logs And JavaScript Errors](./browser-logs.md)
36
+ - [Session Management](./session-management.md)
37
+ - [Browser Contexts](./browser-context.md)
38
+ - [Emulation](./emulation.md)
39
+ - [Mobile Emulation](./mobile-emulation.md)
40
+ - [Error Codes](./error-codes.md)
@@ -0,0 +1,28 @@
1
+ # Why CraftDriver?
2
+
3
+ CraftDriver is for writing boringly reliable automation against real browsers, with code that reads nicely.
4
+
5
+ ## What It Cares About
6
+
7
+ - 🍺 **Focused Node.js API** - browser automation without a giant framework around it.
8
+ - 🧭 **Real browsers** - drives installed Chrome, Chromium, and Firefox instead of patched browser engine builds.
9
+ - 🌐 **Standards that age well** - W3C WebDriver standards stay stable while browser-private protocols change.
10
+ - 🚦 **Readable, auto-waited flows** - role, label, text, test id, CSS, XPath, click, fill, and expect.
11
+ - 📡 **Network control** - mock, block, intercept, and wait for browser requests and responses.
12
+ - 🔐 **Reusable sessions** - save cookies and localStorage, then launch already signed in.
13
+ - ⏱️ **Virtual clock** - freeze or fast-forward `Date`, timers, and time-sensitive UI.
14
+ - ♿ **Accessibility audits** - run axe-core checks on pages, elements, and locators.
15
+ - 🧾 **Trace evidence** - capture actions, console output, errors, network events, and screenshots.
16
+ - 🤖 **Agent-friendly** - CLI, MCP, and assistant rules when coding agents need the browser.
17
+
18
+ ## Good Fits
19
+
20
+ - End-to-end tests in Node.js.
21
+ - Browser scripts and diagnostics.
22
+ - Projects that want installed Chrome, Chromium, and Firefox through WebDriver.
23
+ - Tests that need network mocks, saved auth state, virtual time, or accessibility gates.
24
+ - Coding agents that should use the same browser automation primitives as humans.
25
+
26
+ ## Not The Goal
27
+
28
+ CraftDriver is not trying to be a giant testing universe. It is the browser control layer: launch, navigate, click, fill, assert, inspect, debug, and get on with your day.
@@ -0,0 +1,64 @@
1
+ # Zero-Config Drivers
2
+
3
+ CraftDriver is designed so a normal install is enough:
4
+
5
+ ```bash
6
+ npm install craftdriver --save-dev
7
+ ```
8
+
9
+ Then launch an installed browser:
10
+
11
+ ```ts
12
+ import { Browser } from 'craftdriver';
13
+
14
+ const browser = await Browser.launch({ browserName: 'chrome' });
15
+ ```
16
+
17
+ You do not need to add `chromedriver`, `geckodriver`, or browser downloads to most projects. CraftDriver resolves the matching WebDriver binary, starts it on a free port, and caches resolution details so later launches are faster.
18
+
19
+ ## What Happens At Launch?
20
+
21
+ CraftDriver checks for the driver in this order:
22
+
23
+ | Step | Source |
24
+ | ---- | ----------------------------------------------------------------------- |
25
+ | 1 | Explicit `ChromeService` / `FirefoxService` configuration |
26
+ | 2 | Environment variables such as `CHROMEDRIVER_PATH` or `GECKODRIVER_PATH` |
27
+ | 3 | Known CI-provided driver directories (e.g. GitHub Actions' `CHROMEWEBDRIVER` / `GECKOWEBDRIVER`) |
28
+ | 4 | Project-local binaries in `node_modules/.bin` |
29
+ | 5 | Binaries already available on `PATH` |
30
+ | 6 | Auto-resolved and cached driver matching the installed browser |
31
+
32
+ If a browser update leaves a cached driver stale, CraftDriver retries once with a refreshed driver instead of making you clear the cache manually.
33
+
34
+ ## CI Friendly
35
+
36
+ The default setup works well on CI runners that already include Chrome or
37
+ Firefox. On **GitHub Actions** specifically, craftdriver auto-detects the
38
+ runner's own pre-installed, version-matched driver out of the box (via
39
+ `CHROMEWEBDRIVER` / `GECKOWEBDRIVER`) — no configuration needed, and it's
40
+ faster than the fallback probes since it skips version detection entirely (see
41
+ [Driver Configuration → CI platform detection](./driver-configuration.md#ci-platform-detection)).
42
+
43
+ For platforms without built-in detection, or to pin a driver other than the
44
+ runner's default, set the path manually:
45
+
46
+ ```bash
47
+ CRAFTDRIVER_CHROMEDRIVER_PATH=/usr/bin/chromedriver npm test
48
+ CRAFTDRIVER_OFFLINE=1 npm test
49
+ CRAFTDRIVER_CACHE_DIR=/tmp/craftdriver-cache npm test
50
+ ```
51
+
52
+ ## When To Configure Manually
53
+
54
+ Manual configuration is useful when:
55
+
56
+ - your CI image pins a specific browser and driver pair
57
+ - network access is blocked
58
+ - you need custom driver logging
59
+ - you want to avoid any version detection during launch
60
+ - you're launching a non-default Chrome/Chromium/Firefox build via
61
+ `browserPath` / `CRAFTDRIVER_CHROME_PATH` — see
62
+ [Driver Configuration → Browser Binary Configuration](./driver-configuration.md#browser-binary-configuration)
63
+
64
+ See [Driver Configuration](./driver-configuration.md) for the full reference.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "craftdriver",
3
- "version": "1.0.3",
3
+ "version": "1.1.0",
4
4
  "description": "Modern WebDriver automation library for NodeJS",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -24,6 +24,10 @@
24
24
  "examples:start": "npm run serve",
25
25
  "docs:api": "node scripts/gen-api-reference.mjs",
26
26
  "docs:api:check": "node scripts/gen-api-reference.mjs --check",
27
+ "docs:dev": "vitepress dev docs",
28
+ "docs:build": "vitepress build docs",
29
+ "docs:preview": "vitepress preview docs",
30
+ "docs:check": "npm run docs:api:check && npm run docs:build",
27
31
  "prepublishOnly": "npm run build && npm run lint"
28
32
  },
29
33
  "keywords": [
@@ -34,11 +38,16 @@
34
38
  "chromium",
35
39
  "automation",
36
40
  "browser-automation",
41
+ "e2e",
42
+ "e2e-testing",
37
43
  "testing",
38
44
  "selenium",
45
+ "mcp",
39
46
  "cli",
40
47
  "agent",
41
- "ai"
48
+ "ai",
49
+ "ai-agents",
50
+ "web-testing"
42
51
  ],
43
52
  "author": "Dimitar Topuzov",
44
53
  "license": "MIT",
@@ -49,14 +58,15 @@
49
58
  "bugs": {
50
59
  "url": "https://github.com/dtopuzov/craftdriver/issues"
51
60
  },
52
- "homepage": "https://github.com/dtopuzov/craftdriver#readme",
61
+ "homepage": "https://dtopuzov.github.io/craftdriver/",
53
62
  "engines": {
54
63
  "node": ">=18"
55
64
  },
56
65
  "files": [
57
66
  "dist",
58
67
  "bin",
59
- "docs",
68
+ "docs/**/*.md",
69
+ "docs/public",
60
70
  "skills",
61
71
  "README.md",
62
72
  "CHANGELOG.md",
@@ -80,6 +90,7 @@
80
90
  "rimraf": "^6.1.3",
81
91
  "semantic-release": "^25.0.5",
82
92
  "typescript": "^5.0.0",
93
+ "vitepress": "^1.6.4",
83
94
  "vitest": "^4.0.18"
84
95
  },
85
96
  "dependencies": {
@@ -90,6 +101,9 @@
90
101
  "brace-expansion": "5.0.6",
91
102
  "ip-address": "10.1.1",
92
103
  "npm": "^11.18.0",
93
- "undici": "7.28.0"
104
+ "undici": "7.28.0",
105
+ "vitepress": {
106
+ "vite": "6.4.3"
107
+ }
94
108
  }
95
109
  }