From 6a98f252f45c581f2b0efedf7c4c5b74cbcffc50 Mon Sep 17 00:00:00 2001 From: Dave Vandyke Date: Tue, 28 Nov 2023 11:47:04 +0000 Subject: [PATCH] Remove Engadget workaround from google-ima shim There was a workaround in the google-ima shim that applied only to www.engadget.com that set a current advert to be returned by AdEvent.getAd() and AdsManager.getCurrentAd(). When testing the website, I couldn't see that code-path being hit at all, so let's remove the workaround. Also, let's take care to return null instead of undefined as is specified[1]. In the future, we could expand this logic if necessary. I think setting the currentAd to new Ad() when the AdEvent.Type.LOADED event fires and back to null when AdEvent.Type.ALL_ADS_COMPLETED fires would make sense - but we would need to test that doesn't cause more website breakage first. 1 - https://developers.google.com/interactive-media-ads/docs/sdks/html5/client-side/reference/js/google.ima.AdEvent#getAd --- surrogates/google-ima.js | 20 ++++---------------- 1 file changed, 4 insertions(+), 16 deletions(-) diff --git a/surrogates/google-ima.js b/surrogates/google-ima.js index 2ce62d3..f08eab9 100644 --- a/surrogates/google-ima.js +++ b/surrogates/google-ima.js @@ -500,6 +500,7 @@ if (!window.google || !window.google.ima || !window.google.ima.VERSION) { } } + // eslint-disable-next-line no-unused-vars class Ad { constructor() { this._pi = new AdPodInfo(); @@ -650,22 +651,9 @@ if (!window.google || !window.google.ima || !window.google.ima.VERSION) { AdError.ErrorCode = {}; AdError.Type = {}; - const isEngadget = () => { - try { - for (const ctx of Object.values(window.vidible._getContexts())) { - const player = ctx.getPlayer(); - if (!player) { continue; } - const div = player.div; - if (!div) { continue; } - if (div.innerHTML.includes("www.engadget.com")) { - return true; - } - } - } catch (_) {} - return false; - }; - - const currentAd = isEngadget() ? undefined : new Ad(); + // TODO: Consider setting this to `new Ad()` when AdEvent.Type.LOADED fires + // and clearing it again after AdEvent.Type.ALL_ADS_COMPLETED fires. + const currentAd = null; class AdEvent { constructor(type) {