|
| 1 | +/** |
| 2 | + * Slow-load hint shown during Pyodide initialisation on Microsoft Edge. |
| 3 | + * |
| 4 | + * Edge's "Enhance your security on the web" feature (a.k.a. Enhanced |
| 5 | + * Security Mode) disables the WebAssembly JIT on unfamiliar sites, |
| 6 | + * which makes Pyodide start-up 20-40x slower than on Chrome / Firefox. |
| 7 | + * Microsoft documents this explicitly and recommends adding the site |
| 8 | + * as an exception (see ``microsoft-edge-security-browse-safer`` page, |
| 9 | + * "Important" admonition): |
| 10 | + * |
| 11 | + * > Developers should be aware that the WebAssembly (WASM) interpreter |
| 12 | + * > running in enhanced security mode might not yield the expected |
| 13 | + * > level of performance. We recommend adding your site as an |
| 14 | + * > exception to opt-out of enhanced security mode for site users. |
| 15 | + * |
| 16 | + * This component shows a discreet, English-only hint after a delay, |
| 17 | + * but only when the user agent looks like Microsoft Edge. The hint is |
| 18 | + * unmounted as soon as the runtime finishes loading. |
| 19 | + * |
| 20 | + * Note: Chromium blocks ``<a href="edge://...">`` navigation from web |
| 21 | + * pages for security reasons, so the settings URL is exposed as a |
| 22 | + * copy-to-clipboard button rather than a real link. |
| 23 | + */ |
| 24 | + |
| 25 | +import { useEffect, useState } from "react"; |
| 26 | + |
| 27 | +/** Detect Microsoft Edge (Chromium). The UA token is ``Edg/`` — not |
| 28 | + * ``Edge/`` which was the legacy EdgeHTML browser. */ |
| 29 | +function isMicrosoftEdge(): boolean { |
| 30 | + if (typeof navigator === "undefined") return false; |
| 31 | + return /\bEdg\//.test(navigator.userAgent); |
| 32 | +} |
| 33 | + |
| 34 | +const HINT_DELAY_MS = 60_000; |
| 35 | +const EDGE_SETTINGS_URL = "edge://settings/privacy"; |
| 36 | +const MS_DOC_URL = |
| 37 | + "https://learn.microsoft.com/en-us/deployedge/microsoft-edge-security-browse-safer"; |
| 38 | + |
| 39 | +export function EdgeSlowLoadHint() { |
| 40 | + const [show, setShow] = useState(false); |
| 41 | + const [copied, setCopied] = useState(false); |
| 42 | + |
| 43 | + useEffect(() => { |
| 44 | + if (!isMicrosoftEdge()) return; |
| 45 | + const id = window.setTimeout(() => setShow(true), HINT_DELAY_MS); |
| 46 | + return () => window.clearTimeout(id); |
| 47 | + }, []); |
| 48 | + |
| 49 | + if (!show) return null; |
| 50 | + |
| 51 | + const copyUrl = async () => { |
| 52 | + try { |
| 53 | + await navigator.clipboard.writeText(EDGE_SETTINGS_URL); |
| 54 | + setCopied(true); |
| 55 | + window.setTimeout(() => setCopied(false), 2000); |
| 56 | + } catch { |
| 57 | + // Clipboard API unavailable (e.g. insecure context): silently ignore. |
| 58 | + } |
| 59 | + }; |
| 60 | + |
| 61 | + return ( |
| 62 | + <div className="plot-loading-edge-hint"> |
| 63 | + <div className="plot-loading-edge-hint-title"> |
| 64 | + Loading is unusually slow on Microsoft Edge? |
| 65 | + </div> |
| 66 | + <div className="plot-loading-edge-hint-body"> |
| 67 | + Edge's <strong>Enhance your security on the web</strong> setting |
| 68 | + disables the WebAssembly JIT compiler on unfamiliar sites, which can |
| 69 | + slow down Pyodide start-up by 20-40x.{" "} |
| 70 | + <a href={MS_DOC_URL} target="_blank" rel="noopener noreferrer"> |
| 71 | + Microsoft recommends adding the site as an exception |
| 72 | + </a>{" "} |
| 73 | + as the official workaround for WebAssembly-heavy applications: |
| 74 | + <ol> |
| 75 | + <li> |
| 76 | + Open the Edge settings page (Chromium blocks direct links to{" "} |
| 77 | + <code>edge://</code> URLs from web pages, so use the button below to |
| 78 | + copy the URL, then paste it into the address bar): |
| 79 | + <div className="plot-loading-edge-hint-url"> |
| 80 | + <code>{EDGE_SETTINGS_URL}</code> |
| 81 | + <button |
| 82 | + type="button" |
| 83 | + onClick={copyUrl} |
| 84 | + className="plot-loading-edge-hint-copy" |
| 85 | + > |
| 86 | + {copied ? "Copied!" : "Copy URL"} |
| 87 | + </button> |
| 88 | + </div> |
| 89 | + </li> |
| 90 | + <li> |
| 91 | + Under <em>Security</em>, make sure{" "} |
| 92 | + <em>Enhance your security on the web</em> is turned on, then click{" "} |
| 93 | + <em>Manage enhanced security for sites</em>. |
| 94 | + </li> |
| 95 | + <li> |
| 96 | + Under <em>Never use enhanced security for these sites</em>, click{" "} |
| 97 | + <em>Add a site</em> and enter the URL of this application (for |
| 98 | + example <code>https://datalab-platform.com</code>). |
| 99 | + </li> |
| 100 | + <li>Reload this page.</li> |
| 101 | + </ol> |
| 102 | + </div> |
| 103 | + </div> |
| 104 | + ); |
| 105 | +} |
0 commit comments