Skip to content
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
4 changes: 2 additions & 2 deletions packages/isomorphic/urlMatch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@

import { isString } from './stringUtils';

export function isHttpUrl(url: string): boolean {
export function isHttpUrl(url: string, base?: string): boolean {
try {
return ['http:', 'https:'].includes(new URL(url).protocol);
return ['http:', 'https:'].includes(new URL(url, base).protocol);
} catch {
return false;
}
Expand Down
15 changes: 1 addition & 14 deletions packages/trace-viewer/snapshot.html
Original file line number Diff line number Diff line change
Expand Up @@ -17,19 +17,6 @@
<html lang="en">
<body>
<iframe src="about:blank" sandbox="allow-same-origin allow-scripts" style="position:absolute;top:0;left:0;right:0;bottom:0;width:100%;height:100%;border:none;"></iframe>
<script>
(async () => {
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');
if (!navigator.serviceWorker.controller)
await new Promise(f => navigator.serviceWorker.oncontrollerchange = f);
const traceUrl = new URL(location.href).searchParams.get('trace');
const params = new URLSearchParams();
params.set('trace', traceUrl);
await fetch('contexts?' + params.toString());
document.querySelector('iframe').src = new URLSearchParams(location.search).get('r');
})();
</script>
<script type="module" src="/src/snapshotMain.ts"></script>
</body>
</html>
3 changes: 3 additions & 0 deletions packages/trace-viewer/src/DEPS.list
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,8 @@
@web/**
ui/

[snapshotMain.ts]
@isomorphic/**

[sw-main.ts]
sw/**
36 changes: 36 additions & 0 deletions packages/trace-viewer/src/snapshotMain.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
/*
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 { isHttpUrl } from '@isomorphic/urlMatch';

(async () => {
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');
if (!navigator.serviceWorker.controller)
await new Promise(f => navigator.serviceWorker.oncontrollerchange = f);
const traceUrl = new URL(location.href).searchParams.get('trace');
const params = new URLSearchParams();
if (traceUrl)
params.set('trace', traceUrl);
await fetch('contexts?' + params.toString());
const r = new URLSearchParams(location.search).get('r');
if (!r || !isHttpUrl(r, location.href))
return;
const iframe = document.querySelector('iframe');
if (iframe)
iframe.src = r;
})();
Loading