Skip to content

feat(webview): append Anthias version to the User-Agent - #3102

Merged
vpetersson merged 1 commit into
masterfrom
feat/webview-user-agent-anthias-version
Jul 2, 2026
Merged

feat(webview): append Anthias version to the User-Agent#3102
vpetersson merged 1 commit into
masterfrom
feat/webview-user-agent-anthias-version

Conversation

@vpetersson

@vpetersson vpetersson commented Jul 1, 2026

Copy link
Copy Markdown
Contributor

Issues Fixed

No associated issue. The Qt webview used QtWebEngine's default User-Agent, so outbound page/subresource requests were indistinguishable from generic Chromium — ops on the receiving end couldn't tell traffic came from an Anthias screen or which release.

Description

Append an Anthias/<version> product token to QtWebEngine's default User-Agent. The string still reads as a normal browser (Mozilla/5.0 … Chrome/… Safari/… Anthias/2026.6.3), preserving site compatibility while making Anthias traffic identifiable.

  • anthias_common/http.py — new get_anthias_product_token() is the single source of truth for the Anthias/<version> label (and its unknown fallback). get_user_agent() now builds on it, so the format lives in one place.
  • anthias_viewer/__init__.py_build_webview_env() composes the token via that helper and passes it to the webview through the ANTHIAS_UA_TOKEN env var. Set unconditionally, before the board-specific early returns, so every platform plugin gets it and any stale inherited value is overwritten.
  • anthias_webview/src/view.cpp — reads ANTHIAS_UA_TOKEN and appends it verbatim to profile->httpUserAgent(). No token-format logic in C++.

Resulting UA: Mozilla/5.0 … Chrome/… Safari/… Anthias/<version> — valid per RFC 9110 §10.1.5 (product = token ["/" product-version]).

Verification. Compile-verified on both Qt majors via the image builder — Qt6 (x86) and Qt5 (pi3 armhf): view.cpp recompiled from source on each toolchain and the ANTHIAS_UA_TOKEN symbol confirmed present in each AnthiasViewer binary (old ANTHIAS_VERSION absent). Unit tests added for the token helper (tests/test_http.py) and the env injection (tests/test_viewer.py); full local run green.

Checklist

  • I have performed a self-review of my own code.
  • New and existing unit tests pass locally and on CI with my changes.
  • I have done an end-to-end test for Raspberry Pi devices. (Compile-verified on Qt5/Qt6 via the image builder; not run on a live device.)
  • I have tested my changes for x86 devices. (Compile-verified; not run on a live device.)
  • I added a documentation for the changes I have made (when necessary).

🤖 Generated with Claude Code

@vpetersson
vpetersson requested a review from a team as a code owner July 1, 2026 12:55
@vpetersson vpetersson self-assigned this Jul 1, 2026
@vpetersson
vpetersson requested a review from Copilot July 1, 2026 12:56

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pull request overview

This PR makes Anthias traffic identifiable to receiving services by appending an Anthias/<version> product token to QtWebEngine’s default User-Agent, with the version injected into the webview subprocess environment by the Python viewer.

Changes:

  • Update the QtWebEngine default profile User-Agent to append Anthias/<version> (falls back to unknown).
  • Inject ANTHIAS_VERSION into the spawned webview subprocess environment via _build_webview_env().
  • Add debug logging for the final User-Agent string.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

File Description
src/anthias_webview/src/view.cpp Appends Anthias/<version> to QtWebEngine’s default User-Agent using ANTHIAS_VERSION from the environment.
src/anthias_viewer/init.py Sets ANTHIAS_VERSION from get_anthias_release() in the env passed to the webview subprocess.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread src/anthias_viewer/__init__.py Outdated
@vpetersson
vpetersson force-pushed the feat/webview-user-agent-anthias-version branch from ffb77b0 to 4ba588d Compare July 1, 2026 13:42
@vpetersson
vpetersson requested a review from Copilot July 1, 2026 13:42

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.

Comment thread src/anthias_viewer/__init__.py
- Add an "Anthias/<version>" product token to QtWebEngine's default
  User-Agent so requests still read as Mozilla/Chrome/Safari while
  identifying the source screen and release
- Inject ANTHIAS_VERSION into the webview env from get_anthias_release(),
  falling back to "unknown" when unavailable

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
@vpetersson
vpetersson force-pushed the feat/webview-user-agent-anthias-version branch from 4ba588d to 5393754 Compare July 1, 2026 13:46
@vpetersson
vpetersson requested a review from Copilot July 1, 2026 13:46
@sonarqubecloud

sonarqubecloud Bot commented Jul 1, 2026

Copy link
Copy Markdown

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 5 out of 5 changed files in this pull request and generated 1 comment.

Comment on lines +200 to +207
# Pass the Anthias product token ("Anthias/<version>") to the C++
# webview, which appends it to QtWebEngine's User-Agent (see the
# profile setup in src/anthias_webview/src/view.cpp). Composed by the
# canonical get_anthias_product_token() helper so the format lives in
# one place. Set unconditionally — before the board-specific early
# returns below — so every platform plugin gets it and any stale
# inherited value is overwritten.
env['ANTHIAS_UA_TOKEN'] = get_anthias_product_token()
@vpetersson

Copy link
Copy Markdown
Contributor Author

On-device UA verification

Drove the live AnthiasViewer binary via D-Bus loadPage at a request-echo server and captured the actual outbound User-Agent header (not just the internal value) on both Qt majors:

Qt Runtime Captured User-Agent
Qt6 QtWebEngine 6.8.2 (amd64) Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) QtWebEngine/6.8.2 Chrome/122.0.6261.171 Safari/537.36 Anthias/2026.6.3
Qt5 QtWebEngine 5.15.14 (armhf, Pi 4) Mozilla/5.0 (X11; Linux aarch64) AppleWebKit/537.36 (KHTML, like Gecko) QtWebEngine/5.15.14 Chrome/87.0.4280.144 Safari/537.36 Anthias/2026.6.3

Both keep the full Mozilla/… Chrome/… Safari/… browser identity with the Anthias/<version> product token appended, matching what get_anthias_product_token() produces on the Python side. Combined with the earlier image-builder compile checks (view.cpp recompiled on both toolchains, ANTHIAS_UA_TOKEN symbol present in each binary), the User-Agent change is verified end-to-end on Qt5 and Qt6.

@vpetersson
vpetersson merged commit 87374fe into master Jul 2, 2026
10 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.

2 participants