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

prebid / Prebid.js / 22922810184

10 Mar 2026 08:27PM UTC coverage: 96.33% (+0.003%) from 96.327%
22922810184

push

github

c5859c
web-flow
Core: fix error handling when loading debugging-standalone (#14554)

* Core: fix error handling when loading debugging-standalone

* lint

* run error callback once

* lint

56991 of 69714 branches covered (81.75%)

48 of 52 new or added lines in 4 files covered. (92.31%)

1 existing line in 1 file now uncovered.

217560 of 225848 relevant lines covered (96.33%)

70.48 hits per line

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

93.75
/src/debugging.js
1
import { config } from './config.js';
2
import { getHook, hook } from './hook.js';
3
import { getGlobal } from './prebidGlobal.js';
4
import { logError, 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
import * as utils from './utils.js';
10
import { BANNER, NATIVE, VIDEO } from './mediaTypes.js';
11
import { Renderer } from './Renderer.js';
12

13
import { getDistUrlBase, getGlobalVarName } from './buildOptions.js';
14

15
export const DEBUG_KEY = `__${getGlobalVarName()}_debugging__`;
8✔
16

17
function isDebuggingInstalled() {
18
  return getGlobal().installedModules.includes('debugging');
1✔
19
}
20

21
function loadScript(url) {
NEW
22
  return new PbPromise((resolve, reject) => {
×
NEW
23
    loadExternalScript(url, MODULE_TYPE_PREBID, 'debugging', { success: resolve, error: reject });
×
24
  });
25
}
26

27
export function debuggingModuleLoader({ alreadyInstalled = isDebuggingInstalled, script = loadScript } = {}) {
12✔
28
  let loading = null;
12✔
29
  return function () {
12✔
30
    if (loading == null) {
6✔
31
      loading = new PbPromise((resolve, reject) => {
5✔
32
        // run this in a 0-delay timeout to give installedModules time to be populated
33
        setTimeout(() => {
5✔
34
          if (alreadyInstalled()) {
5✔
35
            resolve();
2✔
36
          } else {
37
            const url = `${getDistUrlBase()}debugging-standalone.js`;
3✔
38
            logMessage(`Debugging module not installed, loading it from "${url}"...`);
3✔
39
            getGlobal()._installDebugging = true;
3✔
40
            script(url).then(() => {
3✔
41
              getGlobal()._installDebugging({
2✔
42
                DEBUG_KEY,
43
                hook,
44
                config,
45
                createBid,
46
                logger: prefixLog('DEBUG:'),
47
                utils,
48
                BANNER,
49
                NATIVE,
50
                VIDEO,
51
                Renderer
52
              });
53
            }).then(resolve, reject);
54
          }
55
        });
56
      })
57
    }
58
    return loading;
6✔
59
  }
60
}
61

62
export function debuggingControls({ load = debuggingModuleLoader(), hook = getHook('requestBids') } = {}) {
11✔
63
  let promise = null;
11✔
64
  let enabled = false;
11✔
65
  function waitForDebugging(next, ...args) {
4!
66
    return (promise || PbPromise.resolve())
2!
67
      .catch((e) => {
68
        logError(`Could not load debugging module`, e);
1✔
69
      })
70
      .then(() => next.apply(this, args))
2✔
71
  }
72
  function enable() {
73
    if (!enabled) {
4✔
74
      promise = load();
4✔
75
      // set debugging to high priority so that it has the opportunity to mess with most things
76
      hook.before(waitForDebugging, 99);
4✔
77
      enabled = true;
4✔
78
    }
79
  }
80
  function disable() {
81
    hook.getHooks({ hook: waitForDebugging }).remove();
11✔
82
    enabled = false;
11✔
83
  }
84
  function reset() {
85
    promise = null;
9✔
86
    disable();
9✔
87
  }
88
  return { enable, disable, reset };
11✔
89
}
90

91
const ctl = debuggingControls();
8✔
92
export const reset = ctl.reset;
8✔
93

94
export function loadSession() {
95
  let storage = null;
8✔
96
  try {
8✔
97
    // eslint-disable-next-line no-restricted-properties
98
    storage = window.sessionStorage;
8✔
99
  } catch (e) {}
100

101
  if (storage !== null) {
8✔
102
    const debugging = ctl;
8✔
103
    let config = null;
8✔
104
    try {
8✔
105
      config = storage.getItem(DEBUG_KEY);
8✔
106
    } catch (e) {}
107
    if (config !== null) {
8!
108
      // just make sure the module runs; it will take care of parsing the config (and disabling itself if necessary)
109
      debugging.enable();
×
110
    }
111
  }
112
}
113

114
config.getConfig('debugging', function ({ debugging }) {
9✔
115
  debugging?.enabled ? ctl.enable() : ctl.disable();
2✔
116
});
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