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

Conversation

twiss
Copy link
Member

@twiss twiss commented Feb 1, 2022

Fix #1464. Depends on #1474.

src/util.js Outdated Show resolved Hide resolved
twiss and others added 2 commits February 10, 2022 21:36
Co-authored-by: larabr <larabr+github@protonmail.com>
@twiss twiss merged commit f93f59e into openpgpjs:main Feb 11, 2022
@twiss twiss deleted the check-navigator-existence branch February 11, 2022 12:33
@@ -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.

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.

Cannot deploy to Cloudflare Worker due to dependency on browser-only "navigator"
3 participants