chore: better error for trace viewer over http:// (#27722)

We saw in the past a lot of users reporting issues like this. Maybe a
more readable error helps.

Before they just saw:

```
Uncaught (in promise) TypeError: Cannot read properties of undefined (reading 'register')
  at index.38834ec3.js:1:3775
  at index.38834ec3.js:1:4006
```

Fixes https://github.com/microsoft/playwright/issues/27655
This commit is contained in:
Max Schmitt 2023-10-23 18:21:19 +02:00 committed by GitHub
parent b8678ef902
commit 5fe77f9a6f
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 6 additions and 0 deletions

View file

@ -18,6 +18,8 @@
<body>
<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);

View file

@ -26,6 +26,8 @@ import { WorkbenchLoader } from './ui/workbenchLoader';
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');
if (!navigator.serviceWorker.controller) {
await new Promise<void>(f => {

View file

@ -26,6 +26,8 @@ import { UIModeView } from './ui/uiModeView';
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 website (${window.location}) via HTTPS or localhost.`);
navigator.serviceWorker.register('sw.bundle.js');
if (!navigator.serviceWorker.controller) {
await new Promise<void>(f => {