diff --git a/src/adRendering.js b/src/adRendering.js
index 3dca6968533..9eb894ec190 100644
--- a/src/adRendering.js
+++ b/src/adRendering.js
@@ -253,8 +253,12 @@ export function renderAdDirect(doc, adId, options) {
*/
export function insertLocatorFrame() {
if (!window.frames[PB_LOCATOR]) {
- const frame = createInvisibleIframe();
- frame.name = PB_LOCATOR;
- document.body.appendChild(frame);
+ if (!document.body) {
+ window.requestAnimationFrame(insertLocatorFrame);
+ } else {
+ const frame = createInvisibleIframe();
+ frame.name = PB_LOCATOR;
+ document.body.appendChild(frame);
+ }
}
}
diff --git a/test/pages/banner_sync.html b/test/pages/banner_sync.html
new file mode 100644
index 00000000000..71403ba5570
--- /dev/null
+++ b/test/pages/banner_sync.html
@@ -0,0 +1,97 @@
+
+
+
+
+
+
+ Prebid.js Banner Example
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+Prebid.js Banner Ad Unit Test
+
+
+
+
+
+
+
diff --git a/test/spec/e2e/banner/basic_banner_ad.spec.js b/test/spec/e2e/banner/basic_banner_ad.spec.js
index 511b1002d80..2d055743e8f 100644
--- a/test/spec/e2e/banner/basic_banner_ad.spec.js
+++ b/test/spec/e2e/banner/basic_banner_ad.spec.js
@@ -2,6 +2,7 @@ const expect = require('chai').expect;
const {setupTest, testPageURL} = require('../../../helpers/testing-utils');
const TEST_PAGE_URL = testPageURL('banner.html?pbjs_debug=true');
+const SYNC_PAGE_URL = testPageURL('banner_sync.html?pbjs_debug=true');
const CREATIVE_IFRAME_ID = 'google_ads_iframe_/19968336/header-bid-tag-0_0';
const CREATIVE_IFRAME_CSS_SELECTOR = 'iframe[id="' + CREATIVE_IFRAME_ID + '"]';
@@ -14,20 +15,25 @@ const EXPECTED_TARGETING_KEYS = {
'hb_bidder_appnexus': 'appnexus'
};
-setupTest({
- url: TEST_PAGE_URL,
- waitFor: CREATIVE_IFRAME_CSS_SELECTOR,
- expectGAMCreative: true
-}, 'Prebid.js Banner Ad Unit Test', function () {
- it('should load the targeting keys with correct values', async function () {
- const result = await browser.execute(function () {
- return window.pbjs.getAdserverTargeting('div-gpt-ad-1460505748561-1');
- });
- const targetingKeys = result['div-gpt-ad-1460505748561-1'];
+Object.entries({
+ 'synchronously': SYNC_PAGE_URL,
+ 'asynchronously': TEST_PAGE_URL,
+}).forEach(([t, testPage]) => {
+ setupTest({
+ url: testPage,
+ waitFor: CREATIVE_IFRAME_CSS_SELECTOR,
+ expectGAMCreative: true
+ }, `Prebid.js Banner Ad Unit Test (loading ${t})`, function () {
+ it('should load the targeting keys with correct values', async function () {
+ const result = await browser.execute(function () {
+ return window.pbjs.getAdserverTargeting('div-gpt-ad-1460505748561-1');
+ });
+ const targetingKeys = result['div-gpt-ad-1460505748561-1'];
- expect(targetingKeys).to.include(EXPECTED_TARGETING_KEYS);
- expect(targetingKeys.hb_adid).to.be.a('string');
- expect(targetingKeys.hb_adid_appnexus).to.be.a('string');
- expect(targetingKeys.hb_size).to.satisfy((size) => size === '300x250' || '300x600');
+ expect(targetingKeys).to.include(EXPECTED_TARGETING_KEYS);
+ expect(targetingKeys.hb_adid).to.be.a('string');
+ expect(targetingKeys.hb_adid_appnexus).to.be.a('string');
+ expect(targetingKeys.hb_size).to.satisfy((size) => size === '300x250' || '300x600');
+ });
});
});