Skip to content

Commit 6131375

Browse files
authored
Unify web_viewer/index.html and index_bundled.html (#4720)
### What It turns out this was already mostly done. The only change needed was removing the analytics script and adding it via JS when we are served on `app.rerun.io`. Fixes #2156 Fixes #2428 ### Checklist * [x] I have read and agree to [Contributor Guide](https://github.com/rerun-io/rerun/blob/main/CONTRIBUTING.md) and the [Code of Conduct](https://github.com/rerun-io/rerun/blob/main/CODE_OF_CONDUCT.md) * [x] I've included a screenshot or gif (if applicable) * [x] I have tested the web demo (if applicable): * Using newly built examples: [app.rerun.io](https://app.rerun.io/pr/4720/index.html) * Using examples from latest `main` build: [app.rerun.io](https://app.rerun.io/pr/4720/index.html?manifest_url=https://app.rerun.io/version/main/examples_manifest.json) * Using full set of examples from `nightly` build: [app.rerun.io](https://app.rerun.io/pr/4720/index.html?manifest_url=https://app.rerun.io/version/nightly/examples_manifest.json) * [x] The PR title and labels are set such as to maximize their usefulness for the next release's CHANGELOG - [PR Build Summary](https://build.rerun.io/pr/4720) - [Docs preview](https://rerun.io/preview/9d10741f8a8a21de05f24fca7f82ebb130d2d063/docs) <!--DOCS-PREVIEW--> - [Examples preview](https://rerun.io/preview/9d10741f8a8a21de05f24fca7f82ebb130d2d063/examples) <!--EXAMPLES-PREVIEW--> - [Recent benchmark results](https://build.rerun.io/graphs/crates.html) - [Wasm size tracking](https://build.rerun.io/graphs/sizes.html)
1 parent a1d3711 commit 6131375

File tree

4 files changed

+47
-438
lines changed

4 files changed

+47
-438
lines changed

crates/re_web_viewer_server/Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ include = [
1818

1919
# Matches the files in crates/re_web_viewer_server/src/lib.rs
2020
"web_viewer/favicon.svg",
21-
"web_viewer/index_bundled.html",
21+
"web_viewer/index.html",
2222
"web_viewer/re_viewer_bg.wasm",
2323
"web_viewer/re_viewer.js",
2424
"web_viewer/sw.js",

crates/re_web_viewer_server/src/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ mod data {
2424
#![allow(clippy::large_include_file)]
2525

2626
// If you add/remove/change the paths here, also update the include-list in `Cargo.toml`!
27-
pub const INDEX_HTML: &[u8] = include_bytes!("../web_viewer/index_bundled.html");
27+
pub const INDEX_HTML: &[u8] = include_bytes!("../web_viewer/index.html");
2828
pub const FAVICON: &[u8] = include_bytes!("../web_viewer/favicon.svg");
2929
pub const SW_JS: &[u8] = include_bytes!("../web_viewer/sw.js");
3030
pub const VIEWER_JS: &[u8] = include_bytes!("../web_viewer/re_viewer.js");

web_viewer/index.html

+45-39
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<!DOCTYPE html>
2-
<!-- The version of index.html that will be served by app.rerun.io -->
2+
<!-- Rerun SDK-bundled web viewer. -->
33
<html>
44
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
55

@@ -146,12 +146,6 @@
146146
<!-- The Wasm code will resize the canvas dynamically -->
147147
<canvas id="the_canvas_id" class="hidden"></canvas>
148148

149-
<script
150-
src="https://fifteen-thirtyeight.rerun.io/script.js"
151-
data-site="QKMCQFTQ"
152-
defer
153-
></script>
154-
155149
<script>
156150
// The `--no-modules`-generated JS from `wasm-bindgen` attempts to use
157151
// `WebAssembly.instantiateStreaming` to instantiate the wasm module,
@@ -169,6 +163,14 @@
169163
<script src="re_viewer.js"></script>
170164

171165
<script>
166+
if (window.location.hostname == "app.rerun.io") {
167+
const script = document.createElement("script");
168+
script.src = "https://fifteen-thirtyeight.rerun.io/script.js";
169+
script.dataset.site = "QKMCQFTQ";
170+
script.defer = true;
171+
document.body.appendChild(script);
172+
}
173+
172174
function show_center_html(html) {
173175
center_text_elem = document.getElementById("center_text");
174176
center_text_elem.innerHTML = html;
@@ -199,12 +201,13 @@
199201
)
200202
) {
201203
show_center_html(`
202-
<p>
203-
Rerun is not yet supported on mobile browsers.
204-
</p>
205-
<p>
206-
<a class="button" href="#" id="try_anyways">Try anyways</a>
207-
</p>`);
204+
<p>
205+
Rerun is not yet supported on mobile browsers.
206+
</p>
207+
<p>
208+
<a class="button" href="#" id="try_anyways">Try anyways</a>
209+
</p>
210+
`);
208211
document
209212
.querySelector("#try_anyways")
210213
.addEventListener("click", function (event) {
@@ -312,13 +315,14 @@
312315
"`navigator.gpu` is undefined. This indicates lack of WebGPU support.",
313316
);
314317
show_center_html(`
315-
<p class="strong">
316-
Missing WebGPU support.
317-
</p>
318-
<p class="subdued">
319-
This version of Rerun requires WebGPU support which is not available in your browser.
320-
Either try a different browser or use the WebGL version of Rerun.
321-
</p>`);
318+
<p class="strong">
319+
Missing WebGPU support.
320+
</p>
321+
<p class="subdued">
322+
This version of Rerun requires WebGPU support which is not available in your browser.
323+
Either try a different browser or use the WebGL version of Rerun.
324+
</p>
325+
`);
322326
return;
323327
}
324328

@@ -333,16 +337,17 @@
333337
document.getElementById("the_canvas_id").remove();
334338

335339
show_center_html(`
336-
<p class="strong">
337-
Rerun has crashed.
338-
</p>
339-
<pre align="left">${handle.panic_message()}</pre>
340-
<p>
341-
See the console for details.
342-
</p>
343-
<p>
344-
Reload the page to try again.
345-
</p>`);
340+
<p class="strong">
341+
Rerun has crashed.
342+
</p>
343+
<pre align="left">${handle.panic_message()}</pre>
344+
<p>
345+
See the console for details.
346+
</p>
347+
<p>
348+
Reload the page to try again.
349+
</p>
350+
`);
346351
} else {
347352
let delay_ms = 1000;
348353
setTimeout(check_for_panic, delay_ms);
@@ -381,15 +386,16 @@
381386

382387
hide_canvas();
383388
show_center_html(`
384-
<p>
385-
An error occurred during loading:
386-
</p>
387-
<p style="font-family:Courier New">
388-
${error}
389-
</p>
390-
<p style="font-size:14px">
391-
Make sure you use a modern browser with ${render_backend_name} and Wasm enabled.
392-
</p>`);
389+
<p>
390+
An error occurred during loading:
391+
</p>
392+
<p style="font-family:Courier New">
393+
${error}
394+
</p>
395+
<p style="font-size:14px">
396+
Make sure you use a modern browser with ${render_backend_name} and Wasm enabled.
397+
</p>
398+
`);
393399
}
394400
</script>
395401
</body>

0 commit comments

Comments
 (0)