MCPcopy Index your code
hub / github.com/ampproject/amphtml / maybeInstrumentsNodes

Function maybeInstrumentsNodes

3p/environment.js:98–125  ·  view source on GitHub ↗

* Instrument added nodes if they are instrumentable iframes. * @param {!Window} win * @param {!Array<!Node>|NodeList<!Node>|NodeList<!Element>|null} addedNodes

(win, addedNodes)

Source from the content-addressed store, hash-verified

96 * @param {!Array<!Node>|NodeList<!Node>|NodeList<!Element>|null} addedNodes
97 */
98function maybeInstrumentsNodes(win, addedNodes) {
99 for (let n = 0; n < addedNodes.length; n++) {
100 const node = addedNodes[n];
101 try {
102 if (node.tagName != 'IFRAME') {
103 continue;
104 }
105 const src = node.getAttribute('src');
106 const srcdoc = node.getAttribute('srcdoc');
107 if (src == null || /^(about:|javascript:)/i.test(src.trim()) || srcdoc) {
108 if (node.contentWindow) {
109 instrumentIframeWindow(node, win, node.contentWindow);
110 node.addEventListener('load', () => {
111 try {
112 instrumentIframeWindow(node, win, node.contentWindow);
113 } catch (e) {
114 console./*OK*/ error(e.message, e.stack);
115 }
116 });
117 } else if (srcdoc) {
118 instrumentSrcdoc(parent, node);
119 }
120 }
121 } catch (e) {
122 console./*OK*/ error(e.message, e.stack);
123 }
124 }
125}
126
127/**
128 * Installs a mutation observer in a window to look for iframes.

Callers 2

manageWin_Function · 0.85
installObserverFunction · 0.85

Calls 6

instrumentIframeWindowFunction · 0.85
instrumentSrcdocFunction · 0.85
getAttributeMethod · 0.80
testMethod · 0.45
addEventListenerMethod · 0.45
errorMethod · 0.45

Tested by

no test coverage detected