{"record":{"id":"ff5626bddcb61020","repo":"emberjs/ember.js","slug":"glimmer-runtime-needs-a-valid-globalthis-url","errorCode":null,"errorMessage":"@glimmer/runtime needs a valid \"globalThis.URL\"","messagePattern":"@glimmer/runtime needs a valid \"globalThis\\.URL\"","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"critical","filePath":"packages/@glimmer/runtime/lib/dom/sanitized-values.ts","lineNumber":113,"sourceCode":"\n      return protocol === null ? ':' : protocol;\n    };\n  } else if (typeof weirdURL === 'function') {\n    return (_url: string) => {\n      try {\n        let url = new weirdURL(_url);\n\n        return url.protocol;\n      } catch {\n        // any non-fully qualified url string will trigger an error (because there is no\n        // baseURI that we can provide; in that case we **know** that the protocol is\n        // \"safe\" because it isn't specifically one of the `badProtocols` listed above\n        // (and those protocols can never be the default baseURI)\n        return ':';\n      }\n    };\n  } else {\n    throw new Error(`@glimmer/runtime needs a valid \"globalThis.URL\"`);\n  }\n}\n\nlet _protocolForUrlImplementation: typeof protocolForUrl | undefined;\nfunction protocolForUrl(url: string): string {\n  if (!_protocolForUrlImplementation) {\n    _protocolForUrlImplementation = findProtocolForURL();\n  }\n  return _protocolForUrlImplementation(url);\n}\n\nexport function sanitizeAttributeValue(\n  element: SimpleElement,\n  attribute: string,\n  value: unknown\n): unknown {\n  if (value === null || value === undefined) {\n    return value;","sourceCodeStart":95,"sourceCodeEnd":131,"githubUrl":"https://github.com/emberjs/ember.js/blob/26f97246a8bf2e28edf26ac3093da2e86c04ffc5/packages/@glimmer/runtime/lib/dom/sanitized-values.ts#L95-L131","documentation":"protocolForUrl sanitizes URLs (for href/src attributes) by parsing them with globalThis.URL to extract the protocol and block dangerous protocols like javascript:. If the runtime environment does not provide a usable globalThis.URL constructor, Glimmer cannot sanitize URLs and throws this error at implementation setup time instead of proceeding unsafely.","triggerScenarios":"Calling protocolForUrl (indirectly via findProtocolForURL during attribute sanitization) in an environment where globalThis or globalThis.URL is undefined or not a valid constructor — e.g. very old runtimes, stripped/minified Node builds, or unusual embedded JS engines.","commonSituations":"SSR/Node versions without global URL (Node < 10); bundler polyfill shims that delete or stub globalThis.URL; restricted environments (some embedded engines, older JSDOM setups) lacking the URL global.","solutions":["Upgrade the runtime (Node/bundler output) to one with globalThis.URL available (Node >= 10, modern browsers)","Add a URL polyfill to globalThis before the Glimmer runtime initializes","Ensure bundler/polyfill config does not strip or stub globalThis.URL","Verify globalThis.URL works at app startup (typeof globalThis.URL === 'function')"],"exampleFix":"// before\n// no URL global in the environment\n// after\nimport { URL } from 'whatwg-url';\nif (typeof globalThis.URL !== 'function') {\n  globalThis.URL = URL;\n}","handlingStrategy":"validation","validationCode":"if (typeof globalThis !== 'object' || typeof globalThis.URL !== 'function') {\n  throw new Error('globalThis.URL is required before initializing the Glimmer runtime');\n}","typeGuard":"function hasUrlGlobal(env: unknown = globalThis): env is typeof globalThis & { URL: URLConstructor } {\n  return typeof (env as any)?.URL === 'function';\n}","tryCatchPattern":"try {\n  renderTemplate(...);\n} catch (e) {\n  if (String(e?.message).includes('globalThis.URL')) {\n    installUrlPolyfill(); // then retry or fail fast with a clear message\n  } else { throw e; }\n}","preventionTips":["Polyfill globalThis.URL early in SSR/embedded entry points","Target runtimes with URL support (Node >= 10, modern browsers)","Audit bundler polyfills/stubs that remove URL from globals","Smoke-test rendering in the target environment in CI"],"tags":["environment","url","ssr","glimmer"],"backgroundTag":"missing-global-polyfill","analyzedSha":"26f97246a8bf2e28edf26ac3093da2e86c04ffc5","analyzedAt":"2026-09-01T05:01:28.182Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}