Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(trace-viewer): add copy to clipboard button for traceviewer snapshot url on hover (#35213) #35255

Merged
merged 10 commits into from
Mar 28, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions packages/trace-viewer/src/ui/browserFrame.css
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,16 @@
overflow: hidden;
text-overflow: ellipsis;
white-space: nowrap;
display: flex;
align-items: center;
}

.browser-frame-address-bar > button {
visibility: hidden;
}

.browser-frame-address-bar:hover > button {
visibility: visible;
}

.browser-frame-menu-bar {
Expand Down
13 changes: 11 additions & 2 deletions packages/trace-viewer/src/ui/browserFrame.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,17 +16,26 @@

import './browserFrame.css';
import * as React from 'react';
import { CopyToClipboard } from './copyToClipboard';

export const BrowserFrame: React.FunctionComponent<{
url?: string,
}> = ({ url }) => {
}> = ({ url }): React.ReactElement => {
return <div className='browser-frame-header'>
<div style={{ whiteSpace: 'nowrap' }}>
<span className='browser-frame-dot' style={{ backgroundColor: 'rgb(242, 95, 88)' }}></span>
<span className='browser-frame-dot' style={{ backgroundColor: 'rgb(251, 190, 60)' }}></span>
<span className='browser-frame-dot' style={{ backgroundColor: 'rgb(88, 203, 66)' }}></span>
</div>
<div className='browser-frame-address-bar' title={url || 'about:blank'}>{url || 'about:blank'}</div>
<div
className='browser-frame-address-bar'
title={url || 'about:blank'}
>
{url || 'about:blank'}
{url && (
<CopyToClipboard value={url} />
)}
</div>
<div style={{ marginLeft: 'auto' }}>
<div>
<span className='browser-frame-menu-bar'></span>
Expand Down
10 changes: 9 additions & 1 deletion tests/library/trace-viewer.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -467,7 +467,15 @@ test('should show snapshot URL', async ({ page, runAndTrace, server }) => {
await page.evaluate('2+2');
});
await traceViewer.snapshotFrame('page.evaluate');
await expect(traceViewer.page.locator('.browser-frame-address-bar')).toHaveText(server.EMPTY_PAGE);
const browserFrameAddressBarLocator = traceViewer.page.locator('.browser-frame-address-bar');
await expect(browserFrameAddressBarLocator).toHaveText(server.EMPTY_PAGE);
const copySelectorLocator = browserFrameAddressBarLocator.getByRole('button', { name: 'Copy' });
await expect(copySelectorLocator).toBeHidden();
await browserFrameAddressBarLocator.hover();
await expect(copySelectorLocator).toBeVisible();
await traceViewer.page.context().grantPermissions(['clipboard-read', 'clipboard-write']);
await copySelectorLocator.click();
expect(await traceViewer.page.evaluate(() => navigator.clipboard.readText())).toBe(server.EMPTY_PAGE);
});

test('should popup snapshot', async ({ page, runAndTrace, server }) => {
Expand Down
Loading