From a7e9e7ad98f305de5563d122ca5e748805e23ae6 Mon Sep 17 00:00:00 2001 From: bretg Date: Fri, 21 Jun 2024 15:49:46 -0400 Subject: [PATCH 1/2] Adding some comments to nativeAssetManager.js Thought these might help the next poor soul who has to try to figure this thing out --- src/nativeAssetManager.js | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/nativeAssetManager.js b/src/nativeAssetManager.js index a0308038..4c6ef955 100644 --- a/src/nativeAssetManager.js +++ b/src/nativeAssetManager.js @@ -333,11 +333,17 @@ export function newNativeAssetManager(win, nativeTag, mkMessenger = prebidMessen renderPayload.ortb = data.ortb; } + // if there's a rendererUrl, we need to check whether it's already been loaded. + // The mark of it having been loaded is the existence of a window.renderAd() function. + // There are 3 scenarios: + // 1) it's already been loaded in some undocumented way by a publisher or the creative + // 2) it was already loaded from nativeRenderManager.js (which creates a script with is pb-native-renderer) + // 3) it hasn't been loaded yet if ((data.hasOwnProperty('rendererUrl') && data.rendererUrl) || (hasPbNativeData() && win.pbNativeData.hasOwnProperty('rendererUrl'))) { if (win.renderAd) { const newHtml = (win.renderAd && win.renderAd(renderPayload)) || ''; - renderAd(newHtml, data); + renderAd(newHtml, data); // this is the renderAd() below, not to be confused with the renderAd() supplied by the rendererUrl script :-/ } else if (document.getElementById('pb-native-renderer')) { document.getElementById('pb-native-renderer').addEventListener('load', function () { const newHtml = (win.renderAd && win.renderAd(renderPayload)) || ''; @@ -360,7 +366,7 @@ export function newNativeAssetManager(win, nativeTag, mkMessenger = prebidMessen const newHtml = replace(body, data); win.document.body.innerHTML = newHtml; - callback && callback(); + callback && callback(); // all the other scenarios hit the callback via renderAd() stopListening(); } } From 68301e7a86fc0a7df6477f0b24ecea857c6820e7 Mon Sep 17 00:00:00 2001 From: bretg Date: Mon, 24 Jun 2024 09:57:49 -0400 Subject: [PATCH 2/2] Update src/nativeAssetManager.js Co-authored-by: Demetrio Girardi --- src/nativeAssetManager.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/nativeAssetManager.js b/src/nativeAssetManager.js index 4c6ef955..370c6cf8 100644 --- a/src/nativeAssetManager.js +++ b/src/nativeAssetManager.js @@ -334,11 +334,11 @@ export function newNativeAssetManager(win, nativeTag, mkMessenger = prebidMessen } // if there's a rendererUrl, we need to check whether it's already been loaded. - // The mark of it having been loaded is the existence of a window.renderAd() function. // There are 3 scenarios: - // 1) it's already been loaded in some undocumented way by a publisher or the creative - // 2) it was already loaded from nativeRenderManager.js (which creates a script with is pb-native-renderer) + // 1) it's already been loaded (window.renderAd is present) + // 2) it is currently being loaded (through a script tag with id "pb-native-renderer") // 3) it hasn't been loaded yet + // 1 and 2 seem intended to work with logic in nativeRenderManager.js, which (sometimes) loads rendererUrl through a