Skip to content

Conversation

@bershanskiy
Copy link
Contributor

If user instructs User Agent to block cookies, every access to sessionStorage outside of try-catch block results in an error. Prior to this commit, setDebugOptionsFromSessionStorage() contained a faulty check for this case leading to unpredictable breakages in glean embedders. In particular, Glean was breaking pages on MDN https://developer.mozilla.org/

For details see: mdn/yari#13039

This is just one of many ways o fix the bug. Specifically, I removed faulty check in setDebugOptionsFromSessionStorage() in favor of a properly working check (the try-catch block) in getDebugOptionFromSessionStorage().

Tests:
I did not add any tests here because I did not any extra functionality, just removed a faulty check in favor of a functional one.

Changelog:
Updated CHANGELOG.md with a reference to this PR.

Documentation:
This change does not require any documentation.

Pull Request checklist

  • Quality: Make sure this PR builds and runs cleanly.
    • Inside the glean/ folder, run:
      • npm run test Runs all tests
      • npm run lint Runs all linters
  • Tests: This PR includes thorough tests or an explanation of why it does not
  • Changelog: This PR includes a changelog entry to CHANGELOG.md or an explanation of why it does not need one
  • Documentation: This PR includes documentation changes, an explanation of why it does not need that or a follow-up bug has been filed to do that work

@auto-assign auto-assign bot requested a review from travis79 August 27, 2025 15:58
* Fetch debug options from SessionStorage and set the Glean preInit debug options.
*/
function setDebugOptionsFromSessionStorage() {
// If we cannot access browser APIs, we do nothing.
Copy link
Contributor

@Dexterp37 Dexterp37 Sep 5, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@bershanskiy @travis79 if we remove this, wouldn't we hit what #1788 was supposed to fix, again?

Or do we always call this after getDebugOptions..?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

getDebugOptionFromSessionStorage() catches this exception properly (lines 73-82):

const getDebugOptionFromSessionStorage = (
  option: DebugOptionValue
): string | undefined => {
  try {
    return sessionStorage.getItem(`Glean.${option.toString()}`) || undefined;
  } catch (e) {
    console.warn(e);
    return undefined;
  }
};

This PR removes one faulty redundant check to let the code execution to actually reach the proper try-catch.

@Dexterp37 Dexterp37 merged commit 60fb80d into mozilla:main Sep 15, 2025
4 of 5 checks passed
@bershanskiy bershanskiy deleted the b-13039 branch September 15, 2025 10:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants