patchright-core 1.58.2 → 1.59.1
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/ThirdPartyNotices.txt +126 -650
- package/browsers.json +16 -14
- package/lib/bootstrap.js +77 -0
- package/lib/cli/browserActions.js +308 -0
- package/lib/cli/driver.js +3 -2
- package/lib/cli/installActions.js +171 -0
- package/lib/cli/program.js +47 -411
- package/lib/client/android.js +4 -4
- package/lib/client/api.js +3 -3
- package/lib/client/browser.js +8 -0
- package/lib/client/browserContext.js +22 -61
- package/lib/client/browserType.js +19 -51
- package/lib/client/cdpSession.js +6 -2
- package/lib/client/channelOwner.js +1 -1
- package/lib/client/clientHelper.js +2 -1
- package/lib/client/clock.js +0 -1
- package/lib/client/{webSocket.js → connect.js} +57 -7
- package/lib/client/connection.js +8 -4
- package/lib/client/consoleMessage.js +3 -0
- package/lib/client/debugger.js +57 -0
- package/lib/client/dialog.js +8 -1
- package/lib/client/disposable.js +76 -0
- package/lib/client/electron.js +1 -0
- package/lib/client/elementHandle.js +1 -4
- package/lib/client/events.js +3 -3
- package/lib/client/fetch.js +0 -1
- package/lib/client/frame.js +10 -23
- package/lib/client/harRouter.js +13 -1
- package/lib/client/jsHandle.js +4 -8
- package/lib/client/locator.js +13 -44
- package/lib/client/network.js +15 -16
- package/lib/client/page.js +41 -75
- package/lib/client/platform.js +0 -3
- package/lib/client/screencast.js +88 -0
- package/lib/client/selectors.js +3 -1
- package/lib/client/tracing.js +11 -5
- package/lib/client/video.js +13 -20
- package/lib/client/worker.js +6 -6
- package/lib/generated/bindingsControllerSource.js +1 -1
- package/lib/generated/clockSource.js +1 -1
- package/lib/generated/injectedScriptSource.js +1 -1
- package/lib/generated/pollingRecorderSource.js +1 -1
- package/lib/generated/storageScriptSource.js +1 -1
- package/lib/generated/utilityScriptSource.js +1 -1
- package/lib/mcpBundle.js +0 -6
- package/lib/mcpBundleImpl.js +91 -0
- package/lib/protocol/validator.js +224 -138
- package/lib/protocol/validatorPrimitives.js +1 -1
- package/lib/remote/playwrightConnection.js +10 -8
- package/lib/remote/playwrightPipeServer.js +100 -0
- package/lib/remote/playwrightServer.js +13 -8
- package/lib/remote/playwrightWebSocketServer.js +73 -0
- package/lib/remote/serverTransport.js +96 -0
- package/lib/server/android/android.js +2 -2
- package/lib/server/bidi/bidiBrowser.js +30 -8
- package/lib/server/bidi/bidiChromium.js +18 -5
- package/lib/server/bidi/bidiNetworkManager.js +39 -11
- package/lib/server/bidi/bidiPage.js +31 -15
- package/lib/server/bidi/third_party/firefoxPrefs.js +3 -1
- package/lib/server/browser.js +84 -21
- package/lib/server/browserContext.js +110 -58
- package/lib/server/browserType.js +14 -12
- package/lib/server/chromium/chromium.js +15 -12
- package/lib/server/chromium/chromiumSwitches.js +14 -2
- package/lib/server/chromium/crBrowser.js +20 -17
- package/lib/server/chromium/crCoverage.js +1 -13
- package/lib/server/chromium/crDevTools.js +1 -0
- package/lib/server/chromium/crNetworkManager.js +12 -267
- package/lib/server/chromium/crPage.js +67 -199
- package/lib/server/chromium/crServiceWorker.js +7 -14
- package/lib/server/clock.js +33 -41
- package/lib/server/console.js +5 -1
- package/lib/server/debugController.js +12 -6
- package/lib/server/debugger.js +40 -47
- package/lib/server/deviceDescriptorsSource.json +137 -137
- package/lib/server/dispatchers/browserContextDispatcher.js +29 -30
- package/lib/server/dispatchers/browserDispatcher.js +11 -5
- package/lib/server/dispatchers/browserTypeDispatcher.js +7 -0
- package/lib/server/dispatchers/cdpSessionDispatcher.js +4 -1
- package/lib/server/dispatchers/debuggerDispatcher.js +84 -0
- package/lib/server/dispatchers/dispatcher.js +1 -1
- package/lib/server/dispatchers/disposableDispatcher.js +39 -0
- package/lib/server/dispatchers/electronDispatcher.js +2 -1
- package/lib/server/dispatchers/frameDispatcher.js +6 -6
- package/lib/server/dispatchers/jsHandleDispatcher.js +2 -2
- package/lib/server/dispatchers/localUtilsDispatcher.js +37 -1
- package/lib/server/dispatchers/networkDispatchers.js +6 -5
- package/lib/server/dispatchers/pageDispatcher.js +101 -38
- package/lib/server/dispatchers/webSocketRouteDispatcher.js +4 -5
- package/lib/server/disposable.js +41 -0
- package/lib/server/dom.js +44 -26
- package/lib/server/download.js +3 -2
- package/lib/server/electron/electron.js +12 -7
- package/lib/server/firefox/ffBrowser.js +9 -19
- package/lib/server/firefox/ffInput.js +21 -5
- package/lib/server/firefox/ffNetworkManager.js +2 -2
- package/lib/server/firefox/ffPage.js +24 -27
- package/lib/server/frameSelectors.js +5 -172
- package/lib/server/frames.js +234 -687
- package/lib/server/har/harRecorder.js +2 -2
- package/lib/server/har/harTracer.js +5 -4
- package/lib/server/input.js +49 -4
- package/lib/server/instrumentation.js +5 -0
- package/lib/server/javascript.js +6 -26
- package/lib/server/launchApp.js +1 -3
- package/lib/server/localUtils.js +6 -6
- package/lib/server/network.js +9 -8
- package/lib/server/overlay.js +138 -0
- package/lib/server/page.js +157 -105
- package/lib/server/progress.js +6 -0
- package/lib/server/recorder/recorderApp.js +9 -8
- package/lib/server/recorder.js +76 -40
- package/lib/server/registry/index.js +55 -82
- package/lib/server/registry/nativeDeps.js +1 -0
- package/lib/server/screencast.js +90 -143
- package/lib/server/screenshotter.js +0 -6
- package/lib/server/trace/recorder/snapshotter.js +8 -17
- package/lib/server/trace/recorder/snapshotterInjected.js +82 -20
- package/lib/server/trace/recorder/tracing.js +87 -44
- package/lib/server/trace/viewer/traceViewer.js +3 -4
- package/lib/server/usKeyboardLayout.js +7 -0
- package/lib/server/utils/comparators.js +1 -1
- package/lib/server/utils/disposable.js +32 -0
- package/lib/server/utils/eventsHelper.js +3 -1
- package/lib/server/utils/fileUtils.js +16 -2
- package/lib/server/utils/happyEyeballs.js +15 -12
- package/lib/server/utils/hostPlatform.js +0 -15
- package/lib/server/utils/httpServer.js +5 -3
- package/lib/server/utils/network.js +2 -1
- package/lib/server/utils/nodePlatform.js +0 -6
- package/lib/server/utils/processLauncher.js +6 -5
- package/lib/server/utils/zipFile.js +2 -2
- package/lib/server/videoRecorder.js +82 -12
- package/lib/server/webkit/wkBrowser.js +1 -6
- package/lib/server/webkit/wkPage.js +27 -25
- package/lib/server/webkit/wkWorkers.js +2 -1
- package/lib/serverRegistry.js +156 -0
- package/lib/tools/backend/browserBackend.js +79 -0
- package/lib/tools/backend/common.js +63 -0
- package/lib/tools/backend/config.js +41 -0
- package/lib/tools/backend/console.js +66 -0
- package/lib/tools/backend/context.js +296 -0
- package/lib/tools/backend/cookies.js +152 -0
- package/lib/tools/backend/devtools.js +69 -0
- package/lib/tools/backend/dialogs.js +59 -0
- package/lib/tools/backend/evaluate.js +64 -0
- package/lib/tools/backend/files.js +60 -0
- package/lib/tools/backend/form.js +64 -0
- package/lib/tools/backend/keyboard.js +155 -0
- package/lib/tools/backend/logFile.js +95 -0
- package/lib/tools/backend/mouse.js +168 -0
- package/lib/tools/backend/navigate.js +106 -0
- package/lib/tools/backend/network.js +135 -0
- package/lib/tools/backend/pdf.js +48 -0
- package/lib/tools/backend/response.js +305 -0
- package/lib/tools/backend/route.js +140 -0
- package/lib/tools/backend/runCode.js +77 -0
- package/lib/tools/backend/screenshot.js +88 -0
- package/lib/tools/backend/sessionLog.js +74 -0
- package/lib/tools/backend/snapshot.js +208 -0
- package/lib/tools/backend/storage.js +68 -0
- package/lib/tools/backend/tab.js +445 -0
- package/lib/tools/backend/tabs.js +67 -0
- package/lib/tools/backend/tool.js +47 -0
- package/lib/tools/backend/tools.js +102 -0
- package/lib/tools/backend/tracing.js +78 -0
- package/lib/tools/backend/utils.js +83 -0
- package/lib/tools/backend/verify.js +151 -0
- package/lib/tools/backend/video.js +98 -0
- package/lib/tools/backend/wait.js +63 -0
- package/lib/tools/backend/webstorage.js +223 -0
- package/lib/tools/cli-client/cli.js +6 -0
- package/lib/tools/cli-client/help.json +399 -0
- package/lib/tools/cli-client/minimist.js +128 -0
- package/lib/tools/cli-client/program.js +350 -0
- package/lib/tools/cli-client/registry.js +176 -0
- package/lib/tools/cli-client/session.js +289 -0
- package/lib/tools/cli-client/skill/SKILL.md +328 -0
- package/lib/tools/cli-client/skill/references/element-attributes.md +23 -0
- package/lib/tools/cli-client/skill/references/playwright-tests.md +39 -0
- package/lib/tools/cli-client/skill/references/request-mocking.md +87 -0
- package/lib/tools/cli-client/skill/references/running-code.md +231 -0
- package/lib/tools/cli-client/skill/references/session-management.md +169 -0
- package/lib/tools/cli-client/skill/references/storage-state.md +275 -0
- package/lib/tools/cli-client/skill/references/test-generation.md +88 -0
- package/lib/tools/cli-client/skill/references/tracing.md +139 -0
- package/lib/tools/cli-client/skill/references/video-recording.md +143 -0
- package/lib/tools/cli-daemon/command.js +73 -0
- package/lib/tools/cli-daemon/commands.js +956 -0
- package/lib/tools/cli-daemon/daemon.js +157 -0
- package/lib/tools/cli-daemon/helpGenerator.js +177 -0
- package/lib/tools/cli-daemon/program.js +129 -0
- package/lib/tools/dashboard/appIcon.png +0 -0
- package/lib/tools/dashboard/dashboardApp.js +284 -0
- package/lib/tools/dashboard/dashboardController.js +296 -0
- package/lib/tools/exports.js +60 -0
- package/lib/tools/mcp/browserFactory.js +233 -0
- package/lib/tools/mcp/cdpRelay.js +352 -0
- package/lib/tools/mcp/cli-stub.js +7 -0
- package/lib/tools/mcp/config.d.js +16 -0
- package/lib/tools/mcp/config.js +446 -0
- package/lib/tools/mcp/configIni.js +189 -0
- package/lib/tools/mcp/extensionContextFactory.js +55 -0
- package/lib/tools/mcp/index.js +62 -0
- package/lib/tools/mcp/log.js +35 -0
- package/lib/tools/mcp/program.js +107 -0
- package/lib/tools/mcp/protocol.js +28 -0
- package/lib/tools/mcp/watchdog.js +44 -0
- package/lib/tools/trace/SKILL.md +171 -0
- package/lib/{server/trace/viewer/traceParser.js → tools/trace/installSkill.js} +15 -39
- package/lib/tools/trace/traceActions.js +142 -0
- package/lib/tools/trace/traceAttachments.js +69 -0
- package/lib/tools/trace/traceCli.js +87 -0
- package/lib/tools/trace/traceConsole.js +97 -0
- package/lib/tools/trace/traceErrors.js +55 -0
- package/lib/tools/trace/traceOpen.js +69 -0
- package/lib/tools/trace/traceParser.js +96 -0
- package/lib/tools/trace/traceRequests.js +182 -0
- package/lib/tools/trace/traceScreenshot.js +68 -0
- package/lib/tools/trace/traceSnapshot.js +149 -0
- package/lib/tools/trace/traceUtils.js +153 -0
- package/lib/tools/utils/connect.js +32 -0
- package/lib/tools/utils/mcp/http.js +152 -0
- package/lib/tools/utils/mcp/server.js +230 -0
- package/lib/tools/utils/mcp/tool.js +47 -0
- package/lib/tools/utils/socketConnection.js +108 -0
- package/lib/utils/isomorphic/formatUtils.js +64 -0
- package/lib/utils/isomorphic/jsonSchema.js +89 -0
- package/lib/utils/isomorphic/mimeType.js +7 -2
- package/lib/utils/isomorphic/protocolFormatter.js +2 -2
- package/lib/utils/isomorphic/protocolMetainfo.js +127 -106
- package/lib/utils/isomorphic/stringUtils.js +3 -3
- package/lib/utils/isomorphic/timeoutRunner.js +3 -3
- package/lib/utils/isomorphic/trace/snapshotRenderer.js +35 -42
- package/lib/utils/isomorphic/trace/traceLoader.js +15 -14
- package/lib/utils/isomorphic/trace/traceModel.js +3 -2
- package/lib/utils/isomorphic/trace/traceModernizer.js +1 -0
- package/lib/utils/isomorphic/urlMatch.js +54 -1
- package/lib/utils/isomorphic/utilityScriptSerializers.js +11 -0
- package/lib/utils.js +6 -2
- package/lib/utilsBundle.js +3 -21
- package/lib/utilsBundleImpl/index.js +132 -133
- package/lib/vite/dashboard/assets/index-BAOybkp8.js +50 -0
- package/lib/vite/dashboard/assets/index-CZAYOG76.css +1 -0
- package/lib/vite/dashboard/index.html +28 -0
- package/lib/vite/htmlReport/index.html +2 -70
- package/lib/vite/htmlReport/report.css +1 -0
- package/lib/vite/htmlReport/report.js +72 -0
- package/lib/vite/recorder/assets/{codeMirrorModule-CFUTFUO7.js → codeMirrorModule-C8KMvO9L.js} +20 -20
- package/lib/vite/recorder/assets/index-CqAYX1I3.js +193 -0
- package/lib/vite/recorder/index.html +1 -1
- package/lib/vite/traceViewer/assets/{codeMirrorModule-BVA4h_ZY.js → codeMirrorModule-DS0FLvoc.js} +20 -20
- package/lib/vite/traceViewer/assets/defaultSettingsView-GTWI-W_B.js +262 -0
- package/lib/vite/traceViewer/defaultSettingsView.B4dS75f0.css +1 -0
- package/lib/vite/traceViewer/{index.BtyWtaE-.js → index.C5466mMT.js} +1 -1
- package/lib/vite/traceViewer/{index.BVu7tZDe.css → index.CzXZzn5A.css} +1 -1
- package/lib/vite/traceViewer/index.html +4 -4
- package/lib/vite/traceViewer/sw.bundle.js +4 -4
- package/lib/vite/traceViewer/uiMode.Vipi55dB.js +6 -0
- package/lib/vite/traceViewer/uiMode.html +3 -3
- package/lib/zipBundleImpl.js +2 -2
- package/lib/zodBundle.js +39 -0
- package/lib/zodBundleImpl.js +40 -0
- package/package.json +6 -1
- package/types/protocol.d.ts +947 -51
- package/types/types.d.ts +854 -74
- package/lib/client/pageAgent.js +0 -64
- package/lib/mcpBundleImpl/index.js +0 -147
- package/lib/server/agent/actionRunner.js +0 -335
- package/lib/server/agent/actions.js +0 -128
- package/lib/server/agent/codegen.js +0 -111
- package/lib/server/agent/context.js +0 -150
- package/lib/server/agent/expectTools.js +0 -156
- package/lib/server/agent/pageAgent.js +0 -204
- package/lib/server/agent/performTools.js +0 -262
- package/lib/server/agent/tool.js +0 -109
- package/lib/server/dispatchers/pageAgentDispatcher.js +0 -96
- package/lib/server/pageBinding.js +0 -87
- package/lib/utils/isomorphic/oldUtilityScriptSerializers.js +0 -248
- package/lib/vite/recorder/assets/index-CVkBxsGf.js +0 -193
- package/lib/vite/traceViewer/assets/defaultSettingsView-CjfmcdOz.js +0 -266
- package/lib/vite/traceViewer/defaultSettingsView.7ch9cixO.css +0 -1
- package/lib/vite/traceViewer/uiMode.fyrXARf2.js +0 -5
- /package/lib/{server/utils → utils/isomorphic}/imageUtils.js +0 -0
- /package/lib/utils/isomorphic/{traceUtils.js → trace/traceUtils.js} +0 -0
|
@@ -0,0 +1,275 @@
|
|
|
1
|
+
# Storage Management
|
|
2
|
+
|
|
3
|
+
Manage cookies, localStorage, sessionStorage, and browser storage state.
|
|
4
|
+
|
|
5
|
+
## Storage State
|
|
6
|
+
|
|
7
|
+
Save and restore complete browser state including cookies and storage.
|
|
8
|
+
|
|
9
|
+
### Save Storage State
|
|
10
|
+
|
|
11
|
+
```bash
|
|
12
|
+
# Save to auto-generated filename (storage-state-{timestamp}.json)
|
|
13
|
+
playwright-cli state-save
|
|
14
|
+
|
|
15
|
+
# Save to specific filename
|
|
16
|
+
playwright-cli state-save my-auth-state.json
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
### Restore Storage State
|
|
20
|
+
|
|
21
|
+
```bash
|
|
22
|
+
# Load storage state from file
|
|
23
|
+
playwright-cli state-load my-auth-state.json
|
|
24
|
+
|
|
25
|
+
# Reload page to apply cookies
|
|
26
|
+
playwright-cli open https://example.com
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
### Storage State File Format
|
|
30
|
+
|
|
31
|
+
The saved file contains:
|
|
32
|
+
|
|
33
|
+
```json
|
|
34
|
+
{
|
|
35
|
+
"cookies": [
|
|
36
|
+
{
|
|
37
|
+
"name": "session_id",
|
|
38
|
+
"value": "abc123",
|
|
39
|
+
"domain": "example.com",
|
|
40
|
+
"path": "/",
|
|
41
|
+
"expires": 1735689600,
|
|
42
|
+
"httpOnly": true,
|
|
43
|
+
"secure": true,
|
|
44
|
+
"sameSite": "Lax"
|
|
45
|
+
}
|
|
46
|
+
],
|
|
47
|
+
"origins": [
|
|
48
|
+
{
|
|
49
|
+
"origin": "https://example.com",
|
|
50
|
+
"localStorage": [
|
|
51
|
+
{ "name": "theme", "value": "dark" },
|
|
52
|
+
{ "name": "user_id", "value": "12345" }
|
|
53
|
+
]
|
|
54
|
+
}
|
|
55
|
+
]
|
|
56
|
+
}
|
|
57
|
+
```
|
|
58
|
+
|
|
59
|
+
## Cookies
|
|
60
|
+
|
|
61
|
+
### List All Cookies
|
|
62
|
+
|
|
63
|
+
```bash
|
|
64
|
+
playwright-cli cookie-list
|
|
65
|
+
```
|
|
66
|
+
|
|
67
|
+
### Filter Cookies by Domain
|
|
68
|
+
|
|
69
|
+
```bash
|
|
70
|
+
playwright-cli cookie-list --domain=example.com
|
|
71
|
+
```
|
|
72
|
+
|
|
73
|
+
### Filter Cookies by Path
|
|
74
|
+
|
|
75
|
+
```bash
|
|
76
|
+
playwright-cli cookie-list --path=/api
|
|
77
|
+
```
|
|
78
|
+
|
|
79
|
+
### Get Specific Cookie
|
|
80
|
+
|
|
81
|
+
```bash
|
|
82
|
+
playwright-cli cookie-get session_id
|
|
83
|
+
```
|
|
84
|
+
|
|
85
|
+
### Set a Cookie
|
|
86
|
+
|
|
87
|
+
```bash
|
|
88
|
+
# Basic cookie
|
|
89
|
+
playwright-cli cookie-set session abc123
|
|
90
|
+
|
|
91
|
+
# Cookie with options
|
|
92
|
+
playwright-cli cookie-set session abc123 --domain=example.com --path=/ --httpOnly --secure --sameSite=Lax
|
|
93
|
+
|
|
94
|
+
# Cookie with expiration (Unix timestamp)
|
|
95
|
+
playwright-cli cookie-set remember_me token123 --expires=1735689600
|
|
96
|
+
```
|
|
97
|
+
|
|
98
|
+
### Delete a Cookie
|
|
99
|
+
|
|
100
|
+
```bash
|
|
101
|
+
playwright-cli cookie-delete session_id
|
|
102
|
+
```
|
|
103
|
+
|
|
104
|
+
### Clear All Cookies
|
|
105
|
+
|
|
106
|
+
```bash
|
|
107
|
+
playwright-cli cookie-clear
|
|
108
|
+
```
|
|
109
|
+
|
|
110
|
+
### Advanced: Multiple Cookies or Custom Options
|
|
111
|
+
|
|
112
|
+
For complex scenarios like adding multiple cookies at once, use `run-code`:
|
|
113
|
+
|
|
114
|
+
```bash
|
|
115
|
+
playwright-cli run-code "async page => {
|
|
116
|
+
await page.context().addCookies([
|
|
117
|
+
{ name: 'session_id', value: 'sess_abc123', domain: 'example.com', path: '/', httpOnly: true },
|
|
118
|
+
{ name: 'preferences', value: JSON.stringify({ theme: 'dark' }), domain: 'example.com', path: '/' }
|
|
119
|
+
]);
|
|
120
|
+
}"
|
|
121
|
+
```
|
|
122
|
+
|
|
123
|
+
## Local Storage
|
|
124
|
+
|
|
125
|
+
### List All localStorage Items
|
|
126
|
+
|
|
127
|
+
```bash
|
|
128
|
+
playwright-cli localstorage-list
|
|
129
|
+
```
|
|
130
|
+
|
|
131
|
+
### Get Single Value
|
|
132
|
+
|
|
133
|
+
```bash
|
|
134
|
+
playwright-cli localstorage-get token
|
|
135
|
+
```
|
|
136
|
+
|
|
137
|
+
### Set Value
|
|
138
|
+
|
|
139
|
+
```bash
|
|
140
|
+
playwright-cli localstorage-set theme dark
|
|
141
|
+
```
|
|
142
|
+
|
|
143
|
+
### Set JSON Value
|
|
144
|
+
|
|
145
|
+
```bash
|
|
146
|
+
playwright-cli localstorage-set user_settings '{"theme":"dark","language":"en"}'
|
|
147
|
+
```
|
|
148
|
+
|
|
149
|
+
### Delete Single Item
|
|
150
|
+
|
|
151
|
+
```bash
|
|
152
|
+
playwright-cli localstorage-delete token
|
|
153
|
+
```
|
|
154
|
+
|
|
155
|
+
### Clear All localStorage
|
|
156
|
+
|
|
157
|
+
```bash
|
|
158
|
+
playwright-cli localstorage-clear
|
|
159
|
+
```
|
|
160
|
+
|
|
161
|
+
### Advanced: Multiple Operations
|
|
162
|
+
|
|
163
|
+
For complex scenarios like setting multiple values at once, use `run-code`:
|
|
164
|
+
|
|
165
|
+
```bash
|
|
166
|
+
playwright-cli run-code "async page => {
|
|
167
|
+
await page.evaluate(() => {
|
|
168
|
+
localStorage.setItem('token', 'jwt_abc123');
|
|
169
|
+
localStorage.setItem('user_id', '12345');
|
|
170
|
+
localStorage.setItem('expires_at', Date.now() + 3600000);
|
|
171
|
+
});
|
|
172
|
+
}"
|
|
173
|
+
```
|
|
174
|
+
|
|
175
|
+
## Session Storage
|
|
176
|
+
|
|
177
|
+
### List All sessionStorage Items
|
|
178
|
+
|
|
179
|
+
```bash
|
|
180
|
+
playwright-cli sessionstorage-list
|
|
181
|
+
```
|
|
182
|
+
|
|
183
|
+
### Get Single Value
|
|
184
|
+
|
|
185
|
+
```bash
|
|
186
|
+
playwright-cli sessionstorage-get form_data
|
|
187
|
+
```
|
|
188
|
+
|
|
189
|
+
### Set Value
|
|
190
|
+
|
|
191
|
+
```bash
|
|
192
|
+
playwright-cli sessionstorage-set step 3
|
|
193
|
+
```
|
|
194
|
+
|
|
195
|
+
### Delete Single Item
|
|
196
|
+
|
|
197
|
+
```bash
|
|
198
|
+
playwright-cli sessionstorage-delete step
|
|
199
|
+
```
|
|
200
|
+
|
|
201
|
+
### Clear sessionStorage
|
|
202
|
+
|
|
203
|
+
```bash
|
|
204
|
+
playwright-cli sessionstorage-clear
|
|
205
|
+
```
|
|
206
|
+
|
|
207
|
+
## IndexedDB
|
|
208
|
+
|
|
209
|
+
### List Databases
|
|
210
|
+
|
|
211
|
+
```bash
|
|
212
|
+
playwright-cli run-code "async page => {
|
|
213
|
+
return await page.evaluate(async () => {
|
|
214
|
+
const databases = await indexedDB.databases();
|
|
215
|
+
return databases;
|
|
216
|
+
});
|
|
217
|
+
}"
|
|
218
|
+
```
|
|
219
|
+
|
|
220
|
+
### Delete Database
|
|
221
|
+
|
|
222
|
+
```bash
|
|
223
|
+
playwright-cli run-code "async page => {
|
|
224
|
+
await page.evaluate(() => {
|
|
225
|
+
indexedDB.deleteDatabase('myDatabase');
|
|
226
|
+
});
|
|
227
|
+
}"
|
|
228
|
+
```
|
|
229
|
+
|
|
230
|
+
## Common Patterns
|
|
231
|
+
|
|
232
|
+
### Authentication State Reuse
|
|
233
|
+
|
|
234
|
+
```bash
|
|
235
|
+
# Step 1: Login and save state
|
|
236
|
+
playwright-cli open https://app.example.com/login
|
|
237
|
+
playwright-cli snapshot
|
|
238
|
+
playwright-cli fill e1 "user@example.com"
|
|
239
|
+
playwright-cli fill e2 "password123"
|
|
240
|
+
playwright-cli click e3
|
|
241
|
+
|
|
242
|
+
# Save the authenticated state
|
|
243
|
+
playwright-cli state-save auth.json
|
|
244
|
+
|
|
245
|
+
# Step 2: Later, restore state and skip login
|
|
246
|
+
playwright-cli state-load auth.json
|
|
247
|
+
playwright-cli open https://app.example.com/dashboard
|
|
248
|
+
# Already logged in!
|
|
249
|
+
```
|
|
250
|
+
|
|
251
|
+
### Save and Restore Roundtrip
|
|
252
|
+
|
|
253
|
+
```bash
|
|
254
|
+
# Set up authentication state
|
|
255
|
+
playwright-cli open https://example.com
|
|
256
|
+
playwright-cli eval "() => { document.cookie = 'session=abc123'; localStorage.setItem('user', 'john'); }"
|
|
257
|
+
|
|
258
|
+
# Save state to file
|
|
259
|
+
playwright-cli state-save my-session.json
|
|
260
|
+
|
|
261
|
+
# ... later, in a new session ...
|
|
262
|
+
|
|
263
|
+
# Restore state
|
|
264
|
+
playwright-cli state-load my-session.json
|
|
265
|
+
playwright-cli open https://example.com
|
|
266
|
+
# Cookies and localStorage are restored!
|
|
267
|
+
```
|
|
268
|
+
|
|
269
|
+
## Security Notes
|
|
270
|
+
|
|
271
|
+
- Never commit storage state files containing auth tokens
|
|
272
|
+
- Add `*.auth-state.json` to `.gitignore`
|
|
273
|
+
- Delete state files after automation completes
|
|
274
|
+
- Use environment variables for sensitive data
|
|
275
|
+
- By default, sessions run in-memory mode which is safer for sensitive operations
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
# Test Generation
|
|
2
|
+
|
|
3
|
+
Generate Playwright test code automatically as you interact with the browser.
|
|
4
|
+
|
|
5
|
+
## How It Works
|
|
6
|
+
|
|
7
|
+
Every action you perform with `playwright-cli` generates corresponding Playwright TypeScript code.
|
|
8
|
+
This code appears in the output and can be copied directly into your test files.
|
|
9
|
+
|
|
10
|
+
## Example Workflow
|
|
11
|
+
|
|
12
|
+
```bash
|
|
13
|
+
# Start a session
|
|
14
|
+
playwright-cli open https://example.com/login
|
|
15
|
+
|
|
16
|
+
# Take a snapshot to see elements
|
|
17
|
+
playwright-cli snapshot
|
|
18
|
+
# Output shows: e1 [textbox "Email"], e2 [textbox "Password"], e3 [button "Sign In"]
|
|
19
|
+
|
|
20
|
+
# Fill form fields - generates code automatically
|
|
21
|
+
playwright-cli fill e1 "user@example.com"
|
|
22
|
+
# Ran Playwright code:
|
|
23
|
+
# await page.getByRole('textbox', { name: 'Email' }).fill('user@example.com');
|
|
24
|
+
|
|
25
|
+
playwright-cli fill e2 "password123"
|
|
26
|
+
# Ran Playwright code:
|
|
27
|
+
# await page.getByRole('textbox', { name: 'Password' }).fill('password123');
|
|
28
|
+
|
|
29
|
+
playwright-cli click e3
|
|
30
|
+
# Ran Playwright code:
|
|
31
|
+
# await page.getByRole('button', { name: 'Sign In' }).click();
|
|
32
|
+
```
|
|
33
|
+
|
|
34
|
+
## Building a Test File
|
|
35
|
+
|
|
36
|
+
Collect the generated code into a Playwright test:
|
|
37
|
+
|
|
38
|
+
```typescript
|
|
39
|
+
import { test, expect } from '@playwright/test';
|
|
40
|
+
|
|
41
|
+
test('login flow', async ({ page }) => {
|
|
42
|
+
// Generated code from playwright-cli session:
|
|
43
|
+
await page.goto('https://example.com/login');
|
|
44
|
+
await page.getByRole('textbox', { name: 'Email' }).fill('user@example.com');
|
|
45
|
+
await page.getByRole('textbox', { name: 'Password' }).fill('password123');
|
|
46
|
+
await page.getByRole('button', { name: 'Sign In' }).click();
|
|
47
|
+
|
|
48
|
+
// Add assertions
|
|
49
|
+
await expect(page).toHaveURL(/.*dashboard/);
|
|
50
|
+
});
|
|
51
|
+
```
|
|
52
|
+
|
|
53
|
+
## Best Practices
|
|
54
|
+
|
|
55
|
+
### 1. Use Semantic Locators
|
|
56
|
+
|
|
57
|
+
The generated code uses role-based locators when possible, which are more resilient:
|
|
58
|
+
|
|
59
|
+
```typescript
|
|
60
|
+
// Generated (good - semantic)
|
|
61
|
+
await page.getByRole('button', { name: 'Submit' }).click();
|
|
62
|
+
|
|
63
|
+
// Avoid (fragile - CSS selectors)
|
|
64
|
+
await page.locator('#submit-btn').click();
|
|
65
|
+
```
|
|
66
|
+
|
|
67
|
+
### 2. Explore Before Recording
|
|
68
|
+
|
|
69
|
+
Take snapshots to understand the page structure before recording actions:
|
|
70
|
+
|
|
71
|
+
```bash
|
|
72
|
+
playwright-cli open https://example.com
|
|
73
|
+
playwright-cli snapshot
|
|
74
|
+
# Review the element structure
|
|
75
|
+
playwright-cli click e5
|
|
76
|
+
```
|
|
77
|
+
|
|
78
|
+
### 3. Add Assertions Manually
|
|
79
|
+
|
|
80
|
+
Generated code captures actions but not assertions. Add expectations in your test:
|
|
81
|
+
|
|
82
|
+
```typescript
|
|
83
|
+
// Generated action
|
|
84
|
+
await page.getByRole('button', { name: 'Submit' }).click();
|
|
85
|
+
|
|
86
|
+
// Manual assertion
|
|
87
|
+
await expect(page.getByText('Success')).toBeVisible();
|
|
88
|
+
```
|
|
@@ -0,0 +1,139 @@
|
|
|
1
|
+
# Tracing
|
|
2
|
+
|
|
3
|
+
Capture detailed execution traces for debugging and analysis. Traces include DOM snapshots, screenshots, network activity, and console logs.
|
|
4
|
+
|
|
5
|
+
## Basic Usage
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
# Start trace recording
|
|
9
|
+
playwright-cli tracing-start
|
|
10
|
+
|
|
11
|
+
# Perform actions
|
|
12
|
+
playwright-cli open https://example.com
|
|
13
|
+
playwright-cli click e1
|
|
14
|
+
playwright-cli fill e2 "test"
|
|
15
|
+
|
|
16
|
+
# Stop trace recording
|
|
17
|
+
playwright-cli tracing-stop
|
|
18
|
+
```
|
|
19
|
+
|
|
20
|
+
## Trace Output Files
|
|
21
|
+
|
|
22
|
+
When you start tracing, Playwright creates a `traces/` directory with several files:
|
|
23
|
+
|
|
24
|
+
### `trace-{timestamp}.trace`
|
|
25
|
+
|
|
26
|
+
**Action log** - The main trace file containing:
|
|
27
|
+
- Every action performed (clicks, fills, navigations)
|
|
28
|
+
- DOM snapshots before and after each action
|
|
29
|
+
- Screenshots at each step
|
|
30
|
+
- Timing information
|
|
31
|
+
- Console messages
|
|
32
|
+
- Source locations
|
|
33
|
+
|
|
34
|
+
### `trace-{timestamp}.network`
|
|
35
|
+
|
|
36
|
+
**Network log** - Complete network activity:
|
|
37
|
+
- All HTTP requests and responses
|
|
38
|
+
- Request headers and bodies
|
|
39
|
+
- Response headers and bodies
|
|
40
|
+
- Timing (DNS, connect, TLS, TTFB, download)
|
|
41
|
+
- Resource sizes
|
|
42
|
+
- Failed requests and errors
|
|
43
|
+
|
|
44
|
+
### `resources/`
|
|
45
|
+
|
|
46
|
+
**Resources directory** - Cached resources:
|
|
47
|
+
- Images, fonts, stylesheets, scripts
|
|
48
|
+
- Response bodies for replay
|
|
49
|
+
- Assets needed to reconstruct page state
|
|
50
|
+
|
|
51
|
+
## What Traces Capture
|
|
52
|
+
|
|
53
|
+
| Category | Details |
|
|
54
|
+
|----------|---------|
|
|
55
|
+
| **Actions** | Clicks, fills, hovers, keyboard input, navigations |
|
|
56
|
+
| **DOM** | Full DOM snapshot before/after each action |
|
|
57
|
+
| **Screenshots** | Visual state at each step |
|
|
58
|
+
| **Network** | All requests, responses, headers, bodies, timing |
|
|
59
|
+
| **Console** | All console.log, warn, error messages |
|
|
60
|
+
| **Timing** | Precise timing for each operation |
|
|
61
|
+
|
|
62
|
+
## Use Cases
|
|
63
|
+
|
|
64
|
+
### Debugging Failed Actions
|
|
65
|
+
|
|
66
|
+
```bash
|
|
67
|
+
playwright-cli tracing-start
|
|
68
|
+
playwright-cli open https://app.example.com
|
|
69
|
+
|
|
70
|
+
# This click fails - why?
|
|
71
|
+
playwright-cli click e5
|
|
72
|
+
|
|
73
|
+
playwright-cli tracing-stop
|
|
74
|
+
# Open trace to see DOM state when click was attempted
|
|
75
|
+
```
|
|
76
|
+
|
|
77
|
+
### Analyzing Performance
|
|
78
|
+
|
|
79
|
+
```bash
|
|
80
|
+
playwright-cli tracing-start
|
|
81
|
+
playwright-cli open https://slow-site.com
|
|
82
|
+
playwright-cli tracing-stop
|
|
83
|
+
|
|
84
|
+
# View network waterfall to identify slow resources
|
|
85
|
+
```
|
|
86
|
+
|
|
87
|
+
### Capturing Evidence
|
|
88
|
+
|
|
89
|
+
```bash
|
|
90
|
+
# Record a complete user flow for documentation
|
|
91
|
+
playwright-cli tracing-start
|
|
92
|
+
|
|
93
|
+
playwright-cli open https://app.example.com/checkout
|
|
94
|
+
playwright-cli fill e1 "4111111111111111"
|
|
95
|
+
playwright-cli fill e2 "12/25"
|
|
96
|
+
playwright-cli fill e3 "123"
|
|
97
|
+
playwright-cli click e4
|
|
98
|
+
|
|
99
|
+
playwright-cli tracing-stop
|
|
100
|
+
# Trace shows exact sequence of events
|
|
101
|
+
```
|
|
102
|
+
|
|
103
|
+
## Trace vs Video vs Screenshot
|
|
104
|
+
|
|
105
|
+
| Feature | Trace | Video | Screenshot |
|
|
106
|
+
|---------|-------|-------|------------|
|
|
107
|
+
| **Format** | .trace file | .webm video | .png/.jpeg image |
|
|
108
|
+
| **DOM inspection** | Yes | No | No |
|
|
109
|
+
| **Network details** | Yes | No | No |
|
|
110
|
+
| **Step-by-step replay** | Yes | Continuous | Single frame |
|
|
111
|
+
| **File size** | Medium | Large | Small |
|
|
112
|
+
| **Best for** | Debugging | Demos | Quick capture |
|
|
113
|
+
|
|
114
|
+
## Best Practices
|
|
115
|
+
|
|
116
|
+
### 1. Start Tracing Before the Problem
|
|
117
|
+
|
|
118
|
+
```bash
|
|
119
|
+
# Trace the entire flow, not just the failing step
|
|
120
|
+
playwright-cli tracing-start
|
|
121
|
+
playwright-cli open https://example.com
|
|
122
|
+
# ... all steps leading to the issue ...
|
|
123
|
+
playwright-cli tracing-stop
|
|
124
|
+
```
|
|
125
|
+
|
|
126
|
+
### 2. Clean Up Old Traces
|
|
127
|
+
|
|
128
|
+
Traces can consume significant disk space:
|
|
129
|
+
|
|
130
|
+
```bash
|
|
131
|
+
# Remove traces older than 7 days
|
|
132
|
+
find .playwright-cli/traces -mtime +7 -delete
|
|
133
|
+
```
|
|
134
|
+
|
|
135
|
+
## Limitations
|
|
136
|
+
|
|
137
|
+
- Traces add overhead to automation
|
|
138
|
+
- Large traces can consume significant disk space
|
|
139
|
+
- Some dynamic content may not replay perfectly
|
|
@@ -0,0 +1,143 @@
|
|
|
1
|
+
# Video Recording
|
|
2
|
+
|
|
3
|
+
Capture browser automation sessions as video for debugging, documentation, or verification. Produces WebM (VP8/VP9 codec).
|
|
4
|
+
|
|
5
|
+
## Basic Recording
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
# Open browser first
|
|
9
|
+
playwright-cli open
|
|
10
|
+
|
|
11
|
+
# Start recording
|
|
12
|
+
playwright-cli video-start demo.webm
|
|
13
|
+
|
|
14
|
+
# Add a chapter marker for section transitions
|
|
15
|
+
playwright-cli video-chapter "Getting Started" --description="Opening the homepage" --duration=2000
|
|
16
|
+
|
|
17
|
+
# Navigate and perform actions
|
|
18
|
+
playwright-cli goto https://example.com
|
|
19
|
+
playwright-cli snapshot
|
|
20
|
+
playwright-cli click e1
|
|
21
|
+
|
|
22
|
+
# Add another chapter
|
|
23
|
+
playwright-cli video-chapter "Filling Form" --description="Entering test data" --duration=2000
|
|
24
|
+
playwright-cli fill e2 "test input"
|
|
25
|
+
|
|
26
|
+
# Stop and save
|
|
27
|
+
playwright-cli video-stop
|
|
28
|
+
```
|
|
29
|
+
|
|
30
|
+
## Best Practices
|
|
31
|
+
|
|
32
|
+
### 1. Use Descriptive Filenames
|
|
33
|
+
|
|
34
|
+
```bash
|
|
35
|
+
# Include context in filename
|
|
36
|
+
playwright-cli video-start recordings/login-flow-2024-01-15.webm
|
|
37
|
+
playwright-cli video-start recordings/checkout-test-run-42.webm
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
### 2. Record entire hero scripts.
|
|
41
|
+
|
|
42
|
+
When recording a video for the user or as a proof of work, it is best to create a code snippet and execute it with run-code.
|
|
43
|
+
It allows pulling appropriate pauses between the actions and annotating the video. There are new Playwright APIs for that.
|
|
44
|
+
|
|
45
|
+
1) Perform scenario using CLI and take note of all locators and actions. You'll need those locators to request thier bounding boxes for highlight.
|
|
46
|
+
2) Create a file with the intended script for video (below). Use pressSequentially w/ delay for nice typing, make reasonable pauses.
|
|
47
|
+
3) Use playwright-cli run-code --file your-script.js
|
|
48
|
+
|
|
49
|
+
**Important**: Overlays are `pointer-events: none` — they do not interfere with page interactions. You can safely keep sticky overlays visible while clicking, filling, or performing any actions on the page.
|
|
50
|
+
|
|
51
|
+
```js
|
|
52
|
+
async page => {
|
|
53
|
+
await page.screencast.start({ path: 'video.webm', size: { width: 1280, height: 800 } });
|
|
54
|
+
await page.goto('https://demo.playwright.dev/todomvc');
|
|
55
|
+
|
|
56
|
+
// Show a chapter card — blurs the page and shows a dialog.
|
|
57
|
+
// Blocks until duration expires, then auto-removes.
|
|
58
|
+
// Use this for simple use cases, but always feel free to hand-craft your own beautiful
|
|
59
|
+
// overlay via await page.screencast.showOverlay().
|
|
60
|
+
await page.screencast.showChapter('Adding Todo Items', {
|
|
61
|
+
description: 'We will add several items to the todo list.',
|
|
62
|
+
duration: 2000,
|
|
63
|
+
});
|
|
64
|
+
|
|
65
|
+
// Perform action
|
|
66
|
+
await page.getByRole('textbox', { name: 'What needs to be done?' }).pressSequentially('Walk the dog', { delay: 60 });
|
|
67
|
+
await page.getByRole('textbox', { name: 'What needs to be done?' }).press('Enter');
|
|
68
|
+
await page.waitForTimeout(1000);
|
|
69
|
+
|
|
70
|
+
// Show next chapter
|
|
71
|
+
await page.screencast.showChapter('Verifying Results', {
|
|
72
|
+
description: 'Checking the item appeared in the list.',
|
|
73
|
+
duration: 2000,
|
|
74
|
+
});
|
|
75
|
+
|
|
76
|
+
// Add a sticky annotation that stays while you perform actions.
|
|
77
|
+
// Overlays are pointer-events: none, so they won't block clicks.
|
|
78
|
+
const annotation = await page.screencast.showOverlay(`
|
|
79
|
+
<div style="position: absolute; top: 8px; right: 8px;
|
|
80
|
+
padding: 6px 12px; background: rgba(0,0,0,0.7);
|
|
81
|
+
border-radius: 8px; font-size: 13px; color: white;">
|
|
82
|
+
✓ Item added successfully
|
|
83
|
+
</div>
|
|
84
|
+
`);
|
|
85
|
+
|
|
86
|
+
// Perform more actions while the annotation is visible
|
|
87
|
+
await page.getByRole('textbox', { name: 'What needs to be done?' }).pressSequentially('Buy groceries', { delay: 60 });
|
|
88
|
+
await page.getByRole('textbox', { name: 'What needs to be done?' }).press('Enter');
|
|
89
|
+
await page.waitForTimeout(1500);
|
|
90
|
+
|
|
91
|
+
// Remove the annotation when done
|
|
92
|
+
await annotation.dispose();
|
|
93
|
+
|
|
94
|
+
// You can also highlight relevant locators and provide contextual annotations.
|
|
95
|
+
const bounds = await page.getByText('Walk the dog').boundingBox();
|
|
96
|
+
await page.screencast.showOverlay(`
|
|
97
|
+
<div style="position: absolute;
|
|
98
|
+
top: ${bounds.y}px;
|
|
99
|
+
left: ${bounds.x}px;
|
|
100
|
+
width: ${bounds.width}px;
|
|
101
|
+
height: ${bounds.height}px;
|
|
102
|
+
border: 1px solid red;">
|
|
103
|
+
</div>
|
|
104
|
+
<div style="position: absolute;
|
|
105
|
+
top: ${bounds.y + bounds.height + 5}px;
|
|
106
|
+
left: ${bounds.x + bounds.width / 2}px;
|
|
107
|
+
transform: translateX(-50%);
|
|
108
|
+
padding: 6px;
|
|
109
|
+
background: #808080;
|
|
110
|
+
border-radius: 10px;
|
|
111
|
+
font-size: 14px;
|
|
112
|
+
color: white;">Check it out, it is right above this text
|
|
113
|
+
</div>
|
|
114
|
+
`, { duration: 2000 });
|
|
115
|
+
|
|
116
|
+
await page.screencast.stop();
|
|
117
|
+
}
|
|
118
|
+
```
|
|
119
|
+
|
|
120
|
+
Embrace creativity, overlays are powerful.
|
|
121
|
+
|
|
122
|
+
### Overlay API Summary
|
|
123
|
+
|
|
124
|
+
| Method | Use Case |
|
|
125
|
+
|--------|----------|
|
|
126
|
+
| `page.screencast.showChapter(title, { description?, duration?, styleSheet? })` | Full-screen chapter card with blurred backdrop — ideal for section transitions |
|
|
127
|
+
| `page.screencast.showOverlay(html, { duration? })` | Custom HTML overlay — use for callouts, labels, highlights |
|
|
128
|
+
| `disposable.dispose()` | Remove a sticky overlay added without duration |
|
|
129
|
+
| `page.screencast.hideOverlays()` / `page.screencast.showOverlays()` | Temporarily hide/show all overlays |
|
|
130
|
+
|
|
131
|
+
## Tracing vs Video
|
|
132
|
+
|
|
133
|
+
| Feature | Video | Tracing |
|
|
134
|
+
|---------|-------|---------|
|
|
135
|
+
| Output | WebM file | Trace file (viewable in Trace Viewer) |
|
|
136
|
+
| Shows | Visual recording | DOM snapshots, network, console, actions |
|
|
137
|
+
| Use case | Demos, documentation | Debugging, analysis |
|
|
138
|
+
| Size | Larger | Smaller |
|
|
139
|
+
|
|
140
|
+
## Limitations
|
|
141
|
+
|
|
142
|
+
- Recording adds slight overhead to automation
|
|
143
|
+
- Large recordings can consume significant disk space
|