Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Check existence of navigator before using it #1475

Merged
merged 2 commits into from Feb 11, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/util.js
Expand Up @@ -430,7 +430,7 @@ const util = {
return os.cpus().length;
}

return navigator.hardwareConcurrency || 1;
return (typeof navigator !== 'undefined' && navigator.hardwareConcurrency) || 1;

Choose a reason for hiding this comment

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

I appreciate you trying to fix this problem, but just so you know: it doesn't fix the Cloudfare issue because it's still accessing a prohibited API. The mere attempt to read navigator is what's not allowed.
I tried to explain that in my pull request.
I will try to check with cloudflare if they could allow code like this to "pass"... but I thought you would be interested in knowing that.

Copy link
Member Author

Choose a reason for hiding this comment

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

I understand - but even after your PR, you still had to shim util.isEdge, afaiu - after this PR and #1474, you can shim util.getHardwareConcurrency instead :)

Other than that, please do check with Cloudflare, as this is the standard way to check for the existence of global objects, it shouldn't cause issues.

},

isEmailAddress: function(data) {
Expand Down