Playwright is a framework for Web Testing and Automation. It allows testing Chromium, Firefox and WebKit with a single API.
TypeScript automationchromechromiume2e-testingelectronend-to-end-testingfirefoxjavascriptplaywrighttesttest-automationtestingtesting-toolswebwebkit
chore(dashboard): sidebar (#40243)
Simon Knottb793f8486e04
diff --git a/packages/dashboard/src/dashboard.css b/packages/dashboard/src/dashboard.cssindex 037ba9e86c..3f719afa40 100644--- a/packages/dashboard/src/dashboard.css+++ b/packages/dashboard/src/dashboard.css@@ -24,22 +24,6 @@overflow: hidden;}-/* -- Tab bar -- */-.tabbar {- display: flex;- align-items: flex-end;- height: 39px;- min-height: 39px;- padding: 0 4px;- user-select: none;- position: relative;- z-index: 110;-}--:root.light-mode .tabbar {- background: var(--color-canvas-overlay);-}-.dashboard-view.interactive .toolbar::after {content: '';position: absolute;@@ -108,31 +92,6 @@}}-.tabbar-back {- display: flex;- align-items: center;- justify-content: center;- height: 34px;- align-self: flex-end;- color: var(--color-fg-muted);- text-decoration: none;- border-radius: 8px;- margin-right: 4px;- font-size: 11px;- text-transform: uppercase;- font-weight: 600;-}--.tabbar-back:hover {- background: var(--color-canvas-overlay);- color: var(--color-fg-default);-}--.tabbar-back svg {- width: 16px;- height: 16px;-}-.interactive .toolbar .toolbar-button > .codicon {color: var(--color-fg-on-emphasis);}@@ -141,242 +100,6 @@color: var(--color-fg-on-emphasis);}-.tabstrip {- display: flex;- align-items: flex-end;- gap: 1px;- overflow-x: auto;- scrollbar-width: none;- min-width: 0;- padding-top: 8px;-}--.tabstrip::-webkit-scrollbar {- display: none;-}--.tab {- display: flex;- align-items: center;- gap: 6px;- height: 34px;- padding: 0 10px;- background: var(--color-canvas-subtle);- color: var(--color-fg-muted);- font-size: 13px;- cursor: pointer;- white-space: nowrap;- max-width: 200px;- min-width: 48px;- border-radius: 8px 8px 0 0;- user-select: none;- flex-shrink: 0;-}--.tab:hover {- background: var(--color-canvas-overlay);- color: var(--color-fg-muted);-}--.tab.active {- background: var(--color-canvas-overlay);- color: var(--color-fg-default);-}--:root.light-mode .tab {- background: transparent;-}-:root.light-mode .tab:hover {- background: var(--color-canvas-subtle);-}-:root.light-mode .tab.active {- background: var(--color-canvas-subtle);-}--.dashboard-view.interactive .tab.active {- background: rgb(var(--interactive-orange));- color: var(--color-fg-on-emphasis);-}--.dashboard-view.annotate .tab.active {- background: rgb(var(--annotate-blue));- color: var(--color-fg-on-emphasis);-}--.tab-label {- overflow: hidden;- text-overflow: ellipsis;- pointer-events: none;-}--.tab-favicon {- width: 14px;- height: 14px;- flex-shrink: 0;- display: flex;- align-items: center;- justify-content: center;- font-size: 9px;- font-weight: 700;-}--.tab-favicon.placeholder {- background: var(--color-fg-subtle);- border-radius: 2px;-}--.tab-close {- width: 16px;- height: 16px;- border-radius: 50%;- opacity: 0;- margin-left: auto;-}--.tab-close svg {- width: 10px;- height: 10px;-}--.tab:hover .tab-close,-.tab.active .tab-close {- opacity: 1;-}--.tab-close:hover {- background: var(--color-neutral-muted);-}--.new-tab-btn {- width: 28px;- height: 34px;- border-radius: 8px;- margin-left: 4px;- align-self: flex-end;-}--.new-tab-btn:hover {- background: var(--color-canvas-overlay);-}--.new-tab-btn svg {- width: 16px;- height: 16px;-}--.interactive-controls {- margin-left: auto;- margin-right: 0;- align-self: center;- display: inline-flex;- align-items: center;- gap: 8px;- padding: 4px 2px 4px 8px;-}--.segmented-control {- position: relative;- height: 28px;- border-radius: 999px;- padding: 2px;- display: inline-flex;- align-items: center;- gap: 0;- background: var(--color-neutral-subtle);-}--.segmented-control::before {- content: '';- position: absolute;- top: 2px;- bottom: 2px;- left: 2px;- width: calc(50% - 2px);- border-radius: 999px;- background: var(--color-neutral-muted);- transform: translateX(0);- transition: transform 180ms cubic-bezier(0.2, 0.8, 0.2, 1), background-color 180ms ease;-}--.segmented-control.interactive::before {- transform: translateX(100%);- background: rgb(var(--interactive-orange) / 0.95);-}--.segmented-control-option {- position: relative;- z-index: 1;- width: 96px;- height: 24px;- border-radius: 999px;- padding: 0;- border: none;- background: transparent;- color: var(--color-fg-muted);- font-size: 11px;- font-weight: 600;- letter-spacing: 0.03em;- text-transform: uppercase;- white-space: nowrap;- display: flex;- align-items: center;- justify-content: center;- line-height: 1;-}--.segmented-control-option:hover:not(:disabled) {- background: transparent;-}--.segmented-control-option.active {- color: var(--color-fg-default);-}--.segmented-control-option:disabled {- opacity: 0.7;- cursor: default;-}--.dashboard-view.interactive .segmented-control {- background: rgb(255 255 255 / 0.2);-}--.dashboard-view.interactive .segmented-control::before {- background: rgb(255 255 255 / 0.32);-}--:root.light-mode .dashboard-view.interactive .segmented-control {- background: rgb(0 0 0 / 0.1);-}-:root.light-mode .dashboard-view.interactive .segmented-control::before {- background: rgb(0 0 0 / 0.12);-}-:root.light-mode .dashboard-view.interactive .toolbar .nav-btn:hover {- background: rgba(255, 255, 255, 0.18);-}-:root.light-mode .dashboard-view.interactive .toolbar .nav-btn:active {- background: rgba(255, 255, 255, 0.25);-}--.dashboard-view.interactive .segmented-control.interactive::before {- background: rgb(var(--interactive-orange) / 0.95);-}--.dashboard-view.interactive .segmented-control-option {- color: rgb(255 255 255 / 0.74);-}--.dashboard-view.interactive .segmented-control-option.active {- color: var(--color-fg-on-emphasis);-}--:root.light-mode .dashboard-view.interactive .segmented-control-option {- color: var(--color-fg-muted);-}-:root.light-mode .dashboard-view.interactive .segmented-control-option.active {- color: var(--color-fg-on-emphasis);-}-/* -- Toolbar -- */.toolbar {display: flex;diff --git a/packages/dashboard/src/dashboard.tsx b/packages/dashboard/src/dashboard.tsxindex 4fc39df4bb..68e88ed396 100644--- a/packages/dashboard/src/dashboard.tsx+++ b/packages/dashboard/src/dashboard.tsx@@ -16,12 +16,11 @@import React from 'react';import './dashboard.css';-import { navigate, DashboardClientContext } from './index';+import { DashboardClientContext } from './index';import { asLocator } from '@isomorphic/locatorGenerators';import { TraceModel } from '@isomorphic/trace/traceModel';import { SplitView } from '@web/components/splitView';-import { ChevronLeftIcon, ChevronRightIcon, CloseIcon, PlusIcon, ReloadIcon } from './icons';-import { SettingsButton } from './settingsView';+import { ChevronLeftIcon, ChevronRightIcon, ReloadIcon } from './icons';import { Annotations, getImageLayout, clientToViewport } from './annotations';import { ToolbarButton } from '@web/components/toolbarButton';import { TabbedPaneTabModel, TabbedPane } from '@web/components/tabbedPane';@@ -34,16 +33,6 @@ import type { Tab, DashboardChannelEvents } from './dashboardChannel';import { HighlightedElement } from '@trace-viewer/ui/snapshotTab';import { TraceModelContext } from '@trace-viewer/ui/traceModelContext';-function tabFavicon(url: string): string {- try {- const u = new URL(url);- const host = u.hostname.replace(/^www\./, '');- return host ? host[0].toUpperCase() : '';- } catch {- return '';- }-}-const BUTTONS = ['left', 'middle', 'right'] as const;type Mode = 'readonly' | 'interactive' | 'annotate';@@ -52,7 +41,7 @@ export const Dashboard: React.FC<{autoInteractive?: boolean;onAutoInteractiveConsumed?: () => void;}> = ({ browser, autoInteractive, onAutoInteractiveConsumed }) => {- const [sidebarLocation, setSidebarLocation] = useSetting<'bottom' | 'right'>('propertiesSidebarLocation', 'bottom');+ const [sidebarLocation] = useSetting<'bottom' | 'right'>('propertiesSidebarLocation', 'bottom');const client = React.useContext(DashboardClientContext);const [mode, setMode] = React.useState<Mode>('readonly');const [sidebarVisible, setSidebarVisible] = useSetting<boolean>('propertiesSidebarVisible', false);@@ -77,7 +66,6 @@ export const Dashboard: React.FC<{const displayRef = React.useRef<HTMLImageElement>(null);const screenRef = React.useRef<HTMLDivElement>(null);- const tabbarRef = React.useRef<HTMLDivElement>(null);const toolbarRef = React.useRef<HTMLDivElement>(null);const moveThrottleRef = React.useRef(0);const hintTimerRef = React.useRef<ReturnType<typeof setTimeout>>(undefined);@@ -125,11 +113,10 @@ export const Dashboard: React.FC<{if (modeRef.current === 'annotate')return;setFrame(params);- const tabbar = tabbarRef.current;const toolbar = toolbarRef.current;- if (!resized && tabbar && toolbar && params.viewportWidth && params.viewportHeight) {+ if (!resized && toolbar && params.viewportWidth && params.viewportHeight) {resized = true;- const chromeHeight = tabbar.offsetHeight + toolbar.offsetHeight;+ const chromeHeight = toolbar.offsetHeight;const extraW = window.outerWidth - window.innerWidth;const extraH = window.outerHeight - window.innerHeight;const targetW = Math.min(params.viewportWidth + extraW, screen.availWidth);@@ -160,7 +147,6 @@ export const Dashboard: React.FC<{client.off('tabs', onTabs);client.off('frame', onFrame);client.off('elementPicked', onElementPicked);- client.detach({ browser }).catch(() => {});setContext(undefined);setTabs(null);setFrame(undefined);@@ -379,48 +365,6 @@ export const Dashboard: React.FC<{minSidebarSize={300}settingName='devtoolsInspector'main={<div className={'dashboard-view' + (interactive ? ' interactive' : '') + (annotating ? ' annotate' : '')}>- {/* Tab bar */}- <div ref={tabbarRef} className='tabbar'>- <a className='tabbar-back' href='#' title='Back to sessions' onClick={e => { e.preventDefault(); navigate('#'); }}>- <ChevronLeftIcon />- Sessions- </a>- <div id='tabstrip' className='tabstrip' role='tablist'>- {tabs?.map(tab => (- <div- key={tab.page}- className={'tab' + (tab.selected ? ' active' : '')}- role='tab'- aria-selected={tab.selected}- title={tab.url || ''}- onClick={() => client?.selectTab({ browser, context: tab.context, page: tab.page })}- >- {tab.faviconUrl- ? <img className='tab-favicon' src={tab.faviconUrl} alt='' aria-hidden='true' />- : <span className='tab-favicon placeholder' aria-hidden='true'>{tabFavicon(tab.url)}</span>}- <span className='tab-label'>{tab.title || 'New Tab'}</span>- <button- className='tab-close'- title='Close tab'- onClick={e => {- e.stopPropagation();- client?.closeTab({ browser, context: tab.context, page: tab.page });- }}- >- <CloseIcon />- </button>- </div>- ))}- </div>- <button id='new-tab-btn' className='new-tab-btn' title='New Tab' onClick={() => {- if (context)- client?.newTab({ browser, context });- }}>- <PlusIcon />- </button>- <div className='interactive-controls' />- </div>-{/* Toolbar */}<div ref={toolbarRef} className='toolbar'><button className='nav-btn' title='Back' aria-disabled={!interactive || undefined} onClick={() => {@@ -603,9 +547,6 @@ export const Dashboard: React.FC<{tabs={inspectorTabs}selectedTab={selectedSidebarTab}setSelectedTab={setSelectedSidebarTab}- rightToolbar={[- <SettingsButton key='settings' sidebarLocation={sidebarLocation} setSidebarLocation={setSidebarLocation} />,- ]}mode='default'/>}/>diff --git a/packages/dashboard/src/grid.tsx b/packages/dashboard/src/grid.tsxdeleted file mode 100644index fe505e80ca..0000000000--- a/packages/dashboard/src/grid.tsx+++ /dev/null@@ -1,180 +0,0 @@-/**- * Copyright (c) Microsoft Corporation.- *- * Licensed under the Apache License, Version 2.0 (the "License");- * you may not use this file except in compliance with the License.- * You may obtain a copy of the License at- *- * http://www.apache.org/licenses/LICENSE-2.0- *- * Unless required by applicable law or agreed to in writing, software- * distributed under the License is distributed on an "AS IS" BASIS,- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.- * See the License for the specific language governing permissions and- * limitations under the License.- */--import React from 'react';-import './grid.css';-import { navigate, DashboardClientContext } from './index';-import { Screencast } from './screencast';-import { SettingsButton } from './settingsView';--import type { BrowserDescriptor } from '../../playwright-core/src/serverRegistry';-import type { Tab, DashboardChannelEvents } from './dashboardChannel';-import type { SessionModel, SessionStatus } from './sessionModel';--export const Grid: React.FC<{ model: SessionModel }> = ({ model }) => {- const [expandedWorkspaces, setExpandedWorkspaces] = React.useState<Set<string>>(new Set());- const sessions = model.sessions;- const clientInfo = model.clientInfo;-- function toggleWorkspace(workspace: string) {- setExpandedWorkspaces(prev => {- const next = new Set(prev);- if (next.has(workspace))- next.delete(workspace);- else- next.add(workspace);- return next;- });- }-- const workspaceGroups = React.useMemo(() => {- const groups = new Map<string, SessionStatus[]>();- for (const session of sessions) {- const key = session.workspaceDir || 'Global';- let list = groups.get(key);- if (!list) {- list = [];- groups.set(key, list);- }- list.push(session);- }- for (const list of groups.values())- list.sort((a, b) => a.title.localeCompare(b.title));-- // Current workspace first, then alphabetical.- const currentWorkspace = clientInfo?.workspaceDir || 'Global';- const entries = [...groups.entries()];- const current = entries.filter(([key]) => key === currentWorkspace);- const other = entries.filter(([key]) => key !== currentWorkspace).sort((a, b) => a[0].localeCompare(b[0]));- return [...current, ...other];- }, [sessions, clientInfo?.workspaceDir]);-- return (<div className='grid-view'>- <div className='grid-toolbar'>- <SettingsButton />- </div>- <div className='grid-content'>- {model.loading && <div className='grid-loading'>Loading sessions...</div>}- {!model.loading && sessions.length === 0 && <div className='grid-empty'>No sessions found.</div>}-- <div className='workspace-list'>- {workspaceGroups.map(([workspace, entries], index) => {- const isFirst = index === 0;- const isExpanded = isFirst || expandedWorkspaces.has(workspace);- return (- <div key={workspace} className='workspace-group'>- <div- className={'workspace-header' + (isFirst ? '' : ' collapsible')}- onClick={isFirst ? undefined : () => toggleWorkspace(workspace)}- >- {!isFirst && (- <svg className={'workspace-chevron' + (isExpanded ? ' expanded' : '')} viewBox='0 0 24 24' fill='none' stroke='currentColor' strokeWidth='2' strokeLinecap='round' strokeLinejoin='round'>- <polyline points='9 18 15 12 9 6'/>- </svg>- )}- <span className='workspace-name'>{workspace.split('/').pop() || workspace}</span>- <span className='workspace-path'>— {workspace}</span>- </div>- {isExpanded && (- <div className='session-chips'>- {entries.map(session => <SessionChip key={session.browser.guid} descriptor={session} canConnect={session.canConnect} visible={isExpanded} model={model} />)}- </div>- )}- </div>- );- })}- </div>- </div>- </div>);-};--const SessionChip: React.FC<{ descriptor: BrowserDescriptor; canConnect: boolean; visible: boolean; model: SessionModel }> = ({ descriptor, canConnect, visible, model }) => {- const href = '#session=' + encodeURIComponent(descriptor.browser.guid);- const client = React.useContext(DashboardClientContext);- const browser = descriptor.browser.guid;- const attached = canConnect && visible && !!client;- const [selectedTab, setSelectedTab] = React.useState<Tab | undefined>();-- React.useEffect(() => {- if (!attached || !client)- return;- const onTabs = (params: DashboardChannelEvents['tabs']) => {- if (params.target.browser !== browser)- return;- setSelectedTab(params.tabs.find(t => t.selected));- };- client.on('tabs', onTabs);- client.attach({ browser }).catch(() => {});- return () => {- client.off('tabs', onTabs);- client.detach({ browser }).catch(() => {});- };- }, [attached, client, browser]);-- const chipTitle = selectedTab ? `[${descriptor.title}] ${selectedTab.url} \u2014 ${selectedTab.title}` : descriptor.title;-- return (- <a className={'session-chip' + (canConnect ? '' : ' disconnected')} aria-disabled={!canConnect} href={canConnect ? href : undefined} title={chipTitle} onClick={e => {- e.preventDefault();- if (canConnect)- navigate(href);- }}>- <div className='session-chip-header'>- <div className={'session-status-dot ' + (canConnect ? 'open' : 'closed')} />- <span className='session-chip-name'>- {selectedTab ? <>[{descriptor.title}] {selectedTab.url} <span className='session-chip-title'>— {selectedTab.title}</span></> : descriptor.title}- </span>- {canConnect && (- <button- className='session-chip-action'- title='Close session'- onClick={e => {- e.preventDefault();- e.stopPropagation();- void model.closeSession(descriptor);- }}- >- <svg viewBox='0 0 12 12' fill='none' stroke='currentColor' strokeWidth='1.5' strokeLinecap='round'>- <line x1='2' y1='2' x2='10' y2='10'/>- <line x1='10' y1='2' x2='2' y2='10'/>- </svg>- </button>- )}- {!canConnect && (- <button- className='session-chip-action'- title='Delete session data'- onClick={e => {- e.preventDefault();- e.stopPropagation();- void model.deleteSessionData(descriptor);- }}- >- <svg viewBox='0 0 16 16' fill='none' stroke='currentColor' strokeWidth='1.2' strokeLinecap='round' strokeLinejoin='round'>- <path d='M2 4h12'/>- <path d='M5 4V3a1 1 0 0 1 1-1h4a1 1 0 0 1 1 1v1'/>- <path d='M4 4l.8 9a1 1 0 0 0 1 .9h4.4a1 1 0 0 0 1-.9L12 4'/>- </svg>- </button>- )}- </div>- <div className='screencast-container'>- {attached && client && <Screencast client={client} browser={browser} />}- {!canConnect && <div className='screencast-placeholder'>Session closed</div>}- </div>- </a>- );-};diff --git a/packages/dashboard/src/index.tsx b/packages/dashboard/src/index.tsxindex 95e3c8abbb..6915398202 100644--- a/packages/dashboard/src/index.tsx+++ b/packages/dashboard/src/index.tsx@@ -21,9 +21,10 @@ import '@web/common.css';import './common.css';import { applyTheme } from '@web/theme';import { Dashboard } from './dashboard';-import { Grid } from './grid';import { SessionModel } from './sessionModel';import { DashboardClient } from './dashboardClient';+import { SessionSidebar } from './sessionSidebar';+import { SplitView } from '@web/components/splitView';import type { DashboardChannelEvents } from './dashboardChannel';import type { DashboardClientChannel } from './dashboardClient';@@ -54,8 +55,8 @@ if (document.hidden)pushVisibility();const App: React.FC = () => {- const [, setRevision] = React.useState(0);- const [sessionGuid, setSessionGuid] = React.useState<string | undefined>(parseHash);+ const [revision, setRevision] = React.useState(0);+ const [sessionGuid, setSessionGuid] = React.useState<string | undefined>(parseHash());const [autoInteractiveBrowser, setAutoInteractiveBrowser] = React.useState<string | undefined>();React.useEffect(() => model.subscribe(() => setRevision(r => r + 1)), []);@@ -76,15 +77,58 @@ const App: React.FC = () => {return () => client.off('pickLocator', onPickLocator);}, []);- const content = sessionGuid- ? <Dashboard- browser={sessionGuid}- autoInteractive={autoInteractiveBrowser === sessionGuid}- onAutoInteractiveConsumed={() => setAutoInteractiveBrowser(undefined)}- />- : <Grid model={model} />;+ React.useEffect(() => {+ if (!sessionGuid || model.loading)+ return;+ const session = model.sessionByGuid(sessionGuid);+ if (!session || !session.canConnect)+ navigate('#');+ }, [sessionGuid, revision]);++ React.useEffect(() => {+ if (sessionGuid || model.loading)+ return;+ const firstOpenSession = model.sessions.find(session => session.canConnect);+ if (firstOpenSession)+ navigate('#session=' + encodeURIComponent(firstOpenSession.browser.guid));+ }, [sessionGuid, revision]);++ const activeSession = sessionGuid ? model.sessionByGuid(sessionGuid) : undefined;+ const activeBrowser = activeSession?.canConnect ? activeSession.browser.guid : undefined;- return <DashboardClientContext.Provider value={client}>{content}</DashboardClientContext.Provider>;+ return <DashboardClientContext.Provider value={client}>+ <SplitView+ orientation='horizontal'+ sidebarIsFirst+ sidebarSize={320}+ minSidebarSize={220}+ settingName='dashboardSessionSidebar'+ sidebar={<SessionSidebar+ model={model}+ activeBrowser={activeBrowser}+ onSelectTab={tab => {+ if (sessionGuid !== tab.browser)+ navigate('#session=' + encodeURIComponent(tab.browser));+ void client.selectTab({ browser: tab.browser, context: tab.context, page: tab.page });+ }}+ onCloseTab={tab => { void client.closeTab({ browser: tab.browser, context: tab.context, page: tab.page }); }}+ onNewTab={(browser, context) => {+ if (sessionGuid !== browser)+ navigate('#session=' + encodeURIComponent(browser));+ void client.newTab({ browser, context });+ }}+ />}+ main={<div className='dashboard-shell-main'>+ {activeBrowser+ ? <Dashboard+ browser={activeBrowser}+ autoInteractive={autoInteractiveBrowser === activeBrowser}+ onAutoInteractiveConsumed={() => setAutoInteractiveBrowser(undefined)}+ />+ : <div className='dashboard-shell-empty'>Select an open tab in the sidebar.</div>}+ </div>}+ />+ </DashboardClientContext.Provider>;};ReactDOM.createRoot(document.querySelector('#root')!).render(<App />);diff --git a/packages/dashboard/src/sessionSidebar.css b/packages/dashboard/src/sessionSidebar.cssnew file mode 100644index 0000000000..681f8e9033--- /dev/null+++ b/packages/dashboard/src/sessionSidebar.css@@ -0,0 +1,302 @@+/**+ * Copyright (c) Microsoft Corporation.+ *+ * Licensed under the Apache License, Version 2.0 (the "License");+ * you may not use this file except in compliance with the License.+ * You may obtain a copy of the License at+ *+ * http://www.apache.org/licenses/LICENSE-2.0+ *+ * Unless required by applicable law or agreed to in writing, software+ * distributed under the License is distributed on an "AS IS" BASIS,+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.+ * See the License for the specific language governing permissions and+ * limitations under the License.+ */++.dashboard-shell-sidebar {+ width: 100%;+ background: var(--color-canvas-default);+ display: flex;+ flex-direction: column;+ overflow: hidden;+}++.dashboard-shell-sidebar-header {+ height: 40px;+ min-height: 40px;+ display: flex;+ align-items: center;+ justify-content: space-between;+ padding: 0 8px;+ border-bottom: 1px solid var(--color-border-muted);+}++.dashboard-shell-sidebar-title {+ margin: 0;+ font-size: 12px;+ font-weight: 600;+ text-transform: uppercase;+ color: var(--color-fg-muted);+ letter-spacing: 0.03em;+}++.dashboard-shell-sidebar-content {+ flex: 1;+ overflow: auto;+ padding: 0;+}++.sidebar-empty {+ color: var(--color-fg-subtle);+ font-size: 13px;+ padding: 8px 12px;+}++.dashboard-shell-main {+ flex: 1;+ display: flex;+ flex-direction: column;+ height: 100%;+ min-width: 0;+ min-height: 0;+}++.dashboard-shell-main > .vbox {+ flex: 1;+ min-height: 0;+}++.dashboard-shell-empty {+ width: 100%;+ height: 100%;+ display: flex;+ align-items: center;+ justify-content: center;+ color: var(--color-fg-muted);+ font-size: 14px;+}++.workspace-group {+ margin: 0;+}++.workspace-header {+ margin: 0;+ padding: 8px 12px 4px;+ font-size: 12px;+ color: var(--color-fg-muted);+ font-weight: 400;+}++.workspace-path-full {+ display: block;+ min-width: 0;+ overflow: hidden;+ text-overflow: ellipsis;+ white-space: nowrap;+ direction: rtl;+ text-align: left;+ unicode-bidi: plaintext;+}++.sidebar-session-list {+ display: flex;+ flex-direction: column;+ gap: 0;+}++.session-chip.sidebar-session {+ border: none;+ border-radius: 0;+ background: transparent;+ overflow: hidden;+ cursor: default;+ position: relative;+}++.sidebar-session-row {+ width: 100%;+ display: flex;+ align-items: center;+ gap: 8px;+ text-align: left;+ padding: 8px 4px 4px 8px;+}++.session-browser-icon-wrap {+ position: relative;+ width: 18px;+ height: 18px;+ border-radius: 50%;+ flex-shrink: 0;+}++.session-browser-icon {+ width: 100%;+ height: 100%;+ border-radius: 50%;+ background: var(--color-fg-subtle);+ color: var(--color-canvas-default);+ display: flex;+ align-items: center;+ justify-content: center;+ font-size: 10px;+ font-weight: 700;+ transition: opacity 120ms ease;+}++.session-browser-close {+ position: absolute;+ inset: 0;+ border-radius: 50%;+ opacity: 0;+ pointer-events: none;+ transition: opacity 120ms ease;+}++.session-browser-close .codicon {+ font-size: 10px;+}++.session-browser-icon-wrap:hover .session-browser-icon {+ opacity: 0;+}++.session-browser-icon-wrap:hover .session-browser-close {+ opacity: 1;+ pointer-events: auto;+}++.session-browser-close:hover {+ background: var(--color-neutral-muted);+}++.session-chip-name {+ font-size: 13px;+ font-weight: 600;+ color: var(--color-fg-default);+ overflow: hidden;+ text-overflow: ellipsis;+ white-space: nowrap;+ min-width: 0;+}++.sidebar-session-row-actions {+ margin-left: auto;+ display: flex;+ align-items: center;+ gap: 4px;+}++.sidebar-session-new-tab .codicon {+ font-size: 12px;+}++.sidebar-session-new-tab:hover:not(:disabled) {+ background: var(--color-neutral-muted);+}++.sidebar-tab-list {+ padding: 0;+ display: flex;+ flex-direction: column;+ gap: 0;+}++.sidebar-tabs-loading,+.sidebar-tabs-empty {+ color: var(--color-fg-subtle);+ font-size: 12px;+ padding: 4px 12px 6px 38px;+}++.sidebar-tab {+ display: flex;+ align-items: center;+ gap: 6px;+ font-size: 12px;+ color: var(--color-fg-muted);+ border-radius: 0;+ padding: 4px 4px 4px 24px;+}++.sidebar-tab:hover {+ background: var(--color-neutral-muted);+}++.sidebar-tab.active {+ background: var(--color-neutral-subtle);+ color: var(--color-fg-default);+}++.sidebar-tab-favicon {+ width: 14px;+ height: 14px;+ flex-shrink: 0;+ margin-top: 0;+ align-self: center;+}++.sidebar-tab-select {+ display: flex;+ align-items: center;+ gap: 6px;+ flex: 1;+ min-width: 0;+ cursor: pointer;+}++.sidebar-tab-select:focus-visible {+ outline: 1px solid var(--color-accent-emphasis);+ outline-offset: 2px;+}++.sidebar-tab-favicon.placeholder {+ border-radius: 2px;+ background: var(--color-fg-subtle);+ color: var(--color-canvas-default);+ display: flex;+ align-items: center;+ justify-content: center;+ font-size: 9px;+ font-weight: 700;+}++.sidebar-tab-text {+ display: flex;+ flex-direction: column;+ gap: 1px;+ flex: 1;+ min-width: 0;+}++.sidebar-tab-title {+ color: var(--color-fg-default);+ line-height: 1.2;+ overflow: hidden;+ text-overflow: ellipsis;+ white-space: nowrap;+}++.sidebar-tab-url {+ font-size: 11px;+ color: var(--color-fg-subtle);+ line-height: 1.2;+ overflow: hidden;+ text-overflow: ellipsis;+ white-space: nowrap;+}++.sidebar-tab-close {+ margin-left: auto;+ align-self: center;+}++.sidebar-tab-close .codicon {+ font-size: 12px;+}++.sidebar-tab-close:hover {+ background: var(--color-neutral-muted);+}diff --git a/packages/dashboard/src/sessionSidebar.tsx b/packages/dashboard/src/sessionSidebar.tsxnew file mode 100644index 0000000000..1c92a8e463--- /dev/null+++ b/packages/dashboard/src/sessionSidebar.tsx@@ -0,0 +1,209 @@+/**+ * Copyright (c) Microsoft Corporation.+ *+ * Licensed under the Apache License, Version 2.0 (the "License");+ * you may not use this file except in compliance with the License.+ * You may obtain a copy of the License at+ *+ * http://www.apache.org/licenses/LICENSE-2.0+ *+ * Unless required by applicable law or agreed to in writing, software+ * distributed under the License is distributed on an "AS IS" BASIS,+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.+ * See the License for the specific language governing permissions and+ * limitations under the License.+ */++import React from 'react';+import './sessionSidebar.css';+import { DashboardClientContext } from './index';+import { SettingsButton } from './settingsView';+import { useSetting } from '@web/uiUtils';+import { ToolbarButton } from '@web/components/toolbarButton';++import type { Tab, DashboardChannelEvents } from './dashboardChannel';+import type { SessionModel, SessionStatus } from './sessionModel';++type SessionSidebarProps = {+ model: SessionModel;+ activeBrowser?: string;+ onSelectTab: (tab: Tab) => void;+ onCloseTab: (tab: Tab) => void;+ onNewTab: (browser: string, context: string) => void;+};++function tabFavicon(url: string): string {+ try {+ const u = new URL(url);+ const host = u.hostname.replace(/^www\./, '');+ return host ? host[0].toUpperCase() : '';+ } catch {+ return '';+ }+}++function normalizeWorkspacePath(workspace: string): string {+ if (!workspace || workspace === 'Global')+ return workspace;+ if (workspace.startsWith('/') || workspace.startsWith('\\\\') || /^[A-Za-z]:[\\/]/.test(workspace))+ return workspace;+ if (workspace.includes('/'))+ return '/' + workspace;+ return workspace;+}++export const SessionSidebar: React.FC<SessionSidebarProps> = ({ model, activeBrowser, onSelectTab, onCloseTab, onNewTab }) => {+ const client = React.useContext(DashboardClientContext);+ const [sidebarLocation, setSidebarLocation] = useSetting<'bottom' | 'right'>('propertiesSidebarLocation', 'bottom');+ const openSessions = React.useMemo(() => model.sessions.filter(session => session.canConnect), [model.sessions]);+ const clientInfo = model.clientInfo;+ const [browserState, setBrowserState] = React.useState<Record<string, { context: string; tabs?: Tab[]; }>>({});++ React.useEffect(() => {+ if (!client)+ return;++ const onTabs = (params: DashboardChannelEvents['tabs']) => {+ setBrowserState(prev => ({+ ...prev,+ [params.target.browser]: {+ context: params.target.context,+ tabs: params.tabs,+ },+ }));+ };++ client.on('tabs', onTabs);++ for (const session of openSessions) {+ void client.attach({ browser: session.browser.guid }).then(result => {+ setBrowserState(prev => ({+ ...prev,+ [session.browser.guid]: {+ ...prev[session.browser.guid],+ context: result.context,+ },+ }));+ }).catch(() => {});+ }++ return () => client.off('tabs', onTabs);+ }, [client, openSessions]);++ const workspaceGroups = React.useMemo(() => {+ const groups = new Map<string, SessionStatus[]>();+ for (const session of openSessions) {+ const key = session.workspaceDir || 'Global';+ let list = groups.get(key);+ if (!list) {+ list = [];+ groups.set(key, list);+ }+ list.push(session);+ }+ for (const list of groups.values())+ list.sort((a, b) => a.title.localeCompare(b.title));++ const currentWorkspace = clientInfo?.workspaceDir || 'Global';+ const entries = [...groups.entries()];+ const current = entries.filter(([key]) => key === currentWorkspace);+ const other = entries.filter(([key]) => key !== currentWorkspace).sort((a, b) => a[0].localeCompare(b[0]));+ return [...current, ...other];+ }, [openSessions, clientInfo?.workspaceDir]);++ return <nav className='dashboard-shell-sidebar' aria-label='Sessions'>+ <div className='dashboard-shell-sidebar-header'>+ <h2 className='dashboard-shell-sidebar-title'>Sessions</h2>+ <SettingsButton sidebarLocation={sidebarLocation} setSidebarLocation={setSidebarLocation} />+ </div>+ <div className='dashboard-shell-sidebar-content'>+ {model.loading && <div className='sidebar-empty' role='status' aria-live='polite'>Loading sessions...</div>}+ {!model.loading && openSessions.length === 0 && <div className='sidebar-empty' role='status' aria-live='polite'>No open sessions.</div>}+ {workspaceGroups.map(([workspace, entries]) => {+ const workspacePath = normalizeWorkspacePath(workspace);+ return <section key={workspace} className='workspace-group'>+ <h3 className='workspace-header'>+ <span className='workspace-path-full' title={workspacePath}>{workspacePath}</span>+ </h3>+ <div className='sidebar-session-list' role='list'>+ {entries.map(session => {+ const guid = session.browser.guid;+ const browserType = session.browser.browserName;+ const browserInitial = browserType ? browserType[0].toUpperCase() : '?';+ const sessionState = browserState[guid];+ const tabs = sessionState?.tabs;+ const context = sessionState?.context;+ return <div key={guid} className='session-chip sidebar-session' role='listitem' title={session.title}>+ <div className='sidebar-session-row'>+ <div className='session-browser-icon-wrap' title={browserType}>+ <span className='session-browser-icon' aria-hidden='true'>{browserInitial}</span>+ <ToolbarButton+ className='session-browser-close'+ icon='close'+ title='Close session'+ onClick={() => void model.closeSession(session)}+ />+ </div>+ <span className='session-chip-name'>{session.title}</span>+ <div className='sidebar-session-row-actions'>+ <ToolbarButton+ className='sidebar-session-new-tab'+ icon='add'+ title='New tab'+ onClick={() => {+ if (context)+ onNewTab(guid, context);+ }}+ disabled={!context}+ />+ </div>+ </div>+ <div className='sidebar-tab-list' role='list' aria-label={`${session.title} tabs`}>+ {tabs === undefined && <div className='sidebar-tabs-loading' role='status' aria-live='polite'>Loading tabs...</div>}+ {tabs?.length === 0 && <div className='sidebar-tabs-empty' role='status' aria-live='polite'>No tabs open.</div>}+ {tabs?.map(tab => <div+ key={tab.page}+ className={'sidebar-tab' + (guid === activeBrowser && tab.selected ? ' active' : '')}+ role='listitem'+ >+ <div+ className='sidebar-tab-select'+ role='button'+ tabIndex={0}+ aria-current={guid === activeBrowser && tab.selected ? 'page' : undefined}+ title={tab.url || tab.title}+ onClick={() => onSelectTab(tab)}+ onKeyDown={e => {+ if (e.key === 'Enter' || e.key === ' ') {+ e.preventDefault();+ onSelectTab(tab);+ }+ }}+ >+ {tab.faviconUrl+ ? <img className='sidebar-tab-favicon' src={tab.faviconUrl} alt='' aria-hidden='true' />+ : <span className='sidebar-tab-favicon placeholder' aria-hidden='true'>{tabFavicon(tab.url)}</span>}+ <span className='sidebar-tab-text'>+ <span className='sidebar-tab-title'>{tab.title || 'New Tab'}</span>+ <span className='sidebar-tab-url'>{tab.url || 'about:blank'}</span>+ </span>+ </div>+ <ToolbarButton+ className='sidebar-tab-close'+ icon='close'+ title='Close tab'+ onClick={e => {+ e.stopPropagation();+ onCloseTab(tab);+ }}+ />+ </div>)}+ </div>+ </div>;+ })}+ </div>+ </section>;+ })}+ </div>+ </nav>;+};diff --git a/packages/playwright-core/src/tools/dashboard/dashboardController.ts b/packages/playwright-core/src/tools/dashboard/dashboardController.tsindex 0f6f6dcfe2..bbc7a18b19 100644--- a/packages/playwright-core/src/tools/dashboard/dashboardController.ts+++ b/packages/playwright-core/src/tools/dashboard/dashboardController.ts@@ -457,6 +457,7 @@ class AttachedBrowser {size: { width: 1280, height: 800 },...(this._recordingPath ? { path: this._recordingPath } : {}),});+ void page.screenshot().catch(() => {}); // TODO: this is necessary to trigger a first frame - should this be in screencast.start() implementation?}private async _restartScreencast(page: api.Page) {diff --git a/tests/mcp/cli-devtools.spec.ts b/tests/mcp/cli-devtools.spec.tsindex 98af761d8a..4716a3dd92 100644--- a/tests/mcp/cli-devtools.spec.ts+++ b/tests/mcp/cli-devtools.spec.ts@@ -191,7 +191,7 @@ test('pick activates dashboard session', async ({ cdpServer, cli, server, openDaawait cli('snapshot');const dashboard = await openDashboard();- await expect(dashboard.locator('.session-chip')).toHaveCount(1);+ await expect(dashboard.locator('div.dashboard-view')).toBeVisible();const scriptReady = page.waitForEvent('console', msg => msg.text() === 'Recorder script ready for test');const pickPromise = cli('pick');diff --git a/tests/mcp/dashboard.spec.ts b/tests/mcp/dashboard.spec.tsindex 8efe0661ff..5dc6f67ecb 100644--- a/tests/mcp/dashboard.spec.ts+++ b/tests/mcp/dashboard.spec.ts@@ -46,13 +46,13 @@ test('should show current workspace sessions first', async ({ cli, server, openDconst workspaceGroups = dashboard.locator('.workspace-group');await expect(workspaceGroups).toHaveCount(2);- // Current workspace (first) should be first and expanded.- await expect(workspaceGroups.nth(0).locator('.workspace-path')).toContainText(first);- await expect(workspaceGroups.nth(0).locator('.session-chips')).toBeVisible();+ // Current workspace (first) should be first.+ await expect(workspaceGroups.nth(0).locator('.workspace-path-full')).toContainText(first);+ await expect(workspaceGroups.nth(0).locator('.session-chip')).toHaveCount(1);- // Other workspace (second) should be second and collapsed.- await expect(workspaceGroups.nth(1).locator('.workspace-path')).toContainText(second);- await expect(workspaceGroups.nth(1).locator('.session-chips')).not.toBeVisible();+ // Other workspace (second) should be second.+ await expect(workspaceGroups.nth(1).locator('.workspace-path-full')).toContainText(second);+ await expect(workspaceGroups.nth(1).locator('.session-chip')).toHaveCount(1);await dashboard.close();};@@ -67,12 +67,12 @@ test('should show current workspace sessions first', async ({ cli, server, openD});test('should pick locator from browser', async ({ cli, server, openDashboard }) => {- server.setContent('/', '<button style="position:fixed;top:0;left:0;width:200px;height:100px">Submit</button>', 'text/html');+ server.setContent('/', '<button style="position:fixed;inset:0;width:100vw;height:100vh">Submit</button>', 'text/html');await cli('open', server.PREFIX);const dashboard = await openDashboard();- await dashboard.locator('.session-chip').click();+ await dashboard.locator('.sidebar-tab').first().click();await dashboard.getByRole('button', { name: 'Show sidebar' }).click();await dashboard.getByRole('button', { name: 'Pick locator' }).click();@@ -80,7 +80,8 @@ test('should pick locator from browser', async ({ cli, server, openDashboard })await expect(dashboard.locator('div.dashboard-view')).toContainClass('interactive');await expect(async () => {- await dashboard.locator('img#display').click({ position: { x: 500, y: 25 } });+ const box = await dashboard.locator('img#display').boundingBox();+ await dashboard.mouse.click(box!.x + box!.width / 2, box!.y + box!.height / 2);await expect(dashboard.locator('.cm-wrapper').first()).toContainText(`getByRole('button', { name: 'Submit' })`);}).toPass();});@@ -110,3 +111,36 @@ test('should show console and network tabs in sidebar', async ({ cli, server, opawait dashboard.getByRole('tab', { name: 'Response' }).click();await expect(dashboard.locator('.network-response-body')).toContainText('dashboard-response-payload-marker');});++test('sidebar', async ({ cli, server, openDashboard, mcpBrowser }) => {+ test.fixme(mcpBrowser === 'firefox', 'firefox has bug around context creation that breaks this test');+ await cli('open', server.PREFIX);++ const dashboard = await openDashboard();+ const sidebar = dashboard.getByRole('navigation', { name: 'Sessions' });+ await expect(sidebar).toMatchAriaSnapshot(`+- heading "Sessions"+- list:+ - listitem:+ - text: default+ - list:+ - listitem:+ - button "New Tab ${server.PREFIX}/"+ `);++ await cli('open', '--session=foo', server.PREFIX);+ await expect(sidebar).toMatchAriaSnapshot(`+- heading "Sessions"+- list:+ - listitem:+ - text: default+ - list "default tabs":+ - listitem:+ - button "New Tab ${server.PREFIX}/"+ - listitem:+ - text: foo+ - list:+ - listitem:+ - button "New Tab ${server.PREFIX}/"+ `);+});