MCPcopy
hub / github.com/ampproject/amphtml / extensionScriptsInNode

Function extensionScriptsInNode

src/service/extension-script.js:244–270  ·  view source on GitHub ↗
(head)

Source from the content-addressed store, hash-verified

242 * @return {!Array<{script: HTMLScriptElement, extensionId: string, extensionVersion: string}>}
243 */
244export function extensionScriptsInNode(head) {
245 // ampdoc.getHeadNode() can return null.
246 if (!head) {
247 return [];
248 }
249 // Note: Some extensions don't have [custom-element] or [custom-template]
250 // e.g. amp-viewer-integration.
251 const list = head.querySelectorAll(
252 'script[custom-element],script[custom-template]'
253 );
254 const scripts = [];
255 for (let i = 0; i < list.length; i++) {
256 const script = list[i];
257 const extensionId =
258 script.getAttribute('custom-element') ||
259 script.getAttribute('custom-template');
260 const urlParts = parseExtensionUrl(script.src);
261 if (extensionId && urlParts) {
262 scripts.push({
263 script,
264 extensionId,
265 extensionVersion: urlParts.extensionVersion,
266 });
267 }
268 }
269 return scripts;
270}
271
272/**
273 * Verifies that an extension script is present in head for

Callers 3

stubElementsForDocFunction · 0.90
extensionScriptInNodeFunction · 0.85

Calls 3

parseExtensionUrlFunction · 0.85
getAttributeMethod · 0.80
pushMethod · 0.45

Tested by

no test coverage detected