Google IMA SDK HTML5 Chrome back button issue ( possibly bfcache issue )

419 views
Skip to first unread message

Dan Tirdea

unread,
Nov 10, 2016, 1:17:25 PM11/10/16
to Interactive Media Ads SDK
Hi,


I've successfully implemented the HTML5 Goolge IMA in my custom HTML5 video player.

Most of the sites using the player are video sharing websites, so the behavior of the user ( visitor ) is to navigate through multiple pages that implements the video player.

The issue appears when the user hits the back button of the browser.
Within the Ads container, after initialization, is an IFRAME:

<iframe src="http://imasdk.googleapis.com/js/core/bridge3.151.1_en.html#goog_556868638" allowfullscreen="" style="border: 0px; opacity: 0; margin: 0px; padding: 0px; position: relative;"></iframe>


The IFRAME  has the following javascript code inside <body> tag:


<script type="text/javascript">
      // Initialize the bridge on script execution to handle connecting when embedded.
      window.addEventListener('load', function() {
        new ima.ElementBridge();
      },
      false); // useCapture
    </script>

The problem is that the IFRAME's source is cached and the load event is never fired, so the whole IMA environment is not initialized.

Do you have any thoughts about how to deal with this issue ?


Thanks,
Dan

Chris Feldman (IMA SDK Team)

unread,
Nov 10, 2016, 2:20:15 PM11/10/16
to Interactive Media Ads SDK
Hi Dan,

Thank you for reaching out to IMA Support. I need some more information before I can try to replicate your issue.

1. Can you clarify for me the exact user actions being taken before the back button is pressed? And also the exact behavior seen after it is pressed?
2. Are you using VPAID ads?
3. Are you able to replicate this behavior on the IMA for HTML5 sample website (IMA Sample Website)?

Thank you,
Chris Feldman
IMA SDK Team

Daniel Tirdea

unread,
Nov 11, 2016, 6:59:04 AM11/11/16
to ima-sdk
Hi Chris,


Thanks for the quick answer.
We can replicate it on the sample website, here are the steps to reproduce the issue:

Click the sample tag and then the play video icon. Ad will start.

2. In the same browser tab, change the location with https://googleads.github.io/googleads-ima-html5/advanced/?test=2 and hit enter
Click the sample tag and then the play video icon. Ad will start.

3. Same as before with this url: https://googleads.github.io/googleads-ima-html5/advanced/?test=3 and hit enter.
Click the sample tag and then the play video icon. Ad will start.


You will have to do those steps to simulate a user browsing several pages in the same website, tricking the browser to cache those pages and provide you an action on the back button.


Now please hit the back button of your browser and click the play icon from the video player.
You will notice that the video doesn't start after the first play click, you will need to click it again to start the video.

The expected behavior was to show the ad or to raise an event/error that can be handled.
It crashes silently instead, no errors/warnings  given.

The explanation for this is in my first email.


Best,
Daniel




--
You received this message because you are subscribed to the Google Groups "Interactive Media Ads SDK" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ima-sdk+unsubscribe@googlegroups.com.
To post to this group, send email to ima...@googlegroups.com.
Visit this group at https://groups.google.com/group/ima-sdk.
For more options, visit https://groups.google.com/d/optout.



--

--
Kind regards,
Dan TIRDEA

Vu Chau (IMA SDK Team)

unread,
Nov 11, 2016, 12:06:23 PM11/11/16
to Interactive Media Ads SDK
Hi Dan,

Chris is out of office today, so I'll be assisting with this case on his behalf.

It looks like there might be a confusion here.  Our Play button is only intended to play the ad.  It will not make a new ad request and reinitialize the SDK for you if you are back to the page.

If you would like the SDK to re-initialize and start ad playback, you would need to separate the request and the playback logic.  I put together a custom build for that, where I have one button that initializes the SDK and makes the ad request, and another button for playing the ad.  When you navigate away and back to the page, simply re-request before you hit Play.

Let me know if you have any questions,

Vu Chau
IMA SDK Team
To unsubscribe from this group and stop receiving emails from it, send an email to ima-sdk+u...@googlegroups.com.

To post to this group, send email to ima...@googlegroups.com.
Visit this group at https://groups.google.com/group/ima-sdk.
For more options, visit https://groups.google.com/d/optout.

Daniel Tirdea

unread,
Nov 11, 2016, 4:57:11 PM11/11/16
to ima-sdk

Hi Vu,

Thanks for the quick answer and for the sample.

The main ideea is that the behavior on video sharing websites, the player should auto-play the content, so the preroll ad too. At least on desktop and tablets as you need a user click/tap to be able o play video on mobile.

The sample you've put togheter is working fine, but is not the desired workflow.

Adding this to my first email should complete te big picture.

Any way this could be acomplished?

Thanks,
Daniel


To unsubscribe from this group and stop receiving emails from it, send an email to ima-sdk+unsubscribe@googlegroups.com.

