| 19 | // prefers a same-origin derpmap.json if the host serves one and |
| 20 | // otherwise falls back to the canonical map. |
| 21 | async function pickDERPMapURL() { |
| 22 | if (params.get("derpmap")) { |
| 23 | return new URL(params.get("derpmap"), location.href).toString(); |
| 24 | } |
| 25 | if (location.hostname.endsWith(".github.io")) { |
| 26 | return canonicalDERPMapURL; |
| 27 | } |
| 28 | const sameOrigin = new URL("derpmap.json", location.href).toString(); |
| 29 | try { |
| 30 | const resp = await fetch(sameOrigin, { method: "HEAD" }); |
| 31 | if (resp.ok) { |
| 32 | return sameOrigin; |
| 33 | } |
| 34 | } catch (e) {} |
| 35 | return canonicalDERPMapURL; |
| 36 | } |
| 37 | const derpMapURL = await pickDERPMapURL(); |
| 38 | |
| 39 | // tcTest is the state surface polled by the headless-browser |