Skip to content

Commit

Permalink
Fix #3939 - update firefox specific code in renderAd function (#3980)
Browse files Browse the repository at this point in the history
* update browser specific code in renderAd function

* update TODO comment
  • Loading branch information
jsnellbaker authored Jul 9, 2019
1 parent 95495bf commit 1086def
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 3 deletions.
11 changes: 10 additions & 1 deletion src/prebid.js
Original file line number Diff line number Diff line change
Expand Up @@ -325,7 +325,16 @@ $$PREBID_GLOBAL$$.renderAd = function (doc, id) {
const message = `Error trying to write ad. Ad render call ad id ${id} was prevented from writing to the main document.`;
emitAdRenderFail(PREVENT_WRITING_ON_MAIN_DOCUMENT, message, bid);
} else if (ad) {
doc.open('text/html', 'replace');
// will check if browser is firefox and below version 67, if so execute special doc.open()
// for details see: https://github.com/prebid/Prebid.js/pull/3524
// TODO remove this browser specific code at later date (when Firefox < 67 usage is mostly gone)
if (navigator.userAgent && navigator.userAgent.toLowerCase().indexOf('firefox/') > -1) {
const firefoxVerRegx = /firefox\/([\d\.]+)/;
let firefoxVer = navigator.userAgent.toLowerCase().match(firefoxVerRegx)[1]; // grabs the text in the 1st matching group
if (firefoxVer && parseInt(firefoxVer, 10) < 67) {
doc.open('text/html', 'replace');
}
}
doc.write(ad);
doc.close();
setRenderSize(doc, width, height);
Expand Down
2 changes: 0 additions & 2 deletions test/spec/unit/pbjs_api_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -990,7 +990,6 @@ describe('Unit: Prebid Module', function () {

beforeEach(function () {
doc = {
open: sinon.spy(),
write: sinon.spy(),
close: sinon.spy(),
defaultView: {
Expand Down Expand Up @@ -1041,7 +1040,6 @@ describe('Unit: Prebid Module', function () {
});
adResponse.ad = "<script type='text/javascript' src='http://server.example.com/ad/ad.js'></script>";
$$PREBID_GLOBAL$$.renderAd(doc, bidId);
assert.ok(doc.open, 'open method called');
assert.ok(doc.write.calledWith(adResponse.ad), 'ad was written to doc');
assert.ok(doc.close.called, 'close method called');
});
Expand Down

0 comments on commit 1086def

Please sign in to comment.