-
Notifications
You must be signed in to change notification settings - Fork 5.7k
chore: add trace viewer file upload error handling #10243
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
Changes from all commits
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 |
|---|---|---|
|
|
@@ -32,25 +32,31 @@ import { msToString } from '../../uiUtils'; | |
|
|
||
| export const Workbench: React.FunctionComponent<{ | ||
| }> = () => { | ||
| const [traceURL, setTraceURL] = React.useState<string>(new URL(window.location.href).searchParams.get('trace')!); | ||
| const [traceURL, setTraceURL] = React.useState<string>(''); | ||
| const [uploadedTraceName, setUploadedTraceName] = React.useState<string|null>(null); | ||
| const [contextEntry, setContextEntry] = React.useState<ContextEntry>(emptyContext); | ||
| const [selectedAction, setSelectedAction] = React.useState<ActionTraceEvent | undefined>(); | ||
| const [highlightedAction, setHighlightedAction] = React.useState<ActionTraceEvent | undefined>(); | ||
| const [selectedNavigatorTab, setSelectedNavigatorTab] = React.useState<string>('actions'); | ||
| const [selectedPropertiesTab, setSelectedPropertiesTab] = React.useState<string>('logs'); | ||
| const [progress, setProgress] = React.useState<{ done: number, total: number }>({ done: 0, total: 0 }); | ||
| const [dragOver, setDragOver] = React.useState<boolean>(false); | ||
| const [processingErrorMessage, setProcessingErrorMessage] = React.useState<string|null>(null); | ||
|
|
||
| const processTraceFile = (file: File) => { | ||
| const blobTraceURL = URL.createObjectURL(file); | ||
| const url = new URL(window.location.href); | ||
| url.searchParams.set('trace', blobTraceURL); | ||
| url.searchParams.set('traceFileName', file.name); | ||
| const href = url.toString(); | ||
| // Snapshot loaders will inherit the trace url from the query parameters, | ||
| // so set it here. | ||
| window.history.pushState({}, '', href); | ||
| setTraceURL(blobTraceURL); | ||
| setUploadedTraceName(file.name); | ||
| setSelectedAction(undefined); | ||
| setDragOver(false); | ||
| setProcessingErrorMessage(null); | ||
| }; | ||
|
|
||
| const handleDropEvent = (event: React.DragEvent<HTMLDivElement>) => { | ||
|
|
@@ -65,6 +71,13 @@ export const Workbench: React.FunctionComponent<{ | |
| processTraceFile(event.target.files[0]); | ||
| }; | ||
|
|
||
| React.useEffect(() => { | ||
|
mxschmitt marked this conversation as resolved.
|
||
| const newTraceURL = new URL(window.location.href).searchParams.get('trace'); | ||
| // Don't re-use blob file URLs on page load (results in Fetch error) | ||
| if (newTraceURL && !newTraceURL.startsWith('blob:')) | ||
| setTraceURL(newTraceURL); | ||
| }, [setTraceURL]); | ||
|
Member
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 does it mean useEffect around setTraceURL, wouldn't it run only once?
Contributor
Author
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. Yes, as the comment says its about if you open trace viewer with a blob URL. Usually old tab, forced reload etc. |
||
|
|
||
| React.useEffect(() => { | ||
| (async () => { | ||
| if (traceURL) { | ||
|
|
@@ -74,7 +87,17 @@ export const Workbench: React.FunctionComponent<{ | |
| }; | ||
| navigator.serviceWorker.addEventListener('message', swListener); | ||
| setProgress({ done: 0, total: 1 }); | ||
| const contextEntry = (await fetch(`context?trace=${traceURL}`).then(response => response.json())) as ContextEntry; | ||
| const params = new URLSearchParams(); | ||
| params.set('trace', traceURL); | ||
| if (uploadedTraceName) | ||
| params.set('traceFileName', uploadedTraceName); | ||
| const response = await fetch(`context?${params.toString()}`); | ||
| if (!response.ok) { | ||
| setTraceURL(''); | ||
| setProcessingErrorMessage((await response.json()).error); | ||
| return; | ||
| } | ||
| const contextEntry = await response.json() as ContextEntry; | ||
| navigator.serviceWorker.removeEventListener('message', swListener); | ||
| setProgress({ done: 0, total: 0 }); | ||
| modelUtil.indexModel(contextEntry); | ||
|
|
@@ -162,7 +185,8 @@ export const Workbench: React.FunctionComponent<{ | |
| {!!progress.total && <div className='progress'> | ||
| <div className='inner-progress' style={{ width: (100 * progress.done / progress.total) + '%' }}></div> | ||
| </div>} | ||
| {!dragOver && !traceURL && <div className='drop-target'> | ||
| {!dragOver && (!traceURL || processingErrorMessage) && <div className='drop-target'> | ||
| <div className='processing-error'>{processingErrorMessage}</div> | ||
| <div className='title'>Drop Playwright Trace to load</div> | ||
| <div>or</div> | ||
| <button onClick={() => { | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.