Vu Chau (IMA SDK Team)

unread,
Nov 11, 2016, 5:20:50 PM11/11/16
to Interactive Media Ads SDK
Hi Dan,

That use case would be something outside of the SDK as far as ad playback within one session is concerned.  Of course the sample example is by no means feature complete.  You are free to modify it to suit your particular use case.

Since you would like the ad to autoplay, theoretically you could place the logic that initializes the SDK and makes the ad request on page load.  Once you get the onAdsManagerLoaded event, indicating the VAST response has been received and parsed, feel free to make a dynamic call to adsManager.start() to start ad playback. I've modified the same example to illustrate that.

I put in some logging, and it looks like when you are back to the page, a new ad request isn't executed (but we do get a new adDisplayContainer).  I'll find out if this is intended behavior or not.  onAdsManagerLoaded isn't called here unless a new ad request is made.

Vu Chau
IMA SDK Team

Vu Chau (IMA SDK Team)

unread,
Nov 11, 2016, 10:09:31 PM11/11/16
to Interactive Media Ads SDK
Hi Dan,

Just updated my sample again to get as close to your workflow as possible.  The ad should autoplay on each page load.  When you navigate away and back to the ad page, the SDK will re-init and play the ad again.

The idea is we wait a couple of ms after each page load to try to init/re-init the SDK.  This wait is essential as there might be asynchronous operations happening on the page prior to allocating an adDisplayContainer.  We don't want to do that too early; if we do, our adDisplayContainer won't be registered, the ad request won't send, and we won't have an adsManager.  

I recommend tweaking this value based on your testings.  I'll find out if this is something we can have better control over.

Vu

Daniel Tirdea

unread,
Nov 14, 2016, 9:29:13 AM11/14/16
to ima-sdk
Hi Vu,

I really appreciate all your effort on solving this issue.
Your demo page really helped me.

So, once again, thanks a lot for all your help.

Daniel

To unsubscribe from this group and stop receiving emails from it, send an email to ima-sdk+unsubscribe@googlegroups.com.

To post to this group, send email to ima...@googlegroups.com.
Visit this group at https://groups.google.com/group/ima-sdk.
For more options, visit https://groups.google.com/d/optout.

Vu Chau (IMA SDK Team)

unread,
Nov 14, 2016, 10:09:46 AM11/14/16
to Interactive Media Ads SDK
Glad to be of help! Let us know if you need anything else.

Vu

Szymon Fraszczak

unread,
Jan 26, 2017, 9:13:18 AM1/26/17
to Interactive Media Ads SDK
Hello Vu,

Did you have a chance to take a look at this issue? Setting the timeout sounds a bit tricky and it seems that issue still occurs. I was able to reproduce the issue on your test page after a few tries. 

I managed to prevent browser from caching bridge.html iframe by resetting iframe location just after creating AdDisplayContainer:

iframe.contentWindow.location.href = iframe.src;

It solves the issue but it's ugly and I'm not sure if it's safe because it cancels initial request for bridge.html on "regular" page visit. Is it possible to solve this issue on your side?

Thanks,

Chris Feldman (IMA SDK Team)

unread,
Jan 26, 2017, 2:44:37 PM1/26/17
to Interactive Media Ads SDK
Hi Szymon,

We're aware of the complicated relationship between the back button and cached SDK elements. There are currently no 'perfect' solutions for this issue and Vu's answer above is the best work-around we have. The handling of the loading and reloading of pages will vary based on each implementation. I would suggest taking a look at the source for Vu's sample page and adapting the solution to best suit your own needs. 

The solution you've found might work, but if it cancels the initial request for bridge.html then it'll likely have unintended effects on SDK performance.

Let me know if you continue to have issues.

Regards,
Chris Feldman
IMA SDK Team

dh...@gamezop.co

unread,
Nov 9, 2017, 3:26:01 AM11/9/17
to Interactive Media Ads SDK
Hi Vu Chau

I'm still not able to figure this out. I checked the example you gave here - http://www.chauduyphanvu1.com/IMA_ReInit/
If you set window.location= 'http://www.chauduyphanvu1.com/' and then window.history.back()
Then you will see that adsManagerLoaed event is not being fired by SDK. I am facing a similar issue. How to solve this? Any help would be appreciated. 

Thanks
Dhruv

Chris Feldman (IMA SDK Team)

unread,
Nov 9, 2017, 2:57:50 PM11/9/17
to Interactive Media Ads SDK
Hi Dhruv,

Thank you for reaching out to support. At this time, the recommended way for dealing with the chrome back button issue is to implement a very short delay before you initialize any SDK components. Here is an example of what that might look like with our Advanced Sample. The delay is implemented here, and is just 50 ms.

If you continue to have issues, please open a new thread on the forum. For tracking purposes, we like to avoid re-opening old threads.

Thanks!
Chris Feldman
IMA SDK Team

Reply all
Reply to author
Forward
0 new messages