Skip to content

Commit 8d42640

Browse files
Muhammad UbaidhiUbaiddgirardi
authored
Bugfix: Update adRendering.js styling for iframe in case of insterstitial ads (prebid#12975)
* update styling for frame in case of instl ads * Revert "update styling for frame in case of instl ads" This reverts commit 0470efc. * AdRendering file update for interstitial iframe handling * Revert "AdRendering file update for interstitial iframe handling" This reverts commit 6473929. * adding style without relying on frame id and display:block * Update style.width/height in direct rendering * Core: set instl flag on bid responses * Core: do not resize remote creative frames for interstitials * Core: include instl flag in cross-frame messages * Revert "adding style without relying on frame id and display:block" This reverts commit d957586. * iframe handling for missing safeframes * core: resize interstitials' inner iframe --------- Co-authored-by: ubaid <ubaid@advergic.com> Co-authored-by: Demetrio Girardi <dgirardi@prebid.org>
1 parent 39885b0 commit 8d42640

File tree

9 files changed

+93
-9
lines changed

9 files changed

+93
-9
lines changed

creative/renderers/display/renderer.js

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import {ERROR_NO_AD} from './constants.js';
22

3-
export function render({ad, adUrl, width, height}, {mkFrame}, win) {
3+
export function render({ad, adUrl, width, height, instl}, {mkFrame}, win) {
44
if (!ad && !adUrl) {
55
throw {
66
reason: ERROR_NO_AD,
@@ -19,6 +19,12 @@ export function render({ad, adUrl, width, height}, {mkFrame}, win) {
1919
attrs.srcdoc = ad;
2020
}
2121
doc.body.appendChild(mkFrame(doc, attrs));
22+
if (instl && win.frameElement) {
23+
// interstitials are rendered in a nested iframe that needs to be sized
24+
const style = win.frameElement.style;
25+
style.width = width ? `${width}px` : '100vw';
26+
style.height = height ? `${height}px` : '100vh';
27+
}
2228
}
2329
}
2430

libraries/creative-renderer-display/renderer.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/adRendering.js

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ function creativeMessageHandler(deps) {
127127
}
128128

129129
export const getRenderingData = hook('sync', function (bidResponse, options) {
130-
const {ad, adUrl, cpm, originalCpm, width, height} = bidResponse
130+
const {ad, adUrl, cpm, originalCpm, width, height, instl} = bidResponse
131131
const repl = {
132132
AUCTION_PRICE: originalCpm || cpm,
133133
CLICKTHROUGH: options?.clickUrl || ''
@@ -136,7 +136,8 @@ export const getRenderingData = hook('sync', function (bidResponse, options) {
136136
ad: replaceMacros(ad, repl),
137137
adUrl: replaceMacros(adUrl, repl),
138138
width,
139-
height
139+
height,
140+
instl
140141
};
141142
})
142143

@@ -256,9 +257,16 @@ export function renderAdDirect(doc, adId, options) {
256257
emitAdRenderFail(Object.assign({id: adId, bid}, {reason, message}));
257258
}
258259
function resizeFn(width, height) {
259-
if (doc.defaultView && doc.defaultView.frameElement) {
260-
width && (doc.defaultView.frameElement.width = width);
261-
height && (doc.defaultView.frameElement.height = height);
260+
const frame = doc.defaultView?.frameElement;
261+
if (frame) {
262+
if (width) {
263+
frame.width = width;
264+
frame.style.width && (frame.style.width = `${width}px`);
265+
}
266+
if (height) {
267+
frame.height = height;
268+
frame.style.height && (frame.style.height = `${height}px`);
269+
}
262270
}
263271
}
264272
const messageHandler = creativeMessageHandler({resizeFn});

src/auction.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -636,8 +636,11 @@ function getPreparedBidForAuction(bid, {index = auctionManager.index} = {}) {
636636
// but others to not be set yet (like priceStrings). See #1372 and #1389.
637637
events.emit(EVENTS.BID_ADJUSTMENT, bid);
638638

639+
const adUnit = index.getAdUnit(bid);
640+
bid.instl = adUnit?.ortb2Imp?.instl === 1;
641+
639642
// a publisher-defined renderer can be used to render bids
640-
const bidRenderer = index.getBidRequest(bid)?.renderer || index.getAdUnit(bid).renderer;
643+
const bidRenderer = index.getBidRequest(bid)?.renderer || adUnit.renderer;
641644

642645
// a publisher can also define a renderer for a mediaType
643646
const bidObjectMediaType = bid.mediaType;

src/secureCreatives.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,10 @@ function handleEventRequest(reply, data, adObject) {
135135
return handleCreativeEvent(data, adObject);
136136
}
137137

138-
export function resizeRemoteCreative({adId, adUnitCode, width, height}) {
138+
export function resizeRemoteCreative({instl, adId, adUnitCode, width, height}) {
139+
// do not resize interstitials - the creative frame takes the full screen and sizing of the ad should
140+
// be handled within it.
141+
if (instl) return;
139142
function getDimension(value) {
140143
return value ? value + 'px' : '100%';
141144
}

test/spec/auctionmanager_spec.js

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1266,6 +1266,31 @@ describe('auctionmanager.js', function () {
12661266
auction.callBids();
12671267
expect(auction.getBidsReceived()[0].ttlBuffer).to.eql(0);
12681268
});
1269+
1270+
[
1271+
{
1272+
request: 1,
1273+
response: true
1274+
},
1275+
{
1276+
request: 0,
1277+
response: false
1278+
},
1279+
{
1280+
request: 2,
1281+
response: false
1282+
},
1283+
{
1284+
request: undefined,
1285+
response: false
1286+
}
1287+
].forEach(({request, response}) => {
1288+
it(`sets bidResponse.instl to ${response} if adUnit.ortb2Imp.instl is ${request}`, () => {
1289+
adUnits[0].ortb2Imp = {instl: request};
1290+
auction.callBids();
1291+
expect(auction.getBidsReceived()[0].instl).to.equal(response);
1292+
})
1293+
})
12691294
});
12701295

12711296
describe('when auction timeout is 20', function () {

test/spec/creative/displayRenderer_spec.js

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,5 +75,28 @@ describe('Creative renderer - display', () => {
7575
runRenderer({ad: 'mock'});
7676
expect(doc.body.style.height).to.eql('100%');
7777
expect(doc.body.parentElement.style.height).to.eql('100%');
78+
});
79+
80+
it('sizes frame element if instl = true', () => {
81+
win.frameElement = { style: {}};
82+
runRenderer({
83+
ad: 'mock',
84+
width: 123,
85+
height: 321,
86+
instl: true
87+
});
88+
expect(win.frameElement.style).to.eql({
89+
width: '123px',
90+
height: '321px'
91+
})
92+
});
93+
94+
it('does not choke if no frame element can be found', () => {
95+
runRenderer({
96+
ad: 'mock',
97+
width: 123,
98+
height: 321,
99+
instl: true
100+
});
78101
})
79102
})

test/spec/unit/adRendering_spec.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,12 @@ describe('adRendering', () => {
6363
bidResponse = {};
6464
});
6565

66+
it('should carry over instl', () => {
67+
bidResponse.instl = true;
68+
const result = getRenderingData(bidResponse);
69+
expect(result.instl).to.be.true;
70+
});
71+
6672
['ad', 'adUrl'].forEach((prop) => {
6773
describe(`on ${prop}`, () => {
6874
it('replaces AUCTION_PRICE macro', () => {

test/spec/unit/secureCreatives_spec.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -579,5 +579,15 @@ describe('secureCreatives', () => {
579579
sinon.assert.called(slots[1].getSlotElementId);
580580
sinon.assert.calledWith(document.getElementById, 'div2');
581581
});
582+
583+
it('should not resize interstitials', () => {
584+
resizeRemoteCreative({
585+
instl: true,
586+
adId: 'adId',
587+
width: 300,
588+
height: 250,
589+
});
590+
sinon.assert.notCalled(document.getElementById);
591+
})
582592
})
583593
});

0 commit comments

Comments
 (0)