-
Notifications
You must be signed in to change notification settings - Fork 36
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
Use platform over appversion on global navigator object #5389
base: production
Are you sure you want to change the base?
Conversation
* FEATURE: Allow customizing the JSDOM userAgent, platform, and other global | ||
* properties | ||
* See https://github.com/jsdom/jsdom#advanced-configuration | ||
* See https://github.com/specify/specify7/pull/5389 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
that should probably be done using mocking:
in beforeAll in some test file set userAgent/platform/...
in afterAll undo the change
* detection for browsers using Mac. | ||
* See https://developer.mozilla.org/en-US/docs/Web/API/Navigator/platform | ||
*/ | ||
const altKeyName = globalThis.navigator?.platform.startsWith('Mac') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this is exactly the use case that was quoted by you from the MDN article, so probably using navigator.platform in the right choice in this case?
From Mozilla on appVersion: https://developer.mozilla.org/en-US/docs/Web/API/Navigator/appVersion
Recently, localization tests began failing because of an invalid setting of
global.navigator
:https://github.com/specify/specify7/actions/runs/11707985658/job/32609369992
specify7/specifyweb/frontend/js_src/lib/tests/jsdom.js
Lines 10 to 14 in 7fe1b80
This failing test was remedied in 76871c7, which functionally completely removed the reassignment of
global.navigator
.However, it appears that support for
navigator.appVersion
has been dropped in some capacity, asnavigator.appVersion
was returning undefined:https://github.com/specify/specify7/actions/runs/11726874323/job/32666586609
specify7/specifyweb/frontend/js_src/lib/components/Preferences/UserDefinitions.tsx
Lines 67 to 69 in 7fe1b80
This PR cleans up the code in the JSDOM configuration file, and uses
navigator.platform
instead ofappVersion
.navigator.platform
is itself deprecated: https://developer.mozilla.org/en-US/docs/Web/API/Navigator/platformHowever, this use case is explicitly mentioned in the Mozilla docs, and may be a better alternative until a better solution is found...
Checklist
and self-explanatory (or properly documented)