playwright-ws-trace 1.0.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 (32) hide show
  1. package/LICENSE +22 -0
  2. package/README.md +151 -0
  3. package/dist/traceViewer/assets/codeMirrorModule-4q8rQ10u.js +32 -0
  4. package/dist/traceViewer/assets/codeMirrorModule-C8IrGpNa.js +32 -0
  5. package/dist/traceViewer/assets/codeMirrorModule-CMV0Xve7.js +32 -0
  6. package/dist/traceViewer/assets/defaultSettingsView-BSyixIDP.js +267 -0
  7. package/dist/traceViewer/assets/defaultSettingsView-D-F27Sf_.js +267 -0
  8. package/dist/traceViewer/assets/defaultSettingsView-Dfy_AxQA.js +267 -0
  9. package/dist/traceViewer/assets/xtermModule-CsJ4vdCR.js +9 -0
  10. package/dist/traceViewer/codeMirrorModule.DYBRYzYX.css +1 -0
  11. package/dist/traceViewer/codicon.DCmgc-ay.ttf +0 -0
  12. package/dist/traceViewer/defaultSettingsView.26324PFb.css +1 -0
  13. package/dist/traceViewer/defaultSettingsView.8SsIZrFV.css +1 -0
  14. package/dist/traceViewer/defaultSettingsView.CFXgZVUo.css +1 -0
  15. package/dist/traceViewer/index.C4Y3Aw8n.css +1 -0
  16. package/dist/traceViewer/index.DHUPn3i0.js +2 -0
  17. package/dist/traceViewer/index.Ddar81JJ.js +2 -0
  18. package/dist/traceViewer/index.DyW3Fq0z.js +2 -0
  19. package/dist/traceViewer/index.html +43 -0
  20. package/dist/traceViewer/manifest.webmanifest +16 -0
  21. package/dist/traceViewer/playwright-logo.svg +9 -0
  22. package/dist/traceViewer/snapshot.html +21 -0
  23. package/dist/traceViewer/sw.bundle.js +3 -0
  24. package/dist/traceViewer/uiMode.BCiLqXdB.js +5 -0
  25. package/dist/traceViewer/uiMode.Btcz36p_.css +1 -0
  26. package/dist/traceViewer/uiMode.DccP-sCl.js +5 -0
  27. package/dist/traceViewer/uiMode.hG-ABF1X.js +5 -0
  28. package/dist/traceViewer/uiMode.html +17 -0
  29. package/dist/traceViewer/xtermModule.DYP7pi_n.css +32 -0
  30. package/package.json +42 -0
  31. package/scripts/postinstall.js +327 -0
  32. package/src/index.js +15 -0
package/LICENSE ADDED
@@ -0,0 +1,22 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2024 kabaneridev
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
22
+
package/README.md ADDED
@@ -0,0 +1,151 @@
1
+ # playwright-ws-trace 🔌
2
+
3
+ > WebSocket frame tracing for Playwright - see every WebSocket message in your traces!
4
+
5
+ [![npm version](https://badge.fury.io/js/playwright-ws-trace.svg)](https://www.npmjs.com/package/playwright-ws-trace)
6
+
7
+ Microsoft rejected our [PR #38427](https://github.com/microsoft/playwright/pull/38427) to add WebSocket tracing to Playwright. So we made it ourselves. 💪
8
+
9
+ ## Features
10
+
11
+ - 📡 **Record WebSocket frames** - Captures all sent and received frames during test execution
12
+ - 🔍 **View in trace viewer** - Browse WebSocket connections and frames in the standard Playwright trace viewer
13
+ - 🎯 **Filter by type** - New "WS" filter in the Network tab to show only WebSocket traffic
14
+ - 📊 **Frame details** - See direction (sent/received), timestamps, and payload data
15
+ - 📝 **JSON formatting** - Automatically formats JSON payloads for readability
16
+
17
+ ## Installation
18
+
19
+ ```bash
20
+ npm install playwright-ws-trace
21
+ # or
22
+ yarn add playwright-ws-trace
23
+ # or
24
+ pnpm add playwright-ws-trace
25
+ ```
26
+
27
+ The package automatically patches your Playwright installation on install. That's it!
28
+
29
+ ## Usage
30
+
31
+ ### 1. Enable tracing in your tests
32
+
33
+ Configure in `playwright.config.ts`:
34
+
35
+ ```typescript
36
+ import { defineConfig } from '@playwright/test';
37
+
38
+ export default defineConfig({
39
+ use: {
40
+ trace: 'on', // or 'on-first-retry', 'retain-on-failure'
41
+ },
42
+ });
43
+ ```
44
+
45
+ Or start tracing manually:
46
+
47
+ ```typescript
48
+ import { test } from '@playwright/test';
49
+
50
+ test('websocket test', async ({ page, context }) => {
51
+ await context.tracing.start({ snapshots: true, screenshots: true });
52
+
53
+ await page.goto('https://your-websocket-app.com');
54
+ // Your test actions...
55
+
56
+ await context.tracing.stop({ path: 'trace.zip' });
57
+ });
58
+ ```
59
+
60
+ ### 2. View WebSocket traces
61
+
62
+ Use the standard Playwright trace viewer:
63
+
64
+ ```bash
65
+ npx playwright show-trace ./test-results/my-test/trace.zip
66
+ ```
67
+
68
+ Or open from HTML report - click "View Trace" on any test.
69
+
70
+ ### 3. Find WebSocket data
71
+
72
+ In the trace viewer:
73
+ 1. Click the **Network** tab
74
+ 2. Click the **WS** filter to show only WebSocket traffic
75
+ 3. Click on a WebSocket connection to see frames
76
+ 4. View sent (↑) and received (↓) frames with full payload data
77
+
78
+ ## Screenshot
79
+
80
+ ![Trace Viewer with WS filter](https://raw.githubusercontent.com/kabaneridev/playwright-ws-trace/main/demo.png)
81
+
82
+ ## How it works
83
+
84
+ This package patches Playwright on install:
85
+
86
+ 1. **Recording** (`tracing.js`) - Hooks into CDP events to capture:
87
+ - `webSocketCreated` - Connection opened
88
+ - `webSocketFrameSent` - Frame sent to server
89
+ - `webSocketFrameReceived` - Frame received from server
90
+ - `webSocketClosed` - Connection closed
91
+ - `webSocketError` - Connection error
92
+
93
+ 2. **Trace Viewer** - Replaces the bundled viewer with a patched version that:
94
+ - Adds "WS" filter to Network tab
95
+ - Displays WebSocket connections and frames
96
+ - Shows frame direction, timestamp, and payload
97
+
98
+ ## Compatibility
99
+
100
+ | Playwright | Status |
101
+ |------------|--------|
102
+ | 1.50.x - 1.56.x | ✅ Tested |
103
+ | 1.40.0+ | ⚠️ Should work |
104
+
105
+ ## After Playwright Updates
106
+
107
+ When you update Playwright, the patches need to be reapplied:
108
+
109
+ ```bash
110
+ # Reinstall to reapply patches
111
+ npm uninstall playwright-ws-trace && npm install playwright-ws-trace
112
+
113
+ # Or run postinstall manually
114
+ node node_modules/playwright-ws-trace/scripts/postinstall.js --force
115
+ ```
116
+
117
+ ## Troubleshooting
118
+
119
+ ### Patches not applying
120
+
121
+ Run the postinstall script with `--force`:
122
+
123
+ ```bash
124
+ node node_modules/playwright-ws-trace/scripts/postinstall.js --force
125
+ ```
126
+
127
+ ### WS filter not showing
128
+
129
+ Make sure the patched trace viewer was installed. Check that:
130
+ ```bash
131
+ ls node_modules/playwright-core/lib/vite/traceViewer/
132
+ ```
133
+ Contains files from this package.
134
+
135
+ ### WebSocket frames not recorded
136
+
137
+ Ensure tracing is enabled in your config with `trace: 'on'` or similar.
138
+
139
+ ## Contributing
140
+
141
+ PRs welcome! The original PR to Playwright is at [#38427](https://github.com/microsoft/playwright/pull/38427).
142
+
143
+ If Microsoft ever accepts WebSocket tracing into Playwright core, this package will become obsolete - and that's a good thing! 🎉
144
+
145
+ ## License
146
+
147
+ MIT - do whatever you want with it.
148
+
149
+ ---
150
+
151
+ Made with ❤️ because Microsoft said no.