Skip to content

Commit 3eda89d

Browse files
committed
Add file:// detection tip to camera-based basics samples
Show a non-blocking yellow banner when opened via file:// suggesting the user serve the page from a web server for the best experience.
1 parent 5d5e089 commit 3eda89d

2 files changed

Lines changed: 18 additions & 0 deletions

File tree

basics/hello-world.html

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,15 @@ <h1 class="barcode-scanner-title">
2323
<div class="barcode-scanner-view" style="width: 100%; height: 70vh;"></div>
2424
<div class="result-view" style="width: 100%; height: calc(30vh - 80px); padding: 10px;overflow: auto;"></div>
2525
<script>
26+
// Detect file:// protocol and show a helpful tip
27+
if (location.protocol === "file:") {
28+
const tip = document.createElement("div");
29+
tip.style.cssText = "background:#fff3cd;border:1px solid #ffc107;color:#856404;padding:12px 16px;margin:8px;border-radius:6px;font:14px/1.5 sans-serif;text-align:center;";
30+
tip.innerHTML = '<strong>Tip:</strong> This page works via <code>file://</code>, but for the best experience, '
31+
+ 'serve it from a web server (e.g. HTTPS or localhost).';
32+
document.body.insertBefore(tip, document.body.firstChild);
33+
}
34+
2635
const resultView = document.querySelector(".result-view");
2736

2837
/** LICENSE ALERT - README

basics/scan-a-single-barcode.html

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,15 @@ <h1 class="barcode-scanner-title">
2323
<!-- This div will host the barcode scanner's camera view -->
2424
<div class="barcode-scanner-view"></div>
2525
<script>
26+
// Detect file:// protocol and show a helpful tip
27+
if (location.protocol === "file:") {
28+
const tip = document.createElement("div");
29+
tip.style.cssText = "background:#fff3cd;border:1px solid #ffc107;color:#856404;padding:12px 16px;margin:8px;border-radius:6px;font:14px/1.5 sans-serif;text-align:center;";
30+
tip.innerHTML = '<strong>Tip:</strong> This page works via <code>file://</code>, but for the best experience, '
31+
+ 'serve it from a web server (e.g. HTTPS or localhost).';
32+
document.body.insertBefore(tip, document.body.firstChild);
33+
}
34+
2635
/** LICENSE ALERT - README
2736
* To use the library, you need to first specify a license key.
2837
*

0 commit comments

Comments
 (0)