Skip to content

Fix log setup crash in environments without URL or location.href - #1153

Open
cpruijsen wants to merge 2 commits into
digitalbazaar:mainfrom
cpruijsen:fix/issue-1117
Open

cpruijsen wants to merge 2 commits into
digitalbazaar:mainfrom
cpruijsen:fix/issue-1117

Conversation

@cpruijsen

Copy link
Copy Markdown

The console-level block in lib/log.js guards on window.location and then calls
new URL(window.location.href). Two environments reach it and throw: one where location exists but
href is empty or absent, which is what jsdom and several React Native shims give you, and one with
no global URL constructor at all. Either way importing forge fails outright, which is why this
surfaced as a TypeError on upgrade rather than as a missing log level.

This widens the existing guard to require window.location.href and a callable URL before the
parse. Nothing else changes: where the parse worked before it still runs, and where it would have
thrown, forge now loads with the console logger at its default level.

Fixes #1117

Check that the URL constructor and window.location.href exist before
parsing console.level/console.lock query vars at load time. Hybrid
runtimes such as Tabris.js expose a window.location object but lack
the URL global and location.href, so loading the module threw
"TypeError: undefined is not a constructor (evaluating
'new URL(window.location.href)')".
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.

TypeError due to URL(window.location.href) after upgrading to node-forge 1.3.1

1 participant