fix(trace viewer): keep sw alive (#9725)

This commit is contained in:
Pavel Feldman 2021-10-22 14:14:58 -08:00 committed by GitHub
parent 940466f830
commit e2710451f3
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 7 additions and 1 deletions

View file

@ -29,5 +29,7 @@ import '../common.css';
navigator.serviceWorker.oncontrollerchange = () => f();
});
}
// Keep SW running.
setInterval(function() { fetch('ping'); }, 10000);
ReactDOM.render(<Workbench/>, document.querySelector('#root'));
})();

View file

@ -56,8 +56,12 @@ async function doFetch(event: FetchEvent): Promise<Response> {
const url = new URL(request.url);
const relativePath = url.pathname.substring(scopePath.length - 1);
if (relativePath === '/context') {
if (relativePath === '/ping') {
await gc();
return new Response(null, { status: 200 });
}
if (relativePath === '/context') {
const traceModel = await loadTrace(traceUrl, event.clientId);
return new Response(JSON.stringify(traceModel!.contextEntry), {
status: 200,