( win, extensionId, version, latest, includeInserted = true )
| 198 | * @return {!Array<!Element>} |
| 199 | */ |
| 200 | export function getExtensionScripts( |
| 201 | win, |
| 202 | extensionId, |
| 203 | version, |
| 204 | latest, |
| 205 | includeInserted = true |
| 206 | ) { |
| 207 | // Always ignore <script> elements that have a mismatched RTV. |
| 208 | const modifier = |
| 209 | ':not([i-amphtml-loaded-new-version])' + |
| 210 | (includeInserted ? '' : ':not([i-amphtml-inserted])'); |
| 211 | // We have to match against "src" because a few extensions, such as |
| 212 | // "amp-viewer-integration", do not have "custom-element" attribute. |
| 213 | const matches = win.document.head./*OK*/ querySelectorAll( |
| 214 | `script[src*="/${extensionId}-"]${modifier}` |
| 215 | ); |
| 216 | const filtered = []; |
| 217 | for (let i = 0; i < matches.length; i++) { |
| 218 | const match = matches[i]; |
| 219 | const urlParts = parseExtensionUrl(match.src); |
| 220 | if (!urlParts) { |
| 221 | continue; |
| 222 | } |
| 223 | const { |
| 224 | extensionId: scriptExtensionId, |
| 225 | extensionVersion: scriptExtensionVersion, |
| 226 | } = urlParts; |
| 227 | if ( |
| 228 | scriptExtensionId == extensionId && |
| 229 | (isIntermediateExtension(extensionId) || |
| 230 | scriptExtensionVersion == version || |
| 231 | (scriptExtensionVersion == LATEST_VERSION && latest)) |
| 232 | ) { |
| 233 | filtered.push(match); |
| 234 | } |
| 235 | } |
| 236 | return filtered; |
| 237 | } |
| 238 | |
| 239 | /** |
| 240 | * Get list of all the extension JS files. |
no test coverage detected