Closed Bug 2062976 Opened 1 month ago Closed 1 month ago

Fix unreliable article language and write it onto the reader view page

Categories

(Firefox for Android :: Contextual AI, task, P2)

All
Android
task

Tracking

()

RESOLVED FIXED
156 Branch
Tracking Status
firefox156 --- fixed

People

(Reporter: bclark, Assigned: moyin)

References

Details

(Whiteboard: [fxdroid][android-core])

Attachments

(1 file)

ReaderView.show() reads the article language with result.language = doc.documentElement.lang. doc can be either a real DOM or a JSDOMParser DOM. JSDOMParser only defines getters for className, id, href, src and srcset - it has NO getter for lang, only getAttribute. The two sources race and the winning value changes between runs, so the language is not reliable today.

Separately, the rendered reader page never has the language written onto it, so downstream consumers (including PageExtractor.getPageMetadata()) cannot read it. Text-to-speech needs a correct locale or it pronounces the article wrong.

TECHNICAL NOTES

  • File: mobile/android/android-components/components/feature/readerview/src/main/assets/extensions/readerview/readerview.js
  • Current line 50: result.language = doc.documentElement.lang;
  • Change to: result.language = doc.documentElement.getAttribute("lang") || "";
  • Add after document.title = result.title;: document.documentElement.lang = result.language;
  • Both changes are in the same show() function and ship as one patch
  • Note result.language also feeds getReadingTime() and getTextDirection(), so this fix changes existing behaviour for RTL detection and reading-time estimates - verify no regressions there

ACCEPTANCE CRITERIA

  • result.language returns the correct tag for both the real-DOM and JSDOMParser code paths
  • The rendered reader page carries <html lang="..."> matching the source article
  • getPageMetadata().language returns the article language for a moz-extension: reader page
  • Unit tests cover both DOM paths, including an article with no lang attribute (expect "")
  • No regression in reading-time or RTL text-direction behaviour

Part of the Listen to Page text extraction epic (FXDROID-9830).

Blocks: 2062979
Blocks: 2063001
Assignee: nobody → madeyemi
Status: NEW → ASSIGNED

Moving to the Contextual AI component. All Listen to a Page work belongs there rather than in Reader Mode or Experimentation and Telemetry: Contextual AI is triaged by the Core Team, and Listen sits with the other AI features in the team's ownership model. Epic 2 (bug 2064821, FXDROID-9925) was filed into Contextual AI from the start; this brings epic 1 into line. No other field is changed.

Component: Reader Mode → Contextual AI
Pushed by madeyemi@mozilla.com: https://github.com/mozilla-firefox/firefox/commit/2cad4cd3913c https://hg.mozilla.org/integration/autoland/rev/689ddcff2e0f Fix article language and write it to the readerview page r=android-reviewers,skhan
Status: ASSIGNED → RESOLVED
Closed: 1 month ago
Resolution: --- → FIXED
Target Milestone: --- → 156 Branch
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Creator:
Created:
Updated:
Size: