@designcrowd/fe-shared-lib 1.8.3 → 1.8.4-edge-fallback-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/force-unsupported-hidden.png +0 -0
- package/force-unsupported-with-button.png +0 -0
- package/package.json +1 -1
- package/src/atoms/components/VoiceToTextButton/VoiceToTextButton.stories.ts +68 -0
- package/src/useVoiceToText.ts +58 -1
- package/.claude/scheduled_tasks.lock +0 -1
- package/.claude/settings.local.json +0 -54
- package/.claude/skills/playwright-cli/SKILL.md +0 -278
- package/.claude/skills/playwright-cli/references/request-mocking.md +0 -87
- package/.claude/skills/playwright-cli/references/running-code.md +0 -232
- package/.claude/skills/playwright-cli/references/session-management.md +0 -169
- package/.claude/skills/playwright-cli/references/storage-state.md +0 -275
- package/.claude/skills/playwright-cli/references/test-generation.md +0 -88
- package/.claude/skills/playwright-cli/references/tracing.md +0 -139
- package/.claude/skills/playwright-cli/references/video-recording.md +0 -43
- package/.playwright-cli/page-2026-04-27T23-43-18-200Z.yml +0 -68
- package/.playwright-cli/page-2026-04-28T01-20-32-525Z.yml +0 -451
|
Binary file
|
|
Binary file
|
package/package.json
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import VoiceToTextButton from './VoiceToTextButton.vue';
|
|
2
|
+
import { __setVoiceToTextSessionDisabled } from '../../../useVoiceToText';
|
|
2
3
|
|
|
3
4
|
export default {
|
|
4
5
|
title: 'Components/VoiceToTextButton',
|
|
@@ -240,3 +241,70 @@ export const SideBySide = () => ({
|
|
|
240
241
|
SideBySide.story = {
|
|
241
242
|
name: 'Side by Side Comparison',
|
|
242
243
|
};
|
|
244
|
+
|
|
245
|
+
export const ForceUnsupported = () => ({
|
|
246
|
+
components: { VoiceToTextButton },
|
|
247
|
+
data() {
|
|
248
|
+
return {
|
|
249
|
+
// Reactive ping so the button re-renders when we flip the session flag.
|
|
250
|
+
// The composable's isSupported is reactive on its own, but the parent
|
|
251
|
+
// template uses :key to make the toggle obvious in Storybook.
|
|
252
|
+
tick: 0,
|
|
253
|
+
};
|
|
254
|
+
},
|
|
255
|
+
methods: {
|
|
256
|
+
forceUnsupported() {
|
|
257
|
+
__setVoiceToTextSessionDisabled(true);
|
|
258
|
+
this.tick += 1;
|
|
259
|
+
},
|
|
260
|
+
reset() {
|
|
261
|
+
__setVoiceToTextSessionDisabled(false);
|
|
262
|
+
this.tick += 1;
|
|
263
|
+
},
|
|
264
|
+
},
|
|
265
|
+
template: `
|
|
266
|
+
<div class="tw-min-h-[400px] tw-p-8 tw-flex tw-flex-col tw-items-center tw-justify-center tw-bg-white">
|
|
267
|
+
<h3 class="tw-text-grayscale-800 tw-text-lg tw-font-semibold tw-mb-2">Force unsupported preview</h3>
|
|
268
|
+
<p class="tw-text-grayscale-600 tw-text-sm tw-mb-6 tw-text-center tw-max-w-md">
|
|
269
|
+
Simulates the Edge fallback: after a 'network' SpeechRecognitionError, the composable latches
|
|
270
|
+
<code class="tw-bg-grayscale-100 tw-px-1 tw-rounded">isSupported</code> to false for the rest of the session
|
|
271
|
+
and the button hides itself. Reset clears the session flag.
|
|
272
|
+
</p>
|
|
273
|
+
|
|
274
|
+
<div class="tw-flex tw-gap-3 tw-mb-6">
|
|
275
|
+
<button
|
|
276
|
+
type="button"
|
|
277
|
+
@click="forceUnsupported"
|
|
278
|
+
class="tw-px-4 tw-py-2 tw-rounded tw-bg-error-500 tw-text-white tw-text-sm hover:tw-bg-error-600"
|
|
279
|
+
>
|
|
280
|
+
Force unsupported
|
|
281
|
+
</button>
|
|
282
|
+
<button
|
|
283
|
+
type="button"
|
|
284
|
+
@click="reset"
|
|
285
|
+
class="tw-px-4 tw-py-2 tw-rounded tw-bg-grayscale-200 tw-text-grayscale-800 tw-text-sm hover:tw-bg-grayscale-300"
|
|
286
|
+
>
|
|
287
|
+
Reset
|
|
288
|
+
</button>
|
|
289
|
+
</div>
|
|
290
|
+
|
|
291
|
+
<div class="tw-w-full tw-max-w-xl tw-bg-grayscale-100 tw-rounded-full tw-px-6 tw-py-3 tw-flex tw-items-center tw-gap-3 tw-border tw-border-grayscale-300 tw-min-h-[64px]">
|
|
292
|
+
<input
|
|
293
|
+
type="text"
|
|
294
|
+
placeholder="Voice input would appear on the right..."
|
|
295
|
+
class="tw-flex-1 tw-bg-transparent tw-border-none tw-text-grayscale-800 tw-placeholder-grayscale-500 focus:tw-outline-none tw-text-base"
|
|
296
|
+
/>
|
|
297
|
+
<VoiceToTextButton :key="tick" variant="light" size="md" />
|
|
298
|
+
</div>
|
|
299
|
+
|
|
300
|
+
<p class="tw-text-grayscale-500 tw-text-xs tw-mt-4">
|
|
301
|
+
Tip: open DevTools → Application → Session Storage to see the
|
|
302
|
+
<code class="tw-bg-grayscale-100 tw-px-1 tw-rounded">fe-shared-lib:voice-to-text-disabled</code> key.
|
|
303
|
+
</p>
|
|
304
|
+
</div>
|
|
305
|
+
`,
|
|
306
|
+
});
|
|
307
|
+
|
|
308
|
+
ForceUnsupported.story = {
|
|
309
|
+
name: 'Force Unsupported (Edge Fallback)',
|
|
310
|
+
};
|
package/src/useVoiceToText.ts
CHANGED
|
@@ -30,6 +30,14 @@ let recognition: SpeechRecognition | null = null;
|
|
|
30
30
|
let isInitialized = false;
|
|
31
31
|
let errorClearTimeout: ReturnType<typeof setTimeout> | null = null;
|
|
32
32
|
let state: VoiceToTextState | null = null;
|
|
33
|
+
let sessionDisabled: Ref<boolean> | null = null;
|
|
34
|
+
|
|
35
|
+
// Edge ships window.SpeechRecognition but routes it through Microsoft's Online
|
|
36
|
+
// Speech service, which is gated by a Windows privacy toggle that's commonly
|
|
37
|
+
// off — start() then fires a 'network' error. There's no synchronous capability
|
|
38
|
+
// check, so we latch on the first network error and treat the feature as
|
|
39
|
+
// unsupported for the rest of the session. See issue #161.
|
|
40
|
+
const SESSION_DISABLED_KEY = 'fe-shared-lib:voice-to-text-disabled';
|
|
33
41
|
|
|
34
42
|
// Error message mapping per spec
|
|
35
43
|
const ERROR_MESSAGES: Record<string, string> = {
|
|
@@ -53,6 +61,43 @@ function getState(): VoiceToTextState {
|
|
|
53
61
|
return state;
|
|
54
62
|
}
|
|
55
63
|
|
|
64
|
+
function getSessionDisabled(): Ref<boolean> {
|
|
65
|
+
if (!sessionDisabled) {
|
|
66
|
+
let initial = false;
|
|
67
|
+
try {
|
|
68
|
+
initial = typeof window !== 'undefined' && window.sessionStorage?.getItem(SESSION_DISABLED_KEY) === '1';
|
|
69
|
+
} catch {
|
|
70
|
+
// sessionStorage can throw in sandboxed iframes / disabled-cookie contexts
|
|
71
|
+
}
|
|
72
|
+
sessionDisabled = ref(initial);
|
|
73
|
+
}
|
|
74
|
+
return sessionDisabled;
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
function setSessionDisabled(disabled: boolean): void {
|
|
78
|
+
const flag = getSessionDisabled();
|
|
79
|
+
flag.value = disabled;
|
|
80
|
+
try {
|
|
81
|
+
if (typeof window === 'undefined') return;
|
|
82
|
+
if (disabled) {
|
|
83
|
+
window.sessionStorage?.setItem(SESSION_DISABLED_KEY, '1');
|
|
84
|
+
} else {
|
|
85
|
+
window.sessionStorage?.removeItem(SESSION_DISABLED_KEY);
|
|
86
|
+
}
|
|
87
|
+
} catch {
|
|
88
|
+
// ignore storage failures — in-memory flag still applies for this session
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
/**
|
|
93
|
+
* Test/Storybook helper: force the session-disabled latch on or off without
|
|
94
|
+
* needing a real network error. Not part of the public consumer API.
|
|
95
|
+
*/
|
|
96
|
+
// eslint-disable-next-line no-underscore-dangle
|
|
97
|
+
export function __setVoiceToTextSessionDisabled(disabled: boolean): void {
|
|
98
|
+
setSessionDisabled(disabled);
|
|
99
|
+
}
|
|
100
|
+
|
|
56
101
|
/**
|
|
57
102
|
* Singleton composable that wraps the Web Speech API (SpeechRecognition).
|
|
58
103
|
* All calls to useVoiceToText() return the same shared instance.
|
|
@@ -67,7 +112,8 @@ export function useVoiceToText(options: UseVoiceToTextOptions = {}): UseVoiceToT
|
|
|
67
112
|
const SpeechRecognitionCtor: typeof SpeechRecognition | null =
|
|
68
113
|
typeof window !== 'undefined' ? window.SpeechRecognition || window.webkitSpeechRecognition : null;
|
|
69
114
|
|
|
70
|
-
const
|
|
115
|
+
const sessionDisabledRef = getSessionDisabled();
|
|
116
|
+
const isSupported = computed(() => !!SpeechRecognitionCtor && !sessionDisabledRef.value);
|
|
71
117
|
|
|
72
118
|
// Initialize singleton once
|
|
73
119
|
if (!isInitialized && SpeechRecognitionCtor) {
|
|
@@ -98,6 +144,17 @@ export function useVoiceToText(options: UseVoiceToTextOptions = {}): UseVoiceToT
|
|
|
98
144
|
return;
|
|
99
145
|
}
|
|
100
146
|
|
|
147
|
+
// Latch on first network error: Edge exposes SpeechRecognition but the
|
|
148
|
+
// backend doesn't actually work for most users. Hide the feature for the
|
|
149
|
+
// rest of the session rather than surfacing a recurring toast.
|
|
150
|
+
if (event.error === 'network') {
|
|
151
|
+
// eslint-disable-next-line no-console
|
|
152
|
+
console.warn('[useVoiceToText] network error — disabling voice input for this session');
|
|
153
|
+
isListening.value = false;
|
|
154
|
+
setSessionDisabled(true);
|
|
155
|
+
return;
|
|
156
|
+
}
|
|
157
|
+
|
|
101
158
|
const message = ERROR_MESSAGES[event.error] || 'An error occurred with speech recognition.';
|
|
102
159
|
error.value = message;
|
|
103
160
|
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"sessionId":"33dfc84f-253d-421e-b0c6-adbf8fc2c94d","pid":84069,"procStart":"339429","acquiredAt":1777334296981}
|
|
@@ -1,54 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"env": {},
|
|
3
|
-
"permissions": {
|
|
4
|
-
"allow": [
|
|
5
|
-
"Bash(npm outdated:*)",
|
|
6
|
-
"Bash(npm install:*)",
|
|
7
|
-
"Bash(npx npm-check-updates)",
|
|
8
|
-
"Bash(npm audit:*)",
|
|
9
|
-
"Skill(superpowers:writing-plans)",
|
|
10
|
-
"Bash(cat:*)",
|
|
11
|
-
"Bash(mkdir:*)",
|
|
12
|
-
"Skill(superpowers:subagent-driven-development)",
|
|
13
|
-
"Bash(echo:*)",
|
|
14
|
-
"Bash(ping:*)",
|
|
15
|
-
"Bash(docker system:*)",
|
|
16
|
-
"Bash(docker buildx du:*)",
|
|
17
|
-
"Bash(npm view:*)",
|
|
18
|
-
"Bash(~/.npmrc)",
|
|
19
|
-
"Bash(npm run bundle-translation:*)",
|
|
20
|
-
"mcp__plugin_context7_context7__resolve-library-id",
|
|
21
|
-
"Bash(node:*)",
|
|
22
|
-
"Bash(npm:*)",
|
|
23
|
-
"Bash(find:*)",
|
|
24
|
-
"Bash(git -C /home/zknowles/repos/fe-shared-lib log --oneline --all)",
|
|
25
|
-
"Bash(wc:*)",
|
|
26
|
-
"mcp__plugin_context7_context7__query-docs",
|
|
27
|
-
"Skill(superpowers:test-driven-development)",
|
|
28
|
-
"Bash(git rev-parse:*)",
|
|
29
|
-
"Bash(npx tsc:*)",
|
|
30
|
-
"Bash(git add:*)",
|
|
31
|
-
"Bash(git commit:*)",
|
|
32
|
-
"Skill(superpowers:using-superpowers)",
|
|
33
|
-
"WebSearch",
|
|
34
|
-
"Bash(git checkout:*)",
|
|
35
|
-
"Bash(git -C /home/zknowles/repos/fe-shared-lib status)",
|
|
36
|
-
"Bash(git -C /home/zknowles/repos/fe-shared-lib diff package.json)",
|
|
37
|
-
"Bash(git -C /home/zknowles/repos/fe-shared-lib log --oneline -5)",
|
|
38
|
-
"Bash(git -C /home/zknowles/repos/fe-shared-lib diff vite.config.ts)",
|
|
39
|
-
"Bash(git -C /home/zknowles/repos/fe-shared-lib add package.json package-lock.json vite.config.ts)",
|
|
40
|
-
"Bash(git -C /home/zknowles/repos/fe-shared-lib commit -m \"$\\(cat <<''EOF''\nchore: upgrade vite 6→7, vue 3.5.15→3.5.26, storybook 9→10\n\n- Update vite to ^7.3.1\n- Update @vitejs/plugin-vue to ^6.0.3 \\(required for Vite 7\\)\n- Update vite-plugin-vue-devtools to ^7.7.2\n- Update vue to ^3.5.26\n- Remove vite-plugin-eslint \\(unmaintained, incompatible with Vite 7\\)\n- Update storybook to 10.2.1 \\(required for Vite 7 compatibility\\)\n- Update @storybook/vue3, @storybook/vue3-vite to 10.2.1\n- Update @storybook/addon-a11y, @storybook/addon-links, @storybook/addon-themes to 10.2.1\n- Update eslint-plugin-storybook to 10.2.1 \\(required for Storybook 10\\)\n\nCo-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>\nEOF\n\\)\")",
|
|
41
|
-
"Bash(git -C /home/zknowles/repos/fe-shared-lib log --oneline -3)",
|
|
42
|
-
"Bash(git show:*)",
|
|
43
|
-
"Bash(git stash:*)",
|
|
44
|
-
"Bash(chmod:*)",
|
|
45
|
-
"Bash(~/.claude/statusline.sh)",
|
|
46
|
-
"Bash(ls:*)",
|
|
47
|
-
"Bash(for v in 1.5.20-dts-upgrades 1.5.20-dts-upgrades-2 1.5.21 1.5.20-ast-icons 1.5.20-ast-icons-1 1.5.21-BestLogoIcons-3 1.5.22)",
|
|
48
|
-
"Bash(do)",
|
|
49
|
-
"Bash(done)",
|
|
50
|
-
"Bash(cp \"/home/zknowles/.claude/plugins/cache/designcrowd-plugins/experimental/0.19.0/docs/growth-it-runs-on-local-team-2026-04-09-thread.md\" \"/home/zknowles/repos/fe-shared-lib/docs/voice-to-text-discussion.md\")",
|
|
51
|
-
"Bash(cp -r \"/home/zknowles/.claude/plugins/cache/designcrowd-plugins/experimental/0.19.0/docs/growth-it-runs-on-local-team-2026-04-09-thread-attachments\" \"/home/zknowles/repos/fe-shared-lib/docs/voice-to-text-discussion-attachments\")"
|
|
52
|
-
]
|
|
53
|
-
}
|
|
54
|
-
}
|
|
@@ -1,278 +0,0 @@
|
|
|
1
|
-
---
|
|
2
|
-
name: playwright-cli
|
|
3
|
-
description: Automates browser interactions for web testing, form filling, screenshots, and data extraction. Use when the user needs to navigate websites, interact with web pages, fill forms, take screenshots, test web applications, or extract information from web pages.
|
|
4
|
-
allowed-tools: Bash(playwright-cli:*)
|
|
5
|
-
---
|
|
6
|
-
|
|
7
|
-
# Browser Automation with playwright-cli
|
|
8
|
-
|
|
9
|
-
## Quick start
|
|
10
|
-
|
|
11
|
-
```bash
|
|
12
|
-
# open new browser
|
|
13
|
-
playwright-cli open
|
|
14
|
-
# navigate to a page
|
|
15
|
-
playwright-cli goto https://playwright.dev
|
|
16
|
-
# interact with the page using refs from the snapshot
|
|
17
|
-
playwright-cli click e15
|
|
18
|
-
playwright-cli type "page.click"
|
|
19
|
-
playwright-cli press Enter
|
|
20
|
-
# take a screenshot (rarely used, as snapshot is more common)
|
|
21
|
-
playwright-cli screenshot
|
|
22
|
-
# close the browser
|
|
23
|
-
playwright-cli close
|
|
24
|
-
```
|
|
25
|
-
|
|
26
|
-
## Commands
|
|
27
|
-
|
|
28
|
-
### Core
|
|
29
|
-
|
|
30
|
-
```bash
|
|
31
|
-
playwright-cli open
|
|
32
|
-
# open and navigate right away
|
|
33
|
-
playwright-cli open https://example.com/
|
|
34
|
-
playwright-cli goto https://playwright.dev
|
|
35
|
-
playwright-cli type "search query"
|
|
36
|
-
playwright-cli click e3
|
|
37
|
-
playwright-cli dblclick e7
|
|
38
|
-
playwright-cli fill e5 "user@example.com"
|
|
39
|
-
playwright-cli drag e2 e8
|
|
40
|
-
playwright-cli hover e4
|
|
41
|
-
playwright-cli select e9 "option-value"
|
|
42
|
-
playwright-cli upload ./document.pdf
|
|
43
|
-
playwright-cli check e12
|
|
44
|
-
playwright-cli uncheck e12
|
|
45
|
-
playwright-cli snapshot
|
|
46
|
-
playwright-cli snapshot --filename=after-click.yaml
|
|
47
|
-
playwright-cli eval "document.title"
|
|
48
|
-
playwright-cli eval "el => el.textContent" e5
|
|
49
|
-
playwright-cli dialog-accept
|
|
50
|
-
playwright-cli dialog-accept "confirmation text"
|
|
51
|
-
playwright-cli dialog-dismiss
|
|
52
|
-
playwright-cli resize 1920 1080
|
|
53
|
-
playwright-cli close
|
|
54
|
-
```
|
|
55
|
-
|
|
56
|
-
### Navigation
|
|
57
|
-
|
|
58
|
-
```bash
|
|
59
|
-
playwright-cli go-back
|
|
60
|
-
playwright-cli go-forward
|
|
61
|
-
playwright-cli reload
|
|
62
|
-
```
|
|
63
|
-
|
|
64
|
-
### Keyboard
|
|
65
|
-
|
|
66
|
-
```bash
|
|
67
|
-
playwright-cli press Enter
|
|
68
|
-
playwright-cli press ArrowDown
|
|
69
|
-
playwright-cli keydown Shift
|
|
70
|
-
playwright-cli keyup Shift
|
|
71
|
-
```
|
|
72
|
-
|
|
73
|
-
### Mouse
|
|
74
|
-
|
|
75
|
-
```bash
|
|
76
|
-
playwright-cli mousemove 150 300
|
|
77
|
-
playwright-cli mousedown
|
|
78
|
-
playwright-cli mousedown right
|
|
79
|
-
playwright-cli mouseup
|
|
80
|
-
playwright-cli mouseup right
|
|
81
|
-
playwright-cli mousewheel 0 100
|
|
82
|
-
```
|
|
83
|
-
|
|
84
|
-
### Save as
|
|
85
|
-
|
|
86
|
-
```bash
|
|
87
|
-
playwright-cli screenshot
|
|
88
|
-
playwright-cli screenshot e5
|
|
89
|
-
playwright-cli screenshot --filename=page.png
|
|
90
|
-
playwright-cli pdf --filename=page.pdf
|
|
91
|
-
```
|
|
92
|
-
|
|
93
|
-
### Tabs
|
|
94
|
-
|
|
95
|
-
```bash
|
|
96
|
-
playwright-cli tab-list
|
|
97
|
-
playwright-cli tab-new
|
|
98
|
-
playwright-cli tab-new https://example.com/page
|
|
99
|
-
playwright-cli tab-close
|
|
100
|
-
playwright-cli tab-close 2
|
|
101
|
-
playwright-cli tab-select 0
|
|
102
|
-
```
|
|
103
|
-
|
|
104
|
-
### Storage
|
|
105
|
-
|
|
106
|
-
```bash
|
|
107
|
-
playwright-cli state-save
|
|
108
|
-
playwright-cli state-save auth.json
|
|
109
|
-
playwright-cli state-load auth.json
|
|
110
|
-
|
|
111
|
-
# Cookies
|
|
112
|
-
playwright-cli cookie-list
|
|
113
|
-
playwright-cli cookie-list --domain=example.com
|
|
114
|
-
playwright-cli cookie-get session_id
|
|
115
|
-
playwright-cli cookie-set session_id abc123
|
|
116
|
-
playwright-cli cookie-set session_id abc123 --domain=example.com --httpOnly --secure
|
|
117
|
-
playwright-cli cookie-delete session_id
|
|
118
|
-
playwright-cli cookie-clear
|
|
119
|
-
|
|
120
|
-
# LocalStorage
|
|
121
|
-
playwright-cli localstorage-list
|
|
122
|
-
playwright-cli localstorage-get theme
|
|
123
|
-
playwright-cli localstorage-set theme dark
|
|
124
|
-
playwright-cli localstorage-delete theme
|
|
125
|
-
playwright-cli localstorage-clear
|
|
126
|
-
|
|
127
|
-
# SessionStorage
|
|
128
|
-
playwright-cli sessionstorage-list
|
|
129
|
-
playwright-cli sessionstorage-get step
|
|
130
|
-
playwright-cli sessionstorage-set step 3
|
|
131
|
-
playwright-cli sessionstorage-delete step
|
|
132
|
-
playwright-cli sessionstorage-clear
|
|
133
|
-
```
|
|
134
|
-
|
|
135
|
-
### Network
|
|
136
|
-
|
|
137
|
-
```bash
|
|
138
|
-
playwright-cli route "**/*.jpg" --status=404
|
|
139
|
-
playwright-cli route "https://api.example.com/**" --body='{"mock": true}'
|
|
140
|
-
playwright-cli route-list
|
|
141
|
-
playwright-cli unroute "**/*.jpg"
|
|
142
|
-
playwright-cli unroute
|
|
143
|
-
```
|
|
144
|
-
|
|
145
|
-
### DevTools
|
|
146
|
-
|
|
147
|
-
```bash
|
|
148
|
-
playwright-cli console
|
|
149
|
-
playwright-cli console warning
|
|
150
|
-
playwright-cli network
|
|
151
|
-
playwright-cli run-code "async page => await page.context().grantPermissions(['geolocation'])"
|
|
152
|
-
playwright-cli tracing-start
|
|
153
|
-
playwright-cli tracing-stop
|
|
154
|
-
playwright-cli video-start
|
|
155
|
-
playwright-cli video-stop video.webm
|
|
156
|
-
```
|
|
157
|
-
|
|
158
|
-
## Open parameters
|
|
159
|
-
```bash
|
|
160
|
-
# Use specific browser when creating session
|
|
161
|
-
playwright-cli open --browser=chrome
|
|
162
|
-
playwright-cli open --browser=firefox
|
|
163
|
-
playwright-cli open --browser=webkit
|
|
164
|
-
playwright-cli open --browser=msedge
|
|
165
|
-
# Connect to browser via extension
|
|
166
|
-
playwright-cli open --extension
|
|
167
|
-
|
|
168
|
-
# Use persistent profile (by default profile is in-memory)
|
|
169
|
-
playwright-cli open --persistent
|
|
170
|
-
# Use persistent profile with custom directory
|
|
171
|
-
playwright-cli open --profile=/path/to/profile
|
|
172
|
-
|
|
173
|
-
# Start with config file
|
|
174
|
-
playwright-cli open --config=my-config.json
|
|
175
|
-
|
|
176
|
-
# Close the browser
|
|
177
|
-
playwright-cli close
|
|
178
|
-
# Delete user data for the default session
|
|
179
|
-
playwright-cli delete-data
|
|
180
|
-
```
|
|
181
|
-
|
|
182
|
-
## Snapshots
|
|
183
|
-
|
|
184
|
-
After each command, playwright-cli provides a snapshot of the current browser state.
|
|
185
|
-
|
|
186
|
-
```bash
|
|
187
|
-
> playwright-cli goto https://example.com
|
|
188
|
-
### Page
|
|
189
|
-
- Page URL: https://example.com/
|
|
190
|
-
- Page Title: Example Domain
|
|
191
|
-
### Snapshot
|
|
192
|
-
[Snapshot](.playwright-cli/page-2026-02-14T19-22-42-679Z.yml)
|
|
193
|
-
```
|
|
194
|
-
|
|
195
|
-
You can also take a snapshot on demand using `playwright-cli snapshot` command.
|
|
196
|
-
|
|
197
|
-
If `--filename` is not provided, a new snapshot file is created with a timestamp. Default to automatic file naming, use `--filename=` when artifact is a part of the workflow result.
|
|
198
|
-
|
|
199
|
-
## Browser Sessions
|
|
200
|
-
|
|
201
|
-
```bash
|
|
202
|
-
# create new browser session named "mysession" with persistent profile
|
|
203
|
-
playwright-cli -s=mysession open example.com --persistent
|
|
204
|
-
# same with manually specified profile directory (use when requested explicitly)
|
|
205
|
-
playwright-cli -s=mysession open example.com --profile=/path/to/profile
|
|
206
|
-
playwright-cli -s=mysession click e6
|
|
207
|
-
playwright-cli -s=mysession close # stop a named browser
|
|
208
|
-
playwright-cli -s=mysession delete-data # delete user data for persistent session
|
|
209
|
-
|
|
210
|
-
playwright-cli list
|
|
211
|
-
# Close all browsers
|
|
212
|
-
playwright-cli close-all
|
|
213
|
-
# Forcefully kill all browser processes
|
|
214
|
-
playwright-cli kill-all
|
|
215
|
-
```
|
|
216
|
-
|
|
217
|
-
## Local installation
|
|
218
|
-
|
|
219
|
-
In some cases user might want to install playwright-cli locally. If running globally available `playwright-cli` binary fails, use `npx playwright-cli` to run the commands. For example:
|
|
220
|
-
|
|
221
|
-
```bash
|
|
222
|
-
npx playwright-cli open https://example.com
|
|
223
|
-
npx playwright-cli click e1
|
|
224
|
-
```
|
|
225
|
-
|
|
226
|
-
## Example: Form submission
|
|
227
|
-
|
|
228
|
-
```bash
|
|
229
|
-
playwright-cli open https://example.com/form
|
|
230
|
-
playwright-cli snapshot
|
|
231
|
-
|
|
232
|
-
playwright-cli fill e1 "user@example.com"
|
|
233
|
-
playwright-cli fill e2 "password123"
|
|
234
|
-
playwright-cli click e3
|
|
235
|
-
playwright-cli snapshot
|
|
236
|
-
playwright-cli close
|
|
237
|
-
```
|
|
238
|
-
|
|
239
|
-
## Example: Multi-tab workflow
|
|
240
|
-
|
|
241
|
-
```bash
|
|
242
|
-
playwright-cli open https://example.com
|
|
243
|
-
playwright-cli tab-new https://example.com/other
|
|
244
|
-
playwright-cli tab-list
|
|
245
|
-
playwright-cli tab-select 0
|
|
246
|
-
playwright-cli snapshot
|
|
247
|
-
playwright-cli close
|
|
248
|
-
```
|
|
249
|
-
|
|
250
|
-
## Example: Debugging with DevTools
|
|
251
|
-
|
|
252
|
-
```bash
|
|
253
|
-
playwright-cli open https://example.com
|
|
254
|
-
playwright-cli click e4
|
|
255
|
-
playwright-cli fill e7 "test"
|
|
256
|
-
playwright-cli console
|
|
257
|
-
playwright-cli network
|
|
258
|
-
playwright-cli close
|
|
259
|
-
```
|
|
260
|
-
|
|
261
|
-
```bash
|
|
262
|
-
playwright-cli open https://example.com
|
|
263
|
-
playwright-cli tracing-start
|
|
264
|
-
playwright-cli click e4
|
|
265
|
-
playwright-cli fill e7 "test"
|
|
266
|
-
playwright-cli tracing-stop
|
|
267
|
-
playwright-cli close
|
|
268
|
-
```
|
|
269
|
-
|
|
270
|
-
## Specific tasks
|
|
271
|
-
|
|
272
|
-
* **Request mocking** [references/request-mocking.md](references/request-mocking.md)
|
|
273
|
-
* **Running Playwright code** [references/running-code.md](references/running-code.md)
|
|
274
|
-
* **Browser session management** [references/session-management.md](references/session-management.md)
|
|
275
|
-
* **Storage state (cookies, localStorage)** [references/storage-state.md](references/storage-state.md)
|
|
276
|
-
* **Test generation** [references/test-generation.md](references/test-generation.md)
|
|
277
|
-
* **Tracing** [references/tracing.md](references/tracing.md)
|
|
278
|
-
* **Video recording** [references/video-recording.md](references/video-recording.md)
|
|
@@ -1,87 +0,0 @@
|
|
|
1
|
-
# Request Mocking
|
|
2
|
-
|
|
3
|
-
Intercept, mock, modify, and block network requests.
|
|
4
|
-
|
|
5
|
-
## CLI Route Commands
|
|
6
|
-
|
|
7
|
-
```bash
|
|
8
|
-
# Mock with custom status
|
|
9
|
-
playwright-cli route "**/*.jpg" --status=404
|
|
10
|
-
|
|
11
|
-
# Mock with JSON body
|
|
12
|
-
playwright-cli route "**/api/users" --body='[{"id":1,"name":"Alice"}]' --content-type=application/json
|
|
13
|
-
|
|
14
|
-
# Mock with custom headers
|
|
15
|
-
playwright-cli route "**/api/data" --body='{"ok":true}' --header="X-Custom: value"
|
|
16
|
-
|
|
17
|
-
# Remove headers from requests
|
|
18
|
-
playwright-cli route "**/*" --remove-header=cookie,authorization
|
|
19
|
-
|
|
20
|
-
# List active routes
|
|
21
|
-
playwright-cli route-list
|
|
22
|
-
|
|
23
|
-
# Remove a route or all routes
|
|
24
|
-
playwright-cli unroute "**/*.jpg"
|
|
25
|
-
playwright-cli unroute
|
|
26
|
-
```
|
|
27
|
-
|
|
28
|
-
## URL Patterns
|
|
29
|
-
|
|
30
|
-
```
|
|
31
|
-
**/api/users - Exact path match
|
|
32
|
-
**/api/*/details - Wildcard in path
|
|
33
|
-
**/*.{png,jpg,jpeg} - Match file extensions
|
|
34
|
-
**/search?q=* - Match query parameters
|
|
35
|
-
```
|
|
36
|
-
|
|
37
|
-
## Advanced Mocking with run-code
|
|
38
|
-
|
|
39
|
-
For conditional responses, request body inspection, response modification, or delays:
|
|
40
|
-
|
|
41
|
-
### Conditional Response Based on Request
|
|
42
|
-
|
|
43
|
-
```bash
|
|
44
|
-
playwright-cli run-code "async page => {
|
|
45
|
-
await page.route('**/api/login', route => {
|
|
46
|
-
const body = route.request().postDataJSON();
|
|
47
|
-
if (body.username === 'admin') {
|
|
48
|
-
route.fulfill({ body: JSON.stringify({ token: 'mock-token' }) });
|
|
49
|
-
} else {
|
|
50
|
-
route.fulfill({ status: 401, body: JSON.stringify({ error: 'Invalid' }) });
|
|
51
|
-
}
|
|
52
|
-
});
|
|
53
|
-
}"
|
|
54
|
-
```
|
|
55
|
-
|
|
56
|
-
### Modify Real Response
|
|
57
|
-
|
|
58
|
-
```bash
|
|
59
|
-
playwright-cli run-code "async page => {
|
|
60
|
-
await page.route('**/api/user', async route => {
|
|
61
|
-
const response = await route.fetch();
|
|
62
|
-
const json = await response.json();
|
|
63
|
-
json.isPremium = true;
|
|
64
|
-
await route.fulfill({ response, json });
|
|
65
|
-
});
|
|
66
|
-
}"
|
|
67
|
-
```
|
|
68
|
-
|
|
69
|
-
### Simulate Network Failures
|
|
70
|
-
|
|
71
|
-
```bash
|
|
72
|
-
playwright-cli run-code "async page => {
|
|
73
|
-
await page.route('**/api/offline', route => route.abort('internetdisconnected'));
|
|
74
|
-
}"
|
|
75
|
-
# Options: connectionrefused, timedout, connectionreset, internetdisconnected
|
|
76
|
-
```
|
|
77
|
-
|
|
78
|
-
### Delayed Response
|
|
79
|
-
|
|
80
|
-
```bash
|
|
81
|
-
playwright-cli run-code "async page => {
|
|
82
|
-
await page.route('**/api/slow', async route => {
|
|
83
|
-
await new Promise(r => setTimeout(r, 3000));
|
|
84
|
-
route.fulfill({ body: JSON.stringify({ data: 'loaded' }) });
|
|
85
|
-
});
|
|
86
|
-
}"
|
|
87
|
-
```
|