More serialization between foreground/background

Repository details (talkie)
Project page
talkie
Project log category
(708 entries)
Repository
@joelpurra/talkie
Owner
@joelpurra
Contributors
Contributors on Github
Project status
⏲️ This project has had recent commits.
📂 This project is open.
🌠 This project is popular.
Repository activity period
🗓
Commits
751 commits
Stars
72 stars
Commit details (eec9c455)
Author
Authored at
Committer
Joel Purra
Committed at

Commit message

More serialization between foreground/background

  • There has been an uptick in errors in Firefox with the message can't access dead object.
    • Occurs when listing/configuring voices on the options page.
    • A simple page reload can work around the problem, but it is not a permanent fix for a one-time problem.
  • The error has been reported (via email) by three users in 2023.
    • The error message is Firefox-specific, and the error does not seem to occur in Chromium-based browsers.
    • Reports come from the options page, where it so happens that (optional, manual) prepared (email) error reports are available.
    • If the error happens to be the background "process", the issue may be obscured since there is no automatic crash reporting. No background incidents have been reported.
  • The error happens sporadically, and may be hard to reliably reproduce.
    • Presumably triggered when one part of the web extension is unloaded, but another part still holds object/array references from the former.
    • The the former part already being "gone", the error occurs in the latter.
    • May be related to webext background page timeouts, as well as to how long the options page is open (but perhaps not actively accessing the background).
  • Seems related to accessing SafeVoiceObject.
    • The Talkie-specific object was previously introduced to avoid this particular issue, mirroring the browser-native SpeechSynthesisVoice objects.
    • The error occurs despite each SafeVoiceObject being a newly created object where all property values are primitives.
    • It may happen that newly SafeVoiceObject objects (or SafeVoiceObjects arrays) themselves become the dead references. The underlying issue had been assumed to be restriced to browser-native objects, created outside the direct control of Talkie.
  • Documentation from Mozilla on this error is generally outdated
    • Documention refers to the old type of "Firefox addons" (pre-webext), and suggested fixes cannot be applied.
    • Talkie is a webext (not an old "addon"), although a bit older (using a background page) – not the most recent version (using services workers).
    • The error still seem to belong to the same class of "dead object" reference/access/type errors.
  • This fix attempts to reduce errors by applying additional serialization/deserialization.
    • Serialization is performed using JSON.stringify(...)/JSON.parse(...).
    • Applied only to passing non-primitives (objects, arrays) between the foreground/background, meaning the Talkie "services" API.
    • The extra serialization is performed after receiving objects/arrays from "another" webext part, such that the passed reference is short-lived and not returned to callers.
  • An alternative fix is to only pass primitives, to hopefully avoid references.
    • Objects/arrays may be passed as JSON-encoded strings in transit between "parts". May (already have been) be implemented generically, using a full "wire" protocol?
    • Can also reduce object/array use in the Talkie service API, to avoid references.
    • Passing webext-native browser.Tab.Tab objects has been avoided by only passing the tab identifier (Tab.Tab.id: number | undefined). The object result was not used anyhow, as the opening tab does not communicate with the newly opened in Talkie.
  • The real fix may be to upgrade Talkie to webext manifest v3 (MV3).
    • The services workers used in v3 should be better suited for messaging.
    • An upgrade is required anyhow, since both Mozilla Firefox and Chromium (Google Chrome) will end v2 support.
Raw text
More serialization between foreground/background

- There has been an uptick in errors in Firefox with the message `can't access dead object`.
  - Occurs when listing/configuring voices on the options page.
  - A simple page reload can work around the problem, but it is not a permanent fix for a one-time problem.
- The error has been reported (via email) by three users in 2023.
  - The error message is Firefox-specific, and the error does not seem to occur in Chromium-based browsers.
  - Reports come from the options page, where it so happens that (optional, manual) prepared (email) error reports are available.
  - If the error happens to be the background "process", the issue may be obscured since there is no automatic crash reporting. No background incidents have been reported.
- The error happens sporadically, and may be hard to reliably reproduce.
  - Presumably triggered when one part of the web extension is unloaded, but another part still holds object/array references from the former.
  - The the former part already being "gone", the error occurs in the latter.
  - May be related to webext background page timeouts, as well as to how long the options page is open (but perhaps not actively accessing the background).
- Seems related to accessing `SafeVoiceObject`.
  - The Talkie-specific object was previously introduced to avoid this particular issue, mirroring the browser-native `SpeechSynthesisVoice` objects.
  - The error occurs despite each `SafeVoiceObject` being a newly created object where all property values are primitives.
  - It may happen that newly `SafeVoiceObject` objects (or `SafeVoiceObjects` arrays) themselves become the dead references. The underlying issue had been assumed to be restriced to browser-native objects, created outside the direct control of Talkie.
- Documentation from Mozilla on this error is generally outdated
  - Documention refers to the old type of "Firefox addons" (pre-webext), and suggested fixes cannot be applied.
  - Talkie is a webext (not an old "addon"), although a bit older (using a background page) -- not the most recent version (using services workers).
  - The error still seem to belong to the same class of "dead object" reference/access/type errors.
- This fix attempts to reduce errors by applying additional serialization/deserialization.
  - Serialization is performed using `JSON.stringify(...)`/`JSON.parse(...)`.
  - Applied only to passing non-primitives (objects, arrays) between the foreground/background, meaning the Talkie "services" API.
  - The extra serialization is performed _after receiving_ objects/arrays from "another" webext part, such that the passed reference is short-lived and not returned to callers.
- An alternative fix is to only pass primitives, to hopefully avoid references.
  - Objects/arrays may be passed as JSON-encoded strings in transit between "parts". May (already have been) be implemented generically, using a full "wire" protocol?
  - Can also reduce object/array use in the Talkie service API, to avoid references.
  - Passing webext-native `browser.Tab.Tab` objects has been avoided by only passing the tab identifier (`Tab.Tab.id: number | undefined`). The object result was not used anyhow, as the opening tab does not communicate with the newly opened in Talkie.
- The real fix may be to upgrade Talkie to webext manifest v3 (MV3).
  - The services workers used in v3 should be better suited for messaging.
  - An upgrade is required anyhow, since both Mozilla Firefox and Chromium (Google Chrome) will end v2 support.

Changed files (15)

Path Additions Deletions
code/packages/browser-background/src/background/create-and-start-tab-listeners.mts +4 -4
code/packages/browser-background/src/background/create-talkie-services.mts +7 -3
code/packages/browser-background/src/speaking-status.mts +9 -9
code/packages/browser-background/src/talkie-background.mts +4 -4
code/packages/browser-background/src/welcome-manager.mts +4 -4
code/packages/options-application/src/components/navigation/nav-container-types.mts +2 -2
code/packages/options-application/src/components/navigation/nav-helpers.mts +6 -6
code/packages/options-application/src/slices/tabs.mts +3 -3
code/packages/renderer/src/render.mts +1 -1
code/packages/shared-interfaces/src/speaking-history.mts +6 -1
code/packages/shared-interfaces/src/webext.mts +22 -0
code/packages/split-environment-interfaces/src/iapi.mts +6 -5
code/packages/split-environment-node/src/server-specific/api.mts +7 -2
code/packages/split-environment-webextension/src/browser-specific/api.mts +13 -11
code/packages/split-environment-webextension/src/browser-specific/urls.mts +20 -11

Commit categories (3)