(head)
| 242 | * @return {!Array<{script: HTMLScriptElement, extensionId: string, extensionVersion: string}>} |
| 243 | */ |
| 244 | export 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 |
no test coverage detected