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

feat: introduce navigator.language #12322

Merged
merged 26 commits into from
Oct 18, 2022
Merged

Conversation

AnInternetTroll
Copy link
Contributor

@AnInternetTroll AnInternetTroll commented Oct 4, 2021

Link to the spec: https://html.spec.whatwg.org/multipage/system-state.html#dom-navigator-language-dev
To access navigator.language you must pass --allow-env as it can lead to fingerprinting.

What this PR doesn't add is languagechange which quite frankly is outside of my skill level.

@CLAassistant
Copy link

CLAassistant commented Oct 4, 2021

CLA assistant check
All committers have signed the CLA.

@AnInternetTroll
Copy link
Contributor Author

AnInternetTroll commented Oct 4, 2021

The spec says the following

If the user is using an anonymizing service, then the value "en-US" is suggested; if all users of the service use that same value, that reduces the possibility of distinguishing the users from each other.

And MDN says:

Returns a DOMString representing the preferred language of the user, usually the language of the browser UI. The null value is returned when this is unknown.

I would argue that if --allow-env isn't passed then navigator.language should be en-US. or null instead of throwing an error.

Also an additional note, on unix this would be more or less the same as getting the LANG env variable, so maybe --allow-env=LANG should allow navigator.language to return the correct language. This should be discussed though as it is not how it works on windows.

Copy link
Member

@crowlKats crowlKats left a comment

Choose a reason for hiding this comment

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

Missing WorkerNavigator typings and property definition in 99_main

runtime/js/99_main.js Outdated Show resolved Hide resolved
runtime/js/99_main.js Outdated Show resolved Hide resolved
@lucacasonato
Copy link
Member

Actually, this can be enabled by default (no permissions), because the default language can already be extracted via Intl global.

Comment on lines 118 to 122
fn op_languages(
_state: &mut OpState,
_: (),
_: (),
) -> Result<Vec<String>, AnyError> {
Copy link
Member

Choose a reason for hiding this comment

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

If locale_config caches the result it means that this value cannot change after the first call. I'd suggest to remove this op and forward the value to JS in BootstrapOptions struct.

CC @lucacasonato

Copy link
Member

@lucacasonato lucacasonato left a comment

Choose a reason for hiding this comment

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

Could you also add a test for navigator.languages?

lucacasonato
lucacasonato previously approved these changes Oct 11, 2021
Copy link
Member

@lucacasonato lucacasonato left a comment

Choose a reason for hiding this comment

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

Looks good now. Thanks Ben.

@lucacasonato lucacasonato dismissed their stale review October 11, 2021 13:17

Sorry @AnInternetTroll, accidentally left my review comment on the wrong PR.

Copy link
Member

@crowlKats crowlKats left a comment

Choose a reason for hiding this comment

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

languages should be frozen

@stale
Copy link

stale bot commented Dec 27, 2021

This pull request has been automatically marked as stale because it has not had recent activity. It will be closed in 7 days if no further activity occurs. Thank you for your contributions.

@stale stale bot added the stale label Dec 27, 2021
@bartlomieju bartlomieju removed the stale label Dec 28, 2021
@stale
Copy link

stale bot commented Feb 26, 2022

This pull request has been automatically marked as stale because it has not had recent activity. It will be closed in 7 days if no further activity occurs. Thank you for your contributions.

@stale stale bot added the stale label Feb 26, 2022
@AnInternetTroll
Copy link
Contributor Author

Not stale, work has been done in rusty_v8 denoland/rusty_v8#953

@stale stale bot removed the stale label Apr 29, 2022
@stale
Copy link

stale bot commented Jul 1, 2022

This pull request has been automatically marked as stale because it has not had recent activity. It will be closed in 7 days if no further activity occurs. Thank you for your contributions.

@stale stale bot added the stale label Jul 1, 2022
@bartlomieju bartlomieju removed the stale label Jul 1, 2022
@stale
Copy link

stale bot commented Sep 20, 2022

This pull request has been automatically marked as stale because it has not had recent activity. It will be closed in 7 days if no further activity occurs. Thank you for your contributions.

@stale stale bot added the stale label Sep 20, 2022
@stale stale bot removed the stale label Sep 30, 2022
@bartlomieju
Copy link
Member

This is now done and should be ready to land. @lucacasonato @crowlKats please review

Copy link
Member

@lucacasonato lucacasonato left a comment

Choose a reason for hiding this comment

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

LGTM

Copy link
Member

@bartlomieju bartlomieju left a comment

Choose a reason for hiding this comment

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

LGTM

@bartlomieju bartlomieju merged commit 1a0c7ed into denoland:main Oct 18, 2022
Copy link

@zbraniecki zbraniecki left a comment

Choose a reason for hiding this comment

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

fly-by review.

@@ -47,6 +48,7 @@ impl Default for BootstrapOptions {
enable_testing_features: Default::default(),
debug_flag: Default::default(),
ts_version: Default::default(),
locale: "en-EN".to_string(),

Choose a reason for hiding this comment

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

this seems like an error - there's no region EN.

Copy link
Member

Choose a reason for hiding this comment

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

Thanks! Silly mistake on my part, I'll fix it

bartlomieju added a commit that referenced this pull request Oct 28, 2022
Pointed by @zbraniecki in
#12322 (comment), I
made a mistake with default locale value.
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.

None yet

6 participants