Skip to content

feat: Add setLanguage API to webcontents OS-20941#122

Merged
t-bashir-bs merged 1 commit into
28-x-y-bsfrom
tbashir/28-x-y-bs-fix-language-OS-20941
Mar 12, 2026
Merged

feat: Add setLanguage API to webcontents OS-20941#122
t-bashir-bs merged 1 commit into
28-x-y-bsfrom
tbashir/28-x-y-bs-fix-language-OS-20941

Conversation

@t-bashir-bs
Copy link
Copy Markdown

@t-bashir-bs t-bashir-bs commented Mar 11, 2026

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

Release Notes

Notes:

Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

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

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 on WebContents that normalizes a comma-separated language list (trimming whitespace and stripping ;... parameters).
  • Adds spec coverage verifying navigator.language / navigator.languages reflect 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.

Comment thread docs/api/web-contents.md Outdated
Comment thread shell/browser/api/electron_api_web_contents.cc Outdated
@t-bashir-bs t-bashir-bs force-pushed the tbashir/28-x-y-bs-fix-language-OS-20941 branch from 0f9e0c9 to 2836e61 Compare March 11, 2026 16:36
@t-bashir-bs t-bashir-bs force-pushed the tbashir/28-x-y-bs-fix-language-OS-20941 branch from 2836e61 to e3fa123 Compare March 11, 2026 17:29
@t-bashir-bs t-bashir-bs merged commit 2f442e3 into 28-x-y-bs Mar 12, 2026
7 of 8 checks passed
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.

3 participants