Open
Conversation
`getLang()` walks up the DOM tree and returns `null` when no language
attribute is found. This is the common case for PDFs, which almost
never declare a language.
`getSegmenter()` has a default parameter `lang = 'en'`, but JavaScript
default parameters only apply when the argument is `undefined` — not
when it is `null`. So `getSegmenter(null)` bypasses the default and
calls `new Intl.Segmenter(null, { granularity })`, which throws:
TypeError: null is not an object (evaluating 'new Intl.Segmenter(lang, { granularity })')
The error propagates as an unhandled promise rejection and silently
kills TTS — the user clicks Play, nothing happens, and the only
evidence is a console error. This affects every PDF regardless of
content or system configuration.
Fix: fall back to 'en' when `lang` is falsy, not just when it is
undefined. Keep the default parameter for callers that pass nothing.
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
The default TTS highlight callback calls `this.renderer.scrollToAnchor`
to follow along with spoken text. The paginator (for reflowable books)
implements this, but the PDF renderer does not — it is fixed-layout
and has no anchor concept.
As a result, every spoken word on a PDF throws:
this.renderer.scrollToAnchor is not a function. (In
'this.renderer.scrollToAnchor(range, true)',
'this.renderer.scrollToAnchor' is undefined)
These are logged at the GLib CRITICAL level — non-fatal (audio still
plays), but extremely noisy: one log per word, hundreds per page.
Fix: wrap the default callback in a typeof guard so it is a no-op for
renderers that do not implement `scrollToAnchor`. This preserves the
existing behavior for reflowable formats and eliminates the spam on
PDFs, without changing any public API. Callers that pass a custom
`highlight` callback are unaffected.
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
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.
Summary
Two small, independent fixes that together restore TTS on PDFs. Both bugs currently make PDF narration unusable:
tts: fix Intl.Segmenter crash on documents without lang metadata—getLang()returnsnullwhen no language attribute is present (the normal case for PDFs).getSegmenter()'s default parameter (lang = 'en') only triggers forundefined, notnull, sonew Intl.Segmenter(null, ...)throws and TTS silently dies before producing a single word. Fix:lang || 'en'inside the constructor call.view: guard TTS scrollToAnchor for renderers that do not implement it— the default TTS highlight callback callsthis.renderer.scrollToAnchor(range, true), but the PDF renderer doesn't implement that method (it's fixed-layout, no anchor concept). Every spoken word throws aCRITICALlog — non-fatal (audio still plays after the first fix above), but hundreds per page. Fix: wrap the default callback in atypeofguard.Both fixes are scoped to the default PDF path and don't change behavior for reflowable formats or callers that pass their own
highlightcallback.Reproduction
Before these fixes, opening any PDF (from arxiv, Google Scholar, anything) and clicking the Narration (headphones) button produces the following console output and no audio:
With fix 1 applied, audio plays but the console is spammed:
With fix 2 applied as well, PDF TTS is quiet and works end-to-end.
Test plan
Intl.Segmentercrash reproduces on upstream main with a PDF that has no language metadatascrollToAnchorCRITICAL spam reproduces on same PDF with fix 1 appliedhighlightcallbacks🤖 Generated with Claude Code