{"record":{"id":"dc4ab8105510bb59","repo":"angular/components","slug":"namespace-yt-not-found-cannot-construct-embedded","errorCode":null,"errorMessage":"Namespace YT not found, cannot construct embedded youtube player. Please install the YouTube Player API Reference for iframe Embeds: https://developers.google.com/youtube/iframe_api_reference","messagePattern":"Namespace YT not found, cannot construct embedded youtube player\\. Please install the YouTube Player API Reference for iframe Embeds: https://developers\\.google\\.com/youtube/iframe_api_reference","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"src/youtube-player/youtube-player.ts","lineNumber":508,"sourceCode":"   */\n  protected _load(playVideo: boolean) {\n    // Don't do anything if we're not in a browser environment.\n    if (!this._isBrowser) {\n      return;\n    }\n\n    // Might be clobbered by something like `<form id=\"YT\"><input name=\"Player\"></form>`.\n    if (\n      typeof window.YT !== 'object' ||\n      !window.YT ||\n      !window.YT.Player ||\n      typeof window.YT.Player !== 'function'\n    ) {\n      if (this.loadApi) {\n        this._isLoading = true;\n        loadApi(this._nonce);\n      } else if (this.showBeforeIframeApiLoads && (typeof ngDevMode === 'undefined' || ngDevMode)) {\n        throw new Error(\n          'Namespace YT not found, cannot construct embedded youtube player. ' +\n            'Please install the YouTube Player API Reference for iframe Embeds: ' +\n            'https://developers.google.com/youtube/iframe_api_reference',\n        );\n      }\n\n      const existingCallback = (window as YoutubeWindow).onYouTubeIframeAPIReady;\n\n      // The callback might be clobbered by an element with an ID of `onYouTubeIframeAPIReady`.\n      if (typeof existingCallback === 'function') {\n        this._existingApiReadyCallback = (window as YoutubeWindow).onYouTubeIframeAPIReady;\n      }\n\n      (window as YoutubeWindow).onYouTubeIframeAPIReady = () => {\n        this._existingApiReadyCallback?.();\n        this._ngZone.run(() => this._createPlayer(playVideo));\n      };\n    } else {","sourceCodeStart":490,"sourceCodeEnd":526,"githubUrl":"https://github.com/angular/components/blob/0411926e7d8ae06b32236ec1048a888cfad5abf2/src/youtube-player/youtube-player.ts#L490-L526","documentation":"The Angular Components YouTube player wrapper requires the external YouTube IFrame Player API script, which defines the global window.YT namespace. In dev mode, if window.YT is missing (or YT.Player is not a function) when the component tries to load, and the component is not configured to fetch the API itself, it throws this error telling you to install the YouTube IFrame API.","triggerScenarios":"A YouTubePlayer is instantiated and _load runs (via playVideo() or _conditionallyLoad) before window.YT exists, with loadApi=false so the component does not call loadApi(), and showBeforeIframeApiLoads=true causing the throw in ngDevMode.","commonSituations":"Forgetting to include https://www.youtube.com/iframe_api in index.html or loadIframeApi API; loading the app inside an environment where the YouTube script is blocked (ad blockers, CSP) or slow; setting [loadApi]=\"false\" without manually loading the API; calling playVideo() before the API finishes loading.","solutions":["Set the loadApi input to true so the component loads the YouTube IFrame API script itself: <youtube-player loadApi>","If loading the API manually, add <script src=\"https://www.youtube.com/iframe_api\"></script> to index.html and wait for window.onYouTubeIframeAPIReady before rendering/playing","Check that CSP or ad blockers aren't blocking scripts from youtube.com; whitelist them","Avoid calling playVideo() before the YT namespace is available (wait for the player's ready event)"],"exampleFix":"// before\n<youtube-player videoId=\"dQw4w9WgXcQ\" [loadApi]=\"false\"></youtube-player>\n// after\n<youtube-player videoId=\"dQw4w9WgXcQ\" [loadApi]=\"true\"></youtube-player>","handlingStrategy":"validation","validationCode":"function isYouTubeApiReady(): boolean {\n  return typeof window !== 'undefined' && !!(window as any).YT && typeof (window as any).YT.Player === 'function';\n}\nif (!isYouTubeApiReady()) console.warn('YT API not loaded yet; defer playVideo()');","typeGuard":"function hasYouTubeNamespace(w: Window): w is Window & { YT: { Player: Function } } {\n  return 'YT' in w && typeof (w as any).YT?.Player === 'function';\n}","tryCatchPattern":"try {\n  player.playVideo();\n} catch (e) {\n  if (String(e?.message).includes('Namespace YT not found')) {\n    loadIframeApi().then(() => player.playVideo());\n  } else { throw e; }\n}","preventionTips":["Use the loadApi input so the component manages script loading","Load the iframe_api script in index.html and gate rendering on onYouTubeIframeAPIReady","Check CSP allows scripts from https://www.youtube.com","Wait for the player ready event before calling playVideo"],"tags":["youtube","iframe-api","missing-dependency","dev-mode"],"backgroundTag":"missing-global-dependency","analyzedSha":"0411926e7d8ae06b32236ec1048a888cfad5abf2","analyzedAt":"2026-08-31T11:58:23.400Z","schemaVersion":2},"datasetVersion":"2026-08-31T14:17:45.589Z"}