-
Notifications
You must be signed in to change notification settings - Fork 3.8k
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 setting for display canvas content in snapshots #34010
base: main
Are you sure you want to change the base?
Changes from 9 commits
f12164c
e198f8d
a581a6b
a8363ab
0138b5d
198b7be
af7cc37
7fb7a17
11b2090
fc3a35e
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -255,7 +255,9 @@ declare global { | |
|
||
function snapshotScript(viewport: ViewportSize, ...targetIds: (string | undefined)[]) { | ||
function applyPlaywrightAttributes(unwrapPopoutUrl: (url: string) => string, viewport: ViewportSize, ...targetIds: (string | undefined)[]) { | ||
const isUnderTest = new URLSearchParams(location.search).has('isUnderTest'); | ||
const searchParams = new URLSearchParams(location.search); | ||
const shouldPopulateCanvasFromScreenshot = searchParams.has('shouldPopulateCanvasFromScreenshot'); | ||
const isUnderTest = searchParams.has('isUnderTest'); | ||
|
||
// info to recursively compute canvas position relative to the top snapshot frame. | ||
// Before rendering each iframe, its parent extracts the '__playwright_canvas_render_info__' attribute | ||
|
@@ -512,15 +514,20 @@ function snapshotScript(viewport: ViewportSize, ...targetIds: (string | undefine | |
|
||
drawCheckerboard(context, canvas); | ||
|
||
context.drawImage(img, boundingRect.left * img.width, boundingRect.top * img.height, (boundingRect.right - boundingRect.left) * img.width, (boundingRect.bottom - boundingRect.top) * img.height, 0, 0, canvas.width, canvas.height); | ||
if (shouldPopulateCanvasFromScreenshot) { | ||
context.drawImage(img, boundingRect.left * img.width, boundingRect.top * img.height, (boundingRect.right - boundingRect.left) * img.width, (boundingRect.bottom - boundingRect.top) * img.height, 0, 0, canvas.width, canvas.height); | ||
|
||
if (partiallyUncaptured) | ||
canvas.title = `Playwright couldn't capture full canvas contents because it's located partially outside the viewport.`; | ||
else | ||
canvas.title = `Canvas contents are displayed on a best-effort basis based on viewport screenshots taken during test execution.`; | ||
} else { | ||
canvas.title = 'Canvas content display is disabled.'; | ||
} | ||
|
||
if (isUnderTest) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This belongs to the conditional block above. |
||
// eslint-disable-next-line no-console | ||
console.log(`canvas drawn:`, JSON.stringify([boundingRect.left, boundingRect.top, (boundingRect.right - boundingRect.left), (boundingRect.bottom - boundingRect.top)].map(v => Math.floor(v * 100)))); | ||
|
||
if (partiallyUncaptured) | ||
canvas.title = `Playwright couldn't capture full canvas contents because it's located partially outside the viewport.`; | ||
else | ||
canvas.title = `Canvas contents are displayed on a best-effort basis based on viewport screenshots taken during test execution.`; | ||
} | ||
}; | ||
img.onerror = () => { | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
/** | ||
* 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 * as React from 'react'; | ||
import { SettingsView } from './settingsView'; | ||
import { useDarkModeSetting } from '@web/theme'; | ||
import { useShouldPopulateCanvasFromScreenshot } from './settings/useShouldPopulateCanvasFromScreenshot'; | ||
|
||
export const DefaultSettingsView: React.FC<{}> = () => { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What is default settings view and how is it different from generic settings view? Put them into one file and clarify the difference? |
||
const [ | ||
shouldPopulateCanvasFromScreenshot, | ||
setShouldPopulateCanvasFromScreenshot, | ||
] = useShouldPopulateCanvasFromScreenshot(); | ||
const [darkMode, setDarkMode] = useDarkModeSetting(); | ||
|
||
return ( | ||
<SettingsView | ||
settings={[ | ||
{ value: darkMode, set: setDarkMode, name: 'Dark mode' }, | ||
{ | ||
value: shouldPopulateCanvasFromScreenshot, | ||
set: setShouldPopulateCanvasFromScreenshot, | ||
name: 'Display canvas content', | ||
title: 'Attempt to display the captured canvas appearance in the snapshot preview. May not be accurate.' | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Open to comments/suggestions on these strings There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. "Best effort canvas element visualization." ? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. That string is very long. I'd prefer it be shorter so it fits better in the settings UI. I do like the content though. |
||
}, | ||
]} | ||
/> | ||
); | ||
}; |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -280,7 +280,8 @@ const TraceView: React.FunctionComponent<{ | |
return snapshot.action || snapshot.after || snapshot.before; | ||
}, [action]); | ||
const snapshotUrls = React.useMemo(() => { | ||
return snapshot ? extendSnapshot(snapshot) : undefined; | ||
// TODO: Use actual setting. Requires settings UI to be wired up | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Does this mean the patch is not complete? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It seemed to me that this Recorder trace view was not complete. It needs its own settings UI to integrate the canvas setting, and the menu doesn't trivially integrate with Recorder trace view because of annoying CSS issues. |
||
return snapshot ? extendSnapshot(snapshot, false) : undefined; | ||
}, [snapshot]); | ||
|
||
return <SnapshotView | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
/** | ||
* 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 { useSetting } from '@web/uiUtils'; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. That's a little too fine-grained to me, inline? |
||
|
||
export const useShouldPopulateCanvasFromScreenshot = (): [ | ||
boolean, | ||
(value: boolean) => void | ||
] => useSetting('shouldPopulateCanvasFromScreenshot', false); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
/* | ||
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. | ||
*/ | ||
|
||
.settings-toolbar-dialog { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ditto |
||
background-color: var(--vscode-sideBar-background); | ||
|
||
padding: 4px 8px; | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
/* | ||
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 * as React from 'react'; | ||
import { Dialog } from './shared/dialog'; | ||
import { ToolbarButton } from '@web/components/toolbarButton'; | ||
import { DefaultSettingsView } from './defaultSettingsView'; | ||
import './settingsToolbar.css'; | ||
|
||
export const SettingsToolbarButton: React.FC<{}> = () => { | ||
const hostingRef = React.useRef<HTMLButtonElement>(null); | ||
|
||
const [open, setOpen] = React.useState(false); | ||
|
||
return ( | ||
<> | ||
<ToolbarButton | ||
ref={hostingRef} | ||
icon='settings-gear' | ||
title='Settings' | ||
onClick={() => setOpen(current => !current)} | ||
/> | ||
<Dialog | ||
className='settings-toolbar-dialog' | ||
open={open} | ||
width={200} | ||
// TODO: Temporary spacing until design of toolbar buttons is revisited | ||
verticalOffset={8} | ||
requestClose={() => setOpen(false)} | ||
hostingElement={hostingRef} | ||
> | ||
<DefaultSettingsView /> | ||
</Dialog> | ||
</> | ||
); | ||
}; |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -18,22 +18,32 @@ import * as React from 'react'; | |
import './settingsView.css'; | ||
|
||
export type Setting<T> = { | ||
value: T, | ||
set: (value: T) => void, | ||
title: string | ||
value: T; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Land this little refactoring separately, pre-work |
||
set: (value: T) => void; | ||
name: string; | ||
title?: string; | ||
}; | ||
|
||
export const SettingsView: React.FunctionComponent<{ | ||
settings: Setting<boolean>[], | ||
settings: Setting<boolean>[]; | ||
}> = ({ settings }) => { | ||
return <div className='vbox settings-view'> | ||
{settings.map(({ value, set, title }) => { | ||
return <div key={title} className='setting'> | ||
<label> | ||
<input type='checkbox' checked={value} onChange={() => set(!value)}/> | ||
{title} | ||
</label> | ||
</div>; | ||
})} | ||
</div>; | ||
return ( | ||
<div className='vbox settings-view'> | ||
{settings.map(({ value, set, name, title }) => { | ||
const labelId = `setting-${name}`; | ||
|
||
return ( | ||
<div key={name} className='setting' title={title}> | ||
<input | ||
type='checkbox' | ||
id={labelId} | ||
checked={value} | ||
onChange={() => set(!value)} | ||
/> | ||
<label htmlFor={labelId}>{name}</label> | ||
</div> | ||
); | ||
})} | ||
</div> | ||
); | ||
}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Open to comments/suggestions on these strings