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

Function getExtensionScripts

src/service/extension-script.js:200–237  ·  view source on GitHub ↗
(
  win,
  extensionId,
  version,
  latest,
  includeInserted = true
)

Source from the content-addressed store, hash-verified

198 * @return {!Array<!Element>}
199 */
200export 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.

Callers 4

reloadExtensionMethod · 0.90
importUnwrappedMethod · 0.90

Calls 3

parseExtensionUrlFunction · 0.85
isIntermediateExtensionFunction · 0.85
pushMethod · 0.45

Tested by

no test coverage detected