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

Function postMessageToWindows

src/iframe-helper.js:374–389  ·  view source on GitHub ↗
(iframe, targets, type, object, opt_is3P)

Source from the content-addressed store, hash-verified

372 * @param {boolean=} opt_is3P set to true if the iframe is 3p.
373 */
374export function postMessageToWindows(iframe, targets, type, object, opt_is3P) {
375 if (!iframe.contentWindow) {
376 return;
377 }
378 object['type'] = type;
379 object['sentinel'] = getSentinel_(iframe, opt_is3P);
380 let payload = object;
381 if (opt_is3P) {
382 // Serialize ourselves because that is much faster in Chrome.
383 payload = 'amp-' + JSON.stringify(object);
384 }
385 for (let i = 0; i < targets.length; i++) {
386 const target = targets[i];
387 target.win./*OK*/ postMessage(payload, target.origin);
388 }
389}
390
391/**
392 * Gets the sentinel string.

Callers 4

handleOneTimeRequest_Method · 0.90
postMessageFunction · 0.85
sendMethod · 0.85

Calls 3

getSentinel_Function · 0.85
stringifyMethod · 0.80
postMessageMethod · 0.45

Tested by

no test coverage detected