Skip to content

Commit

Permalink
Fix firefox & chrome startup bugs caused by server bundling
Browse files Browse the repository at this point in the history
  • Loading branch information
pimterry committed Sep 22, 2019
1 parent a8448d7 commit f0de733
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 35 deletions.
56 changes: 29 additions & 27 deletions src/cert-check-server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,31 +15,7 @@ let installingCert: boolean;
// If it doesn't, redirect to the certificate itself (the browser will prompt to install)
// Note that this function is stringified, and run in the browser, not here in node.
function ensureCertificateIsInstalled() {
const testUrl = window.location.href.replace('http://', 'https://').replace('check-cert', 'test-https');
const downloadUrl = window.location.href.replace('check-cert', 'download-cert');
const reportSuccessUrl = window.location.href.replace('check-cert', 'report-success');

fetch(testUrl)
.then(() => true)
.catch(() => false)
.then((certificateIsTrusted) => {
if (certificateIsTrusted) {
// Report success (ignoring errors) then continue.
fetch(reportSuccessUrl).catch(() => {}).then(() => {
window.location.replace(targetUrl);
});
} else {
// Start trying to prompt the user to install the cert
if (!installingCert) {
installingCert = true;
document.body.className = 'show-content';
const iframe = document.createElement('iframe');
iframe.src = downloadUrl;
document.body.appendChild(iframe);
setInterval(ensureCertificateIsInstalled, 500);
}
}
});

}

export class CertCheckServer {
Expand Down Expand Up @@ -91,8 +67,34 @@ export class CertCheckServer {
let installingCert = false;
const targetUrl = ${JSON.stringify(targetUrl)};
${ensureCertificateIsInstalled.toString()}
ensureCertificateIsInstalled();
function ensureCertificateIsInstalled() {
const testUrl = window.location.href.replace('http://', 'https://').replace('check-cert', 'test-https');
const downloadUrl = window.location.href.replace('check-cert', 'download-cert');
const reportSuccessUrl = window.location.href.replace('check-cert', 'report-success');
fetch(testUrl)
.then(() => true)
.catch(() => false)
.then((certificateIsTrusted) => {
if (certificateIsTrusted) {
// Report success (ignoring errors) then continue.
fetch(reportSuccessUrl).catch(() => {}).then(() => {
window.location.replace(targetUrl);
});
} else {
// Start trying to prompt the user to install the cert
if (!installingCert) {
installingCert = true;
document.body.className = 'show-content';
const iframe = document.createElement('iframe');
iframe.src = downloadUrl;
document.body.appendChild(iframe);
setInterval(ensureCertificateIsInstalled, 500);
}
}
});
}
ensureCertificateIsInstalled();
</script>
<body>
<h1>
Expand Down
11 changes: 3 additions & 8 deletions src/hide-chrome-warning-server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,7 @@ let targetUrl: string;

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

export class HideChromeWarningServer {

Expand Down Expand Up @@ -37,9 +33,8 @@ export class HideChromeWarningServer {
</style>
<script>
const targetUrl = ${JSON.stringify(targetUrl)};
${jumpToNewTab.toString()}
jumpToNewTab();
window.open(targetUrl, '_blank');
window.close();
</script>
<body>
This page should disappear momentarily. If it doesn't, click
Expand Down

0 comments on commit f0de733

Please sign in to comment.