Skip to content

Commit 4fc71fb

Browse files
authored
Use scrollHeight when body has height 0 (#291)
1 parent 6c86379 commit 4fc71fb

File tree

2 files changed

+17
-5
lines changed

2 files changed

+17
-5
lines changed

src/nativeAssetManager.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -430,7 +430,7 @@ export function newNativeAssetManager(win, nativeTag, mkMessenger = prebidMessen
430430
stopListening();
431431
const resize = () => requestHeightResize(
432432
bid.adId,
433-
(document.body.clientHeight || document.body.offsetHeight),
433+
(document.body.clientHeight || document.body.offsetHeight || document.documentElement.scrollHeight),
434434
document.body.clientWidth > 1 ? document.body.clientWidth : undefined
435435
);
436436
document.readyState === 'complete' ? resize() : window.onload = resize;

test/spec/nativeAssetManager_spec.js

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -620,14 +620,26 @@ describe('nativeAssetManager', () => {
620620
expect(win.document.body.innerHTML).to.include(`<a href="http://www.example.com" target="_blank" class="pb-click">new value</a>`);
621621
});
622622

623+
function getResizeRequest() {
624+
return win.parent.postMessage.args
625+
.map(([msg]) => JSON.parse(msg))
626+
.find((msg) => msg.action === 'resizeNativeHeight')
627+
}
628+
623629
it('should not request width resize if width is 1', () => {
624630
sandbox.stub(document.body, 'clientWidth').get(() => 1);
625631
const nativeAssetManager = makeManager();
626632
nativeAssetManager.loadAssets(AD_ID);
627-
const resizeRequest = win.parent.postMessage.args
628-
.map(([msg]) => JSON.parse(msg))
629-
.find((msg) => msg.action === 'resizeNativeHeight')
630-
expect(resizeRequest.width).to.not.exist;
633+
expect(getResizeRequest().width).to.not.exist;
634+
});
635+
636+
it('should use scrollHeight if offsetHeight & clientHeight are 0', () => {
637+
sandbox.stub(document.body, 'clientHeight').get(() => 0);
638+
sandbox.stub(document.body, 'offsetHeight').get(() => 0);
639+
sandbox.stub(document.documentElement, 'scrollHeight').get(() => 123);
640+
const nativeAssetManager = makeManager();
641+
nativeAssetManager.loadAssets(AD_ID);
642+
expect(getResizeRequest().height).to.eql(123);
631643
})
632644

633645
it('should set the iframe to the width of the container', () => {

0 commit comments

Comments
 (0)