Skip to content

Commit f0de733

Browse files
committed
Fix firefox & chrome startup bugs caused by server bundling
1 parent a8448d7 commit f0de733

File tree

2 files changed

+32
-35
lines changed

2 files changed

+32
-35
lines changed

src/cert-check-server.ts

Lines changed: 29 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -15,31 +15,7 @@ let installingCert: boolean;
1515
// If it doesn't, redirect to the certificate itself (the browser will prompt to install)
1616
// Note that this function is stringified, and run in the browser, not here in node.
1717
function ensureCertificateIsInstalled() {
18-
const testUrl = window.location.href.replace('http://', 'https://').replace('check-cert', 'test-https');
19-
const downloadUrl = window.location.href.replace('check-cert', 'download-cert');
20-
const reportSuccessUrl = window.location.href.replace('check-cert', 'report-success');
21-
22-
fetch(testUrl)
23-
.then(() => true)
24-
.catch(() => false)
25-
.then((certificateIsTrusted) => {
26-
if (certificateIsTrusted) {
27-
// Report success (ignoring errors) then continue.
28-
fetch(reportSuccessUrl).catch(() => {}).then(() => {
29-
window.location.replace(targetUrl);
30-
});
31-
} else {
32-
// Start trying to prompt the user to install the cert
33-
if (!installingCert) {
34-
installingCert = true;
35-
document.body.className = 'show-content';
36-
const iframe = document.createElement('iframe');
37-
iframe.src = downloadUrl;
38-
document.body.appendChild(iframe);
39-
setInterval(ensureCertificateIsInstalled, 500);
40-
}
41-
}
42-
});
18+
4319
}
4420

4521
export class CertCheckServer {
@@ -91,8 +67,34 @@ export class CertCheckServer {
9167
let installingCert = false;
9268
const targetUrl = ${JSON.stringify(targetUrl)};
9369
94-
${ensureCertificateIsInstalled.toString()}
95-
ensureCertificateIsInstalled();
70+
function ensureCertificateIsInstalled() {
71+
const testUrl = window.location.href.replace('http://', 'https://').replace('check-cert', 'test-https');
72+
const downloadUrl = window.location.href.replace('check-cert', 'download-cert');
73+
const reportSuccessUrl = window.location.href.replace('check-cert', 'report-success');
74+
75+
fetch(testUrl)
76+
.then(() => true)
77+
.catch(() => false)
78+
.then((certificateIsTrusted) => {
79+
if (certificateIsTrusted) {
80+
// Report success (ignoring errors) then continue.
81+
fetch(reportSuccessUrl).catch(() => {}).then(() => {
82+
window.location.replace(targetUrl);
83+
});
84+
} else {
85+
// Start trying to prompt the user to install the cert
86+
if (!installingCert) {
87+
installingCert = true;
88+
document.body.className = 'show-content';
89+
const iframe = document.createElement('iframe');
90+
iframe.src = downloadUrl;
91+
document.body.appendChild(iframe);
92+
setInterval(ensureCertificateIsInstalled, 500);
93+
}
94+
}
95+
});
96+
}
97+
ensureCertificateIsInstalled();
9698
</script>
9799
<body>
98100
<h1>

src/hide-chrome-warning-server.ts

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,7 @@ let targetUrl: string;
55

66
// The first tab that opens opens with a Chrome warning about dangerous flags
77
// Closing it and immediately opening a new one is a bit cheeky, but
8-
// is completely gets rid that, more or less invisibly.
9-
function jumpToNewTab() {
10-
window.open(targetUrl, '_blank');
11-
window.close();
12-
}
8+
// is completely gets rid that, more or less invisibly:
139

1410
export class HideChromeWarningServer {
1511

@@ -37,9 +33,8 @@ export class HideChromeWarningServer {
3733
</style>
3834
<script>
3935
const targetUrl = ${JSON.stringify(targetUrl)};
40-
41-
${jumpToNewTab.toString()}
42-
jumpToNewTab();
36+
window.open(targetUrl, '_blank');
37+
window.close();
4338
</script>
4439
<body>
4540
This page should disappear momentarily. If it doesn't, click

0 commit comments

Comments
 (0)