feat: Add setLanguage API to webcontents OS-20941#122
Merged
Conversation
There was a problem hiding this comment.
Pull request overview
Adds a new webContents.setLanguage() API to override per-WebContents accepted languages and updates tests/docs to cover language normalization behavior.
Changes:
- Exposes a new
setLanguage(language)method onWebContentsthat normalizes a comma-separated language list (trimming whitespace and stripping;...parameters). - Adds spec coverage verifying
navigator.language/navigator.languagesreflect the normalized values. - Documents the new API in
docs/api/web-contents.md.
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| spec/api-web-contents-spec.ts | Adds new test cases for the setLanguage behavior in renderer navigator.* APIs. |
| shell/browser/api/electron_api_web_contents.h | Declares WebContents::SetLanguage native API. |
| shell/browser/api/electron_api_web_contents.cc | Implements language normalization and binds setLanguage into the JS API surface. |
| docs/api/web-contents.md | Documents the new contents.setLanguage(language) API and expected behavior. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
0f9e0c9 to
2836e61
Compare
caneraltinbasak
approved these changes
Mar 11, 2026
2836e61 to
e3fa123
Compare
t-bashir-bs
added a commit
that referenced
this pull request
Mar 25, 2026
t-bashir-bs
added a commit
that referenced
this pull request
Apr 30, 2026
t-bashir-bs
added a commit
that referenced
this pull request
May 6, 2026
t-bashir-bs
added a commit
that referenced
this pull request
May 20, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description of Change
When the language is set in QtWebEngine we use ProfileAdapter::setHttpAcceptLanguage. Part of this functionality, to set the "accept-language" field in the header has been implemented in the default-electron-app. However, setting the accept_languages field of prefs was not done, which meant that "navigator.language" and "navigator.languages" was not being set correctly.
This PR adds a new setLanguage API call to web contents which sets the accept_languages field of prefs.
Checklist
npm testpassesRelease Notes
Notes: