{"record":{"id":"f20f953f3ca69657","repo":"dotnet/AspNetCore.Docs","slug":"must-provide-a-non-empty-value-for-the-src-attri","errorCode":null,"errorMessage":"Must provide a non-empty value for the \"src\" attribute.","messagePattern":"Must provide a non-empty value for the \"src\" attribute\\.","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"aspnetcore/blazor/includes/js-interop/blazor-page-script.md","lineNumber":6,"sourceCode":"```javascript\nconst pageScriptInfoBySrc = new Map();\n\nfunction registerPageScriptElement(src) {\n  if (!src) {\n    throw new Error('Must provide a non-empty value for the \"src\" attribute.');\n  }\n\n  let pageScriptInfo = pageScriptInfoBySrc.get(src);\n\n  if (pageScriptInfo) {\n    pageScriptInfo.referenceCount++;\n  } else {\n    pageScriptInfo = { referenceCount: 1, module: null };\n    pageScriptInfoBySrc.set(src, pageScriptInfo);\n    initializePageScriptModule(src, pageScriptInfo);\n  }\n}\n\nfunction unregisterPageScriptElement(src) {\n  if (!src) {\n    return;\n  }\n","sourceCodeStart":1,"sourceCodeEnd":24,"githubUrl":"https://github.com/dotnet/AspNetCore.Docs/blob/c67a80103a1a74db20784debd919c7fdda96c510/aspnetcore/blazor/includes/js-interop/blazor-page-script.md#L1-L24","documentation":"JavaScript guard throw inside registerPageScriptElement: if the 'src' argument is falsy (undefined, empty string, null) it throws because the page-script reference-counting map keys modules by src and cannot register an entry without a unique script URL. Used by the Blazor PageScript custom element helper that manages JS modules across navigations.","triggerScenarios":"A <script type=\"text/javascript\" src=\"\"> or a PageScript element whose src attribute resolves to empty; calling registerPageScriptElement('') programmatically; an attribute binding that evaluates to undefined at render time.","commonSituations":"Dynamic src binding in a Razor template that is sometimes empty; copy/paste of the PageScript element with the src omitted; build/bundler stripping the src; attribute set from a configuration value that is missing.","solutions":["Always supply a non-empty, resolvable script path on the PageScript src attribute.","Validate src before binding: only render the PageScript element when the URL is present.","Default src to a known module path when configuration is absent.","Add a unit/runtime assertion that src is a non-empty string before calling register."],"exampleFix":"// before\nfunction registerPageScriptElement(src) {\n  if (!src) {\n    throw new Error('Must provide a non-empty value for the \"src\" attribute.');\n  }\n  // ...\n}\n\n// after — caller-side guard before rendering the element\n@if (!string.IsNullOrWhiteSpace(ScriptSrc))\n{\n    <PageScript Src=\"@ScriptSrc\" />\n}\nelse\n{\n    <div class=\"text-warning\">Script source not configured.</div>\n}","handlingStrategy":"validation","validationCode":"// Guard before calling register\nif (typeof src !== 'string' || src.trim() === '') {\n  console.warn('PageScript src is empty; skipping registration.');\n  return;\n}","typeGuard":"function isValidSrc(src) { return typeof src === 'string' && src.trim().length > 0; }","tryCatchPattern":"try { registerPageScriptElement(src); }\ncatch (e) {\n  console.error('Failed to register page script:', e.message);\n}","preventionTips":["Always bind a concrete, non-empty src on PageScript elements.","Conditionally render the element only when src is set.","Default src from configuration when missing.","Validate src at the call site before registering."],"tags":["blazor","javascript","pagescript","validation","attribute"],"backgroundTag":null,"analyzedSha":"c67a80103a1a74db20784debd919c7fdda96c510","analyzedAt":"2026-08-13T17:46:11.763Z","schemaVersion":2},"datasetVersion":"2026-08-13T19:17:28.613Z"}