diff --git a/packages/trace-viewer/src/embedded.tsx b/packages/trace-viewer/src/embedded.tsx index 7f64d10bd3..8f0a09e560 100644 --- a/packages/trace-viewer/src/embedded.tsx +++ b/packages/trace-viewer/src/embedded.tsx @@ -20,7 +20,6 @@ import '@web/third_party/vscode/codicon.css'; import React from 'react'; import * as ReactDOM from 'react-dom'; import { EmbeddedWorkbenchLoader } from './ui/embeddedWorkbenchLoader'; -import { setPopoutFunction } from './ui/popout'; (async () => { applyTheme(); @@ -45,8 +44,6 @@ import { setPopoutFunction } from './ui/popout'; window.addEventListener('keyup', handleKeyEvent); if (window.location.protocol !== 'file:') { - if (window.location.href.includes('isUnderTest=true')) - await new Promise(f => setTimeout(f, 1000)); if (!navigator.serviceWorker) throw new Error(`Service workers are not supported.\nMake sure to serve the Trace Viewer (${window.location}) via HTTPS or localhost.`); navigator.serviceWorker.register('sw.bundle.js'); @@ -60,10 +57,5 @@ import { setPopoutFunction } from './ui/popout'; setInterval(function() { fetch('ping'); }, 10000); } - setPopoutFunction((url: string, target?: string) => { - if (url) - window.parent?.postMessage({ command: 'openExternal', params: { url, target } }, '*'); - }); - ReactDOM.render(, document.querySelector('#root')); })(); diff --git a/packages/trace-viewer/src/ui/embeddedWorkbenchLoader.tsx b/packages/trace-viewer/src/ui/embeddedWorkbenchLoader.tsx index fcb355b566..17a2211c41 100644 --- a/packages/trace-viewer/src/ui/embeddedWorkbenchLoader.tsx +++ b/packages/trace-viewer/src/ui/embeddedWorkbenchLoader.tsx @@ -21,6 +21,11 @@ import './embeddedWorkbenchLoader.css'; import { Workbench } from './workbench'; import { currentTheme, toggleTheme } from '@web/theme'; +function openPage(url: string, target?: string) { + if (url) + window.parent!.postMessage({ command: 'openExternal', params: { url, target } }, '*'); +} + export const EmbeddedWorkbenchLoader: React.FunctionComponent = () => { const [traceURLs, setTraceURLs] = React.useState([]); const [model, setModel] = React.useState(emptyModel); @@ -38,7 +43,7 @@ export const EmbeddedWorkbenchLoader: React.FunctionComponent = () => { } }); // notify vscode that it is now listening to its messages - window.parent?.postMessage({ type: 'loaded' }, '*'); + window.parent!.postMessage({ type: 'loaded' }, '*'); }, []); React.useEffect(() => { @@ -81,7 +86,7 @@ export const EmbeddedWorkbenchLoader: React.FunctionComponent = () => {
- + {!traceURLs.length &&
Select test to see the trace
} diff --git a/packages/trace-viewer/src/ui/popout.ts b/packages/trace-viewer/src/ui/popout.ts deleted file mode 100644 index e14ae635ec..0000000000 --- a/packages/trace-viewer/src/ui/popout.ts +++ /dev/null @@ -1,27 +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. - */ - -type PopoutFunction = (url: string, target?: string) => Window | any; - -let popoutFn: PopoutFunction = window.open; -export function setPopoutFunction(fn: PopoutFunction) { - popoutFn = fn; -} - -export function popout(url: string, target?: string): Window | undefined { - const win = popoutFn(url, target); - return win instanceof Window ? win : undefined; -} diff --git a/packages/trace-viewer/src/ui/snapshotTab.tsx b/packages/trace-viewer/src/ui/snapshotTab.tsx index 7823d929cb..4bc2abc9eb 100644 --- a/packages/trace-viewer/src/ui/snapshotTab.tsx +++ b/packages/trace-viewer/src/ui/snapshotTab.tsx @@ -29,7 +29,6 @@ import type { Language } from '@isomorphic/locatorGenerators'; import { locatorOrSelectorAsSelector } from '@isomorphic/locatorParser'; import { TabbedPaneTab } from '@web/components/tabbedPane'; import { BrowserFrame } from './browserFrame'; -import { popout } from './popout'; export const SnapshotTab: React.FunctionComponent<{ action: ActionTraceEvent | undefined, @@ -39,7 +38,8 @@ export const SnapshotTab: React.FunctionComponent<{ setIsInspecting: (isInspecting: boolean) => void, highlightedLocator: string, setHighlightedLocator: (locator: string) => void, -}> = ({ action, sdkLanguage, testIdAttributeName, isInspecting, setIsInspecting, highlightedLocator, setHighlightedLocator }) => { + openPage?: (url: string, target?: string) => Window | any, +}> = ({ action, sdkLanguage, testIdAttributeName, isInspecting, setIsInspecting, highlightedLocator, setHighlightedLocator, openPage }) => { const [measure, ref] = useMeasure(); const [snapshotTab, setSnapshotTab] = React.useState<'action'|'before'|'after'>('action'); @@ -191,7 +191,9 @@ export const SnapshotTab: React.FunctionComponent<{ })}
{ - const win = popout(popoutUrl || '', '_blank'); + if (!openPage) + openPage = window.open; + const win = openPage(popoutUrl || '', '_blank'); win?.addEventListener('DOMContentLoaded', () => { const injectedScript = new InjectedScript(win as any, false, sdkLanguage, testIdAttributeName, 1, 'chromium', []); new ConsoleAPI(injectedScript); diff --git a/packages/trace-viewer/src/ui/workbench.tsx b/packages/trace-viewer/src/ui/workbench.tsx index c50b345b75..afc003c674 100644 --- a/packages/trace-viewer/src/ui/workbench.tsx +++ b/packages/trace-viewer/src/ui/workbench.tsx @@ -51,7 +51,8 @@ export const Workbench: React.FunctionComponent<{ isLive?: boolean, status?: UITestStatus, inert?: boolean, -}> = ({ model, showSourcesFirst, rootDir, fallbackLocation, initialSelection, onSelectionChanged, isLive, status, inert }) => { + openPage?: (url: string, target?: string) => Window | any, +}> = ({ model, showSourcesFirst, rootDir, fallbackLocation, initialSelection, onSelectionChanged, isLive, status, inert, openPage }) => { const [selectedAction, setSelectedActionImpl] = React.useState(undefined); const [revealedStack, setRevealedStack] = React.useState(undefined); const [highlightedAction, setHighlightedAction] = React.useState(); @@ -234,7 +235,8 @@ export const Workbench: React.FunctionComponent<{ isInspecting={isInspecting} setIsInspecting={setIsInspecting} highlightedLocator={highlightedLocator} - setHighlightedLocator={locatorPicked} /> + setHighlightedLocator={locatorPicked} + openPage={openPage} />