Skip to content

Commit

Permalink
Added WebGL check and message for unsupported Android devices
Browse files Browse the repository at this point in the history
  • Loading branch information
morandd committed Nov 29, 2024
1 parent 2c81b2b commit 716a954
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 0 deletions.
56 changes: 56 additions & 0 deletions src/components/CheckWebGLSupport.astro
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@

<!-- A warning message box to inform the user that their browser does not support WebGL 2.0 -->
<dialog class="warning-message-box">
Sorry, this website will not work on this device.
This device is missing a required WebGL extension.
This is a known <a href="https://github.com/openlayers/openlayers/issues/15581">issue</a> with some Android devices.

<br/><br/>
Please visit from another device.<br/>
<button autofocus>Close</button>
</dialog>



<script>

// Javascript function to create a canvas, get a WebGL context, and check for the "OES_texture_float" extension
function WebGL_Has_OES_texture_float() {
const canvas = document.createElement('canvas');
const gl = canvas.getContext('webgl', { antialias: false });
if (!gl) return false;
try {
return gl.getExtension('OES_texture_float')!=null;
} catch (e) {
return false;
}
}

// On document load, check if WebGL 2.0 is supported
document.addEventListener('DOMContentLoaded', () => {
if (!WebGL_Has_OES_texture_float()) {
const el = document.querySelector('.warning-message-box') as HTMLDialogElement;
if (el) el.showModal();
}
});
</script>


<style>
.warning-message-box {
padding: 10px;
border-radius: 10px;
z-index: 1000;
text-align: center;
button {
margin-top: 1rem;
}
max-width: min(500px, 95vw);
border: 1px solid black;
&::backdrop {
backdrop-filter: blur(3px);
background-color: rgba(255, 255, 255, 0.5);
}

}
</style>
3 changes: 3 additions & 0 deletions src/pages/index.astro
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import Toaster from "../components/Toaster.astro";
import ChoosePalette from "../components/ChoosePalette.astro";
import COGURL from "../components/COGURL.astro";
import Matomo from "../components/Matomo.astro";
import CheckWebGLSupport from "../components/CheckWebGLSupport.astro";
export const prerender = true;
import "../style.css";
Expand All @@ -34,6 +35,8 @@ import "../style.css";

<Logos />

<CheckWebGLSupport />

<LowerRightCornerUI />

<COGURL />
Expand Down

0 comments on commit 716a954

Please sign in to comment.