• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

prebid / Prebid.js / #298

29 May 2025 11:21AM UTC coverage: 82.464% (-7.7%) from 90.144%
#298

push

travis-ci

prebidjs-release
Prebid 9.45.0 release

12606 of 17518 branches covered (71.96%)

18622 of 22582 relevant lines covered (82.46%)

157.38 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

51.16
/src/debugging.js
1
import {config} from './config.js';
2
import {getHook, hook} from './hook.js';
3
import {getGlobal} from './prebidGlobal.js';
4
import {logMessage, prefixLog} from './utils.js';
5
import {createBid} from './bidfactory.js';
6
import {loadExternalScript} from './adloader.js';
7
import {PbPromise} from './utils/promise.js';
8
import { MODULE_TYPE_PREBID } from './activities/modules.js';
9

10
export const DEBUG_KEY = '__$$PREBID_GLOBAL$$_debugging__';
1✔
11

12
function isDebuggingInstalled() {
13
  return getGlobal().installedModules.includes('debugging');
×
14
}
15

16
function loadScript(url) {
17
  return new PbPromise((resolve) => {
×
18
    loadExternalScript(url, MODULE_TYPE_PREBID, 'debugging', resolve);
×
19
  });
20
}
21

22
export function debuggingModuleLoader({alreadyInstalled = isDebuggingInstalled, script = loadScript} = {}) {
3✔
23
  let loading = null;
1✔
24
  return function () {
1✔
25
    if (loading == null) {
×
26
      loading = new PbPromise((resolve, reject) => {
×
27
        // run this in a 0-delay timeout to give installedModules time to be populated
28
        setTimeout(() => {
×
29
          if (alreadyInstalled()) {
×
30
            resolve();
×
31
          } else {
32
            const url = '$$PREBID_DIST_URL_BASE$$debugging-standalone.js';
×
33
            logMessage(`Debugging module not installed, loading it from "${url}"...`);
×
34
            getGlobal()._installDebugging = true;
×
35
            script(url).then(() => {
×
36
              getGlobal()._installDebugging({DEBUG_KEY, hook, config, createBid, logger: prefixLog('DEBUG:')});
×
37
            }).then(resolve, reject);
38
          }
39
        });
40
      })
41
    }
42
    return loading;
×
43
  }
44
}
45

46
export function debuggingControls({load = debuggingModuleLoader(), hook = getHook('requestBids')} = {}) {
3✔
47
  let promise = null;
1✔
48
  let enabled = false;
1✔
49
  function waitForDebugging(next, ...args) {
50
    return (promise || PbPromise.resolve()).then(() => next.apply(this, args))
×
51
  }
52
  function enable() {
53
    if (!enabled) {
×
54
      promise = load();
×
55
      // set debugging to high priority so that it has the opportunity to mess with most things
56
      hook.before(waitForDebugging, 99);
×
57
      enabled = true;
×
58
    }
59
  }
60
  function disable() {
61
    hook.getHooks({hook: waitForDebugging}).remove();
1✔
62
    enabled = false;
1✔
63
  }
64
  function reset() {
65
    promise = null;
1✔
66
    disable();
1✔
67
  }
68
  return {enable, disable, reset};
1✔
69
}
70

71
const ctl = debuggingControls();
1✔
72
export const reset = ctl.reset;
1✔
73

74
export function loadSession() {
75
  let storage = null;
1✔
76
  try {
1✔
77
    // eslint-disable-next-line no-restricted-properties
78
    storage = window.sessionStorage;
1✔
79
  } catch (e) {}
80

81
  if (storage !== null) {
1!
82
    let debugging = ctl;
1✔
83
    let config = null;
1✔
84
    try {
1✔
85
      config = storage.getItem(DEBUG_KEY);
1✔
86
    } catch (e) {}
87
    if (config !== null) {
1!
88
      // just make sure the module runs; it will take care of parsing the config (and disabling itself if necessary)
89
      debugging.enable();
×
90
    }
91
  }
92
}
93

94
config.getConfig('debugging', function ({debugging}) {
1✔
95
  debugging?.enabled ? ctl.enable() : ctl.disable();
×
96
});
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc