Skip to content

Commit

Permalink
Debugging module: graceful handling of missing sessionStorage (prebid…
Browse files Browse the repository at this point in the history
  • Loading branch information
dgirardi authored and JacobKlein26 committed Feb 8, 2023
1 parent baad436 commit cf1eafa
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 2 deletions.
12 changes: 10 additions & 2 deletions modules/debugging/debugging.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,17 @@ function saveDebuggingConfig(debugConfig, {sessionStorage = window.sessionStorag
}
}

export function getConfig(debugging, {sessionStorage = window.sessionStorage, DEBUG_KEY, config, hook, logger} = {}) {
export function getConfig(debugging, {getStorage = () => window.sessionStorage, DEBUG_KEY, config, hook, logger} = {}) {
if (debugging == null) return;
saveDebuggingConfig(debugging, {sessionStorage, DEBUG_KEY});
let sessionStorage;
try {
sessionStorage = getStorage();
} catch (e) {
logger.logError(`sessionStorage is not available: debugging configuration will not persist on page reload`, e);
}
if (sessionStorage != null) {
saveDebuggingConfig(debugging, {sessionStorage, DEBUG_KEY});
}
if (!debugging.enabled) {
disableDebugging({hook, logger});
} else {
Expand Down
9 changes: 9 additions & 0 deletions test/spec/modules/debugging_mod_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -273,6 +273,15 @@ describe('bid interceptor', () => {
});
});

describe('Debugging config', () => {
it('should behave gracefully when sessionStorage throws', () => {
const logError = sinon.stub();
const getStorage = () => { throw new Error() };
getConfig({enabled: false}, {getStorage, logger: {logError}, hook});
expect(logError.called).to.be.true;
});
});

describe('bidderBidInterceptor', () => {
let next, interceptBids, onCompletion, interceptResult, done, addBid;

Expand Down

0 comments on commit cf1eafa

Please sign in to comment.