prebid / prebid-universal-creative

Apache License 2.0
43 stars 71 forks source link

SafeFrames don't resize #66

Closed benjaminclot closed 5 years ago

benjaminclot commented 5 years ago

Describe the bug When using SafeFrames, the GPT iFrame doesn't resize correctly and stays at 1x1.

To Reproduce Steps to reproduce the behavior:

  1. Take this example: http://prebid.org/dev-docs/examples/adunit-refresh.html (which, by the way, needs some updating to work)
  2. Enable SafeFrames
  3. Refresh the ad (I also enabled a first call and debug mode) Demo: https://adverline-gam.glitch.me/tests/safeframe.html

Expected behavior The GPT SafeFrame should resize to match its content ad. Obviously, this problem doesn't occur with AdSense/AdX ads, which are also enabled. Some refreshes may be needed to have header bidding winning the auction.

Desktop/Smartphone

Strangely Some header bidding ads seem to work (very rare).

Temporary fix Will cause bugs eventually.

pbjs.onEvent('bidWon', (bid) => {
  if (bid.mediaType === 'banner') {
    const slot = window.googletag.pubads().getSlots()
      .find(s => s.getSlotElementId() == bid.adUnitCode);
    const safeFrame = document.querySelector(`#google_ads_iframe_${slot.getSlotId().getId().replace(/(\.|\/)/g, '\\$1')}[data-is-safeframe="true"]`);

    if (safeFrame) {
      safeFrame.style.height = `${bid.height}px`;
      safeFrame.style.width = `${bid.width}px`;
    }
  }
});
benjaminclot commented 5 years ago

ping @jaiminpanchal27 @jsnellbaker @idettman @mkendall07

Can anybody comment on this? This is a critical bug at it effectively blocks the usage of SafeFrames (at least with GAM).

benjaminclot commented 5 years ago

Any input on this issue would be most welcome.

jaiminpanchal27 commented 5 years ago

@benjaminclot Thanks for submitting the issue. I was able to reproduce the issue with the steps you shared. Basically Prebid's resize function isn't working as it should. I will put up a PR today.

benjaminclot commented 5 years ago

Fixed by this PR: https://github.com/prebid/Prebid.js/pull/3988