Skip to content

Commit fff870b

Browse files
JS-less and CSS-less notices
1 parent 0c7c62c commit fff870b

File tree

1 file changed

+59
-10
lines changed

1 file changed

+59
-10
lines changed

lib/better_errors/templates/main.erb

Lines changed: 59 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
<head>
44
<title><%= exception_type %> at <%= request_path %></title>
55
</head>
6-
<body>
6+
<body class="better-errors-javascript-not-loaded">
77
<%# Stylesheets are placed in the <body> for Turbolinks compatibility. %>
88
<style>
99
/* Basic reset */
@@ -232,6 +232,10 @@
232232
* Navigation
233233
* --------------------------------------------------------------------- */
234234

235+
.better-errors-javascript-not-loaded .backtrace .tabs {
236+
display: none;
237+
}
238+
235239
nav.tabs {
236240
border-bottom: solid 1px #ddd;
237241

@@ -416,6 +420,18 @@
416420
* Display area
417421
* --------------------------------------------------------------------- */
418422

423+
.no-javascript-notice {
424+
margin-bottom: 1em;
425+
padding: 1em;
426+
border: 2px solid #e00;
427+
}
428+
.better-errors-javascript-loaded .no-javascript-notice {
429+
display: none;
430+
}
431+
.no-inline-style-notice {
432+
display: none;
433+
}
434+
419435
.trace_info {
420436
background: #fff;
421437
padding: 6px;
@@ -473,6 +489,10 @@
473489
font-weight: 200;
474490
}
475491

492+
.better-errors-javascript-not-loaded .be-repl {
493+
display: none;
494+
}
495+
476496
.code, .be-console, .unavailable {
477497
background: #fff;
478498
padding: 5px;
@@ -603,6 +623,9 @@
603623
.console-has-been-used .live-console-hint {
604624
display: none;
605625
}
626+
.better-errors-javascript-not-loaded .live-console-hint {
627+
display: none;
628+
}
606629

607630
.hint:before {
608631
content: '\25b2';
@@ -745,6 +768,15 @@
745768
}
746769
</script>
747770

771+
<p class='no-inline-style-notice'>
772+
<strong>
773+
Better Errors can't apply inline style,
774+
possibly because you have a Content Security Policy along with Turbolinks.
775+
But you can
776+
<a href='/__better_errors' target="_blank">open the interactive console in a new tab/window</a>.
777+
</strong>
778+
</p>
779+
748780
<div class='top'>
749781
<header class="exception">
750782
<h2><strong><%= exception_type %></strong> <span>at <%= request_path %></span></h2>
@@ -791,9 +823,18 @@
791823
</ul>
792824
</nav>
793825

794-
<% backtrace_frames.each_with_index do |frame, index| %>
795-
<div class="frame_info" id="frame_info_<%= index %>"></div>
796-
<% end %>
826+
<div class="frameInfos">
827+
<div class="frame_info current" data-frame-idx="0">
828+
<p class='no-javascript-notice'>
829+
Better Errors can't run Javascript here<span class='no-inline-style-notice'> (or apply inline style)</span>,
830+
possibly because you have a Content Security Policy along with Turbolinks.
831+
But you can
832+
<a href='/__better_errors' target="_blank">open the interactive console in a new tab/window</a>.
833+
</p>
834+
<!-- this is enough information to show something in case JS doesn't get to load -->
835+
<%== ErrorPage.render_template('variable_info', first_frame_variable_info) %>
836+
</div>
837+
</div>
797838
</section>
798839
</body>
799840
<script nonce="<%= csp_nonce %>">
@@ -803,9 +844,11 @@
803844
var csrfToken = "<%= csrf_token %>";
804845

805846
var previousFrame = null;
806-
var previousFrameInfo = null;
807847
var allFrames = document.querySelectorAll("ul.frames li");
808-
var allFrameInfos = document.querySelectorAll(".frame_info");
848+
var frameInfos = document.querySelector(".frameInfos");
849+
850+
document.querySelector('body').classList.remove("better-errors-javascript-not-loaded");
851+
document.querySelector('body').classList.add("better-errors-javascript-loaded");
809852

810853
function apiCall(method, opts, cb) {
811854
var req = new XMLHttpRequest();
@@ -979,10 +1022,10 @@
9791022
};
9801023

9811024
function switchTo(el) {
982-
if(previousFrameInfo) {
983-
previousFrameInfo.className = "frame_info";
1025+
var currentFrameInfo = document.querySelectorAll('.frame_info.current');
1026+
for(var i = 0; i < currentFrameInfo.length; i++) {
1027+
currentFrameInfo[i].className = "frame_info";
9841028
}
985-
previousFrameInfo = el;
9861029

9871030
el.className = "frame_info current";
9881031

@@ -991,7 +1034,13 @@
9911034
}
9921035

9931036
function selectFrameInfo(index) {
994-
var el = allFrameInfos[index];
1037+
var el = document.querySelector(".frame_info[data-frame-idx='" + index + "']")
1038+
if (!el) {
1039+
el = document.createElement("div");
1040+
el.className = "frame_info";
1041+
el.setAttribute('data-frame-idx', index);
1042+
frameInfos.appendChild(el);
1043+
}
9951044
if(el) {
9961045
if (el.loaded) {
9971046
return switchTo(el);

0 commit comments

Comments
 (0)