Skip to content

Commit 320f9ed

Browse files
olafbuitelaaridettman
authored andcommitted
Consent module doublecall (#3399)
* * check if consent hook is already set * * removed debug code * * formatting
1 parent b1eeaa9 commit 320f9ed

File tree

1 file changed

+17
-11
lines changed

1 file changed

+17
-11
lines changed

modules/consentManagement.js

+17-11
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ export let allowAuction;
2020
export let staticConsentData;
2121

2222
let consentData;
23+
let addedConsentHook = false;
2324

2425
// add new CMPs here, with their dedicated lookup function
2526
const cmpCallMap = {
@@ -56,11 +57,11 @@ function lookupIabConsent(cmpSuccess, cmpError, hookConfig) {
5657
}
5758

5859
return {
59-
consentDataCallback: function(consentResponse) {
60+
consentDataCallback: function (consentResponse) {
6061
cmpResponse.getConsentData = consentResponse;
6162
afterEach();
6263
},
63-
vendorConsentsCallback: function(consentResponse) {
64+
vendorConsentsCallback: function (consentResponse) {
6465
cmpResponse.getVendorConsents = consentResponse;
6566
afterEach();
6667
}
@@ -82,7 +83,7 @@ function lookupIabConsent(cmpSuccess, cmpError, hookConfig) {
8283
// if the CMP is not found, the iframe function will call the cmpError exit callback to abort the rest of the CMP workflow
8384
try {
8485
cmpFunction = window.__cmp || utils.getWindowTop().__cmp;
85-
} catch (e) {}
86+
} catch (e) { }
8687

8788
if (utils.isFn(cmpFunction)) {
8889
cmpFunction('getConsentData', null, callbackHandler.consentDataCallback);
@@ -97,7 +98,7 @@ function lookupIabConsent(cmpSuccess, cmpError, hookConfig) {
9798
while (!cmpFrame) {
9899
try {
99100
if (f.frames['__cmpLocator']) cmpFrame = f;
100-
} catch (e) {}
101+
} catch (e) { }
101102
if (f === window.top) break;
102103
f = f.parent;
103104
}
@@ -139,13 +140,15 @@ function lookupIabConsent(cmpSuccess, cmpError, hookConfig) {
139140
function callCmpWhileInIframe(commandName, cmpFrame, moduleCallback) {
140141
/* Setup up a __cmp function to do the postMessage and stash the callback.
141142
This function behaves (from the caller's perspective identicially to the in-frame __cmp call */
142-
window.__cmp = function(cmd, arg, callback) {
143+
window.__cmp = function (cmd, arg, callback) {
143144
let callId = Math.random() + '';
144-
let msg = {__cmpCall: {
145-
command: cmd,
146-
parameter: arg,
147-
callId: callId
148-
}};
145+
let msg = {
146+
__cmpCall: {
147+
command: cmd,
148+
parameter: arg,
149+
callId: callId
150+
}
151+
};
149152
cmpCallbacks[callId] = callback;
150153
cmpFrame.postMessage(msg, '*');
151154
}
@@ -371,6 +374,9 @@ export function setConfig(config) {
371374
utils.logError(`consentManagement config with cmpApi: 'static' did not specify consentData. No consents will be available to adapters.`);
372375
}
373376
}
374-
$$PREBID_GLOBAL$$.requestBids.addHook(requestBidsHook, 50);
377+
if (!addedConsentHook) {
378+
$$PREBID_GLOBAL$$.requestBids.addHook(requestBidsHook, 50);
379+
}
380+
addedConsentHook = true;
375381
}
376382
config.getConfig('consentManagement', config => setConfig(config.consentManagement));

0 commit comments

Comments
 (0)