Skip to content

Commit 437f5a9

Browse files
committed
Auto merge of #3044 - Turbo87:fallback, r=jtgeibel
Show error message when JS code fails to load This should resolve #2984, by adding a short error message when something fails to load before the Ember app has booted up: <img width="942" alt="Bildschirmfoto 2020-11-25 um 00 31 31" src="https://user-images.githubusercontent.com/141300/100163272-a0671300-2eb5-11eb-8f43-480e803e5b79.png"> This does use an inline script though, so we might have to adjust the CSP for this 😞 r? `@jtgeibel`
2 parents b9d6b11 + d425ab5 commit 437f5a9

File tree

3 files changed

+5
-1
lines changed

3 files changed

+5
-1
lines changed

app/app.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ import config from './config/environment';
77
import * as Sentry from './sentry';
88

99
if (typeof FastBoot === 'undefined') {
10+
// eslint-disable-next-line unicorn/prefer-add-event-listener
11+
window.onerror = undefined;
1012
Sentry.init();
1113
}
1214

app/index.html

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@
2828

2929
{{content-for 'body'}}
3030

31+
<!-- if you change the following inline script make sure to change the CSP settings of nginx! -->
32+
<script>window.onerror=function(){document.body.innerHTML='<p style="width: 70%;background: var(--main-bg);padding: 10px;">Sorry, it looks like we were not able to load the page. Please make sure your network connection works and you are using an up-to-date browser. If the issue persists, please visit our <a href="https://github.com/rust-lang/crates.io/issues/new/choose">issue tracker</a> to report the problem.</p>'}</script>
3133
<script src="{{rootURL}}assets/vendor.js"></script>
3234
<script src="{{rootURL}}assets/cargo.js"></script>
3335

config/nginx.conf.erb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -211,7 +211,7 @@ http {
211211
add_header X-Frame-Options "SAMEORIGIN";
212212
add_header X-XSS-Protection "1; mode=block";
213213

214-
add_header Content-Security-Policy "default-src 'self'; connect-src 'self' *.ingest.sentry.io https://docs.rs https://<%= s3_host(ENV) %>; script-src 'self' 'unsafe-eval' https://www.gstatic.com; style-src 'self' 'unsafe-inline' https://www.gstatic.com https://code.cdn.mozilla.net; font-src https://code.cdn.mozilla.net; img-src *; object-src 'none'";
214+
add_header Content-Security-Policy "default-src 'self'; connect-src 'self' *.ingest.sentry.io https://docs.rs https://<%= s3_host(ENV) %>; script-src 'self' 'unsafe-eval' https://www.gstatic.com 'sha256-n1+BB7Ckjcal1Pr7QNBh/dKRTtBQsIytFodRiIosXdE='; style-src 'self' 'unsafe-inline' https://www.gstatic.com https://code.cdn.mozilla.net; font-src https://code.cdn.mozilla.net; img-src *; object-src 'none'";
215215
add_header Access-Control-Allow-Origin "*";
216216

217217
add_header Strict-Transport-Security "max-age=31536000" always;

0 commit comments

Comments
 (0)