Skip to content

Playwright is a framework for Web Testing and Automation. It allows testing Chromium, Firefox and WebKit with a single API.

chore(dashboard): styling (#40266)

Simon Knott63495241d1a5
diff --git a/.claude/skills/playwright-dev/SKILL.md b/.claude/skills/playwright-dev/SKILL.md
index 0c693d382e..8a9e0ca5f8 100644
--- a/.claude/skills/playwright-dev/SKILL.md
+++ b/.claude/skills/playwright-dev/SKILL.md
@@ -15,3 +15,4 @@ See [CLAUDE.md](../../../CLAUDE.md) for monorepo structure, build/test/lint comm
- [Vendor Dependencies & Bundling](vendor.md) — utilsBundle, coreBundle, babelBundle; adding vendored npm packages; DEPS.list; `check_deps`
- [Updating WebKit Safari Version](webkit-safari-version.md) — update the Safari version string in the WebKit user-agent
- [Bisecting Across Published Versions](bisect-published-versions.md) — reproduce regressions side-by-side from npm and diff `node_modules/playwright/lib/` between versions
+- [Dashboard](dashboard.md) - the UI powering the "playwright cli show" command, and how to work on it
diff --git a/.claude/skills/playwright-dev/dashboard.md b/.claude/skills/playwright-dev/dashboard.md
new file mode 100644
index 0000000000..adf51b4880
--- /dev/null
+++ b/.claude/skills/playwright-dev/dashboard.md
@@ -0,0 +1,37 @@
+# Developing Dashboard
+
+`packages/dashboard` contains the sourcecode behind `playwright cli show`,
+a dashboard that allow supervising agents while they use playwright cli.
+
+Important code paths:
+
+- `packages/dashboard` has the UI
+- `dashboardController.ts` has the backend
+- `show` section in `cli-client/program.ts`
+
+You can use Playwright CLI to look at the dashboard:
+
+```bash
+# start the dashboard server in the background
+npx playwright cli show --port=0
+
+# open it with Playwright CLI
+npx playwright cli open --session=dashboard localhost:PORT
+npx playwright cli snapshot
+
+# take screenshots to look at UI stuff
+npx playwright cli screenshot
+
+# take videos to showcase you work!
+npx playwright cli video-start video.webm
+
+# chapters are not everything - look at video-recording.md to learn about overlays, much more powerful! embrace creativity.
+npx playwright cli video-chapter "Chapter Title" --description="Details" --duration=2000
+npx playwright cli video-stop
+
+# afterwards, use ffmpeg to turn the video into mp4 for sharing.
+```
+
+For using Playwright CLI, refer to the `packages/playwright-core/src/tools/cli-client/skill/SKILL.md` skill.
+While developing in in this repo, it's important to use `npx playwright cli` instead of `playwright-cli`.
+
diff --git a/packages/dashboard/src/annotations.css b/packages/dashboard/src/annotations.css
index 0090d8e3d9..f9626f6d02 100644
--- a/packages/dashboard/src/annotations.css
+++ b/packages/dashboard/src/annotations.css
@@ -45,6 +45,16 @@
cursor: default;
}
+:root.dark-mode .annotation-toolbar {
+ border-color: var(--color-border-default);
+ box-shadow: 0 4px 16px rgba(0, 0, 0, 0.6);
+}
+
+:root.dark-mode .annotate-action-btn {
+ background: var(--color-neutral-muted);
+ border-color: var(--color-border-default);
+}
+
.annotate-action-btn {
height: 26px;
padding: 0 12px;
diff --git a/packages/dashboard/src/dashboard.tsx b/packages/dashboard/src/dashboard.tsx
index d50e89774e..06dcbdbd4b 100644
--- a/packages/dashboard/src/dashboard.tsx
+++ b/packages/dashboard/src/dashboard.tsx
@@ -37,15 +37,15 @@ export const Dashboard: React.FC = () => {
const [picking, setPicking] = React.useState(false);
const [recording, setRecording] = React.useState(false);
const [screenshotIcon, setScreenshotIcon] = React.useState<'device-camera' | 'clippy'>('device-camera');
- const [showInteractiveHint, setShowInteractiveHint] = React.useState(false);
+ const [flashTick, setFlashTick] = React.useState(0);
const displayRef = React.useRef<HTMLImageElement>(null);
const screenRef = React.useRef<HTMLDivElement>(null);
const toolbarRef = React.useRef<HTMLDivElement>(null);
const viewportMainRef = React.useRef<HTMLDivElement>(null);
const browserChromeRef = React.useRef<HTMLDivElement>(null);
+ const interactiveBtnRef = React.useRef<HTMLButtonElement>(null);
const moveThrottleRef = React.useRef(0);
- const hintTimerRef = React.useRef<ReturnType<typeof setTimeout>>(undefined);
const modeRef = React.useRef<Mode>('readonly');
const aspect = frame && frame.viewportWidth && frame.viewportHeight
@@ -81,18 +81,24 @@ export const Dashboard: React.FC = () => {
const annotating = mode === 'annotate';
React.useEffect(() => {
- if (interactive)
- setShowInteractiveHint(false);
- }, [interactive]);
-
- React.useEffect(() => {
- return () => clearTimeout(hintTimerRef.current);
- }, []);
+ if (flashTick === 0 || interactive)
+ return;
+ const btn = interactiveBtnRef.current;
+ if (!btn)
+ return;
+ btn.classList.remove('flash');
+ // Force a reflow so that re-adding the class restarts the animation.
+ void btn.offsetWidth;
+ btn.classList.add('flash');
+ const timer = setTimeout(() => btn.classList.remove('flash'), 2000);
+ return () => {
+ clearTimeout(timer);
+ btn.classList.remove('flash');
+ };
+ }, [flashTick, interactive]);
function flashInteractiveHint() {
- clearTimeout(hintTimerRef.current);
- setShowInteractiveHint(true);
- hintTimerRef.current = setTimeout(() => setShowInteractiveHint(false), 2000);
+ setFlashTick(tick => tick + 1);
}
const prevTabsRef = React.useRef<Tab[] | null>(null);
@@ -256,7 +262,8 @@ export const Dashboard: React.FC = () => {
{/* Toolbar */}
<div ref={toolbarRef} className='toolbar'>
<ToolbarButton
- className={'mode-toggle mode-interactive' + (showInteractiveHint ? ' flash' : '')}
+ ref={interactiveBtnRef}
+ className='mode-toggle mode-interactive'
title={interactive ? 'Disable interactive mode' : 'Enable interactive mode'}
icon='person'
toggled={interactive}
diff --git a/packages/dashboard/src/sessionSidebar.css b/packages/dashboard/src/sessionSidebar.css
index 592b1f1a99..9aaad8852d 100644
--- a/packages/dashboard/src/sessionSidebar.css
+++ b/packages/dashboard/src/sessionSidebar.css
@@ -283,7 +283,7 @@
.sidebar-tab-url {
font-size: 11px;
- color: var(--color-fg-subtle);
+ color: var(--color-fg-muted);
line-height: 1.2;
overflow: hidden;
text-overflow: ellipsis;
@@ -293,12 +293,21 @@
.sidebar-tab-close {
margin-left: auto;
align-self: center;
+ opacity: 0;
+ pointer-events: none;
+ transition: opacity 120ms ease;
+}
+
+.sidebar-tab:hover .sidebar-tab-close,
+.sidebar-tab-close:focus-visible {
+ opacity: 1;
+ pointer-events: auto;
}
.sidebar-tab-close .codicon {
font-size: 12px;
}
-.sidebar-tab-close:hover {
+.sidebar-tab-close:not(:disabled):hover {
background: var(--color-neutral-muted);
}
diff --git a/packages/playwright-core/src/tools/dashboard/dashboardController.ts b/packages/playwright-core/src/tools/dashboard/dashboardController.ts
index 06a5638185..b13c2173b0 100644
--- a/packages/playwright-core/src/tools/dashboard/dashboardController.ts
+++ b/packages/playwright-core/src/tools/dashboard/dashboardController.ts
@@ -574,6 +574,8 @@ async function faviconUrl(page: api.Page): Promise<string | undefined> {
if (!response.ok)
return undefined;
const blob = await response.blob();
+ if (!blob.type.startsWith('image/'))
+ return undefined;
return await new Promise<string>((resolve, reject) => {
const reader = new FileReader();
reader.onloadend = () => resolve(reader.result as string);