Skip to content

Avoid storage exceptions when localStorage is unavailable - #1056

Open
ryanchou1994 wants to merge 1 commit into
debug-js:masterfrom
ryanchou1994:fix/browser-storage-guards
Open

Avoid storage exceptions when localStorage is unavailable#1056
ryanchou1994 wants to merge 1 commit into
debug-js:masterfrom
ryanchou1994:fix/browser-storage-guards

Conversation

@ryanchou1994

Copy link
Copy Markdown

In a web worker, localStorage is absent. Loading the browser adapter and enabling or disabling a namespace currently throws caught exceptions while looking up storage and calling its methods. With “Pause on caught exceptions” enabled, these interrupt debugging even though the operations otherwise succeed.

Check whether localStorage and exports.storage exist before accessing them. Keep the existing exception handling for environments where storage exists but access is denied, and retain the process.env.DEBUG fallback.

Fixes #954.

The regression test observes actual caught exceptions through Node's inspector and includes a positive control to verify that the debugger is observing them. Additional tests cover available storage, a denied global getter, failing storage methods and the environment fallback.

Validation:

  • The new regression fails against the original source and passes with this change.
  • Full npm test passes on macOS and Linux with Node 22.23.2: 20 Node tests, 14 real headless-browser tests and lint. The 16 existing lint warnings remain.
  • Separate real Chrome/Chromium Worker checks on both platforms observe five storage exceptions with the original source and none with this change; both positive controls succeed.
  • Node 6.17.1 syntax checks and six browser-adapter compatibility controls pass. The inspector-specific test skips Node 6 because that module is unavailable there; the complete suite was run on Node 22.

Browser checks use isolated profiles and local fixtures. Windows, Firefox and Safari were not tested locally.

Copilot AI lite review requested due to automatic review settings September 9, 2026 17:52

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

Avoid throwing errors

2 participants