Skip to content

Commit

Permalink
AdagioBidAdapter: don't try to compute slot position if element is hi…
Browse files Browse the repository at this point in the history
…dden (prebid#11033)
  • Loading branch information
osazos authored Feb 1, 2024
1 parent 7f0732f commit 30513cf
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 11 deletions.
10 changes: 3 additions & 7 deletions modules/adagioBidAdapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -795,16 +795,12 @@ function getSlotPosition(adUnitElementId) {
const scrollLeft = wt.pageXOffset || docEl.scrollLeft || body.scrollLeft;

const elComputedStyle = wt.getComputedStyle(domElement, null);
const elComputedDisplay = elComputedStyle.display || 'block';
const mustDisplayElement = elComputedDisplay === 'none';
const mustDisplayElement = elComputedStyle.display === 'none';

if (mustDisplayElement) {
domElement.style = domElement.style || {};
const originalDisplay = domElement.style.display;
domElement.style.display = 'block';
box = domElement.getBoundingClientRect();
domElement.style.display = originalDisplay || null;
logWarn(LOG_PREFIX, 'The element is hidden. The slot position cannot be computed.');
}

position.x = Math.round(box.left + scrollLeft - clientLeft);
position.y = Math.round(box.top + scrollTop - clientTop);
} catch (err) {
Expand Down
7 changes: 3 additions & 4 deletions test/spec/modules/adagioBidAdapter_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -1497,8 +1497,8 @@ describe('Adagio bid adapter', () => {
expect(result.user_timestamp).to.be.a('String');
});

it('should return `adunit_position` feature when the slot is hidden', function () {
const elem = fixtures.getElementById();
it('should return `adunit_position` feature when the slot is hidden with value 0x0', function () {
const elem = fixtures.getElementById('0', '0', '0', '0');
sandbox.stub(window.top.document, 'getElementById').returns(elem);
sandbox.stub(window.top, 'getComputedStyle').returns({ display: 'none' });
sandbox.stub(utils, 'inIframe').returns(false);
Expand All @@ -1516,8 +1516,7 @@ describe('Adagio bid adapter', () => {
const requests = spec.buildRequests([bidRequest], bidderRequest);
const result = requests[0].data.adUnits[0].features;

expect(result.adunit_position).to.match(/^[\d]+x[\d]+$/);
expect(elem.style.display).to.equal(null); // set null to reset style
expect(result.adunit_position).to.equal('0x0');
});
});

Expand Down

0 comments on commit 30513cf

Please sign in to comment.