[Bug] DOCUMENT_CONNECT can race with ConfigManager.load() on cold startup
Prerequisites
- I searched for any existing report about this bug to avoid opening a duplicate.
- I can reproduce this bug in a new, unmodified web browser profile with Dark Reader installed as the only extension.
- I understand I need to use the Broken Website Report template if this bug I am reporting occurs on a single website.
Bug Description
On cold startup, DOCUMENT_CONNECT may be handled before ConfigManager.load() finishes.
getConnectionMessage() calls getTabMessage() without awaiting Extension.startBarrier, so DETECTOR_HINTS_INDEX can still be undefined:
TypeError: undefined is not an object (evaluating 'trie.regexps')
The content script then receives no response and the fallback theme remains until reload.
Could getConnectionMessage() await startBarrier before calling getTabMessage(), as onCommandInternal() already does?
I’m a Teak developer. Our cold-start timing makes this source-level race easier to reproduce.
Website Address
https://www.bing.com/search?q=dark+reader
Steps To Reproduce
- Enable “Detect dark theme” in Dark Reader.
- Open https://www.bing.com/search?q=dark+reader with Bing using its native dark theme.
- Leave the tab open, terminate the browser, and cold-start it again.
- Restore the existing tab.
Intermittently, Dark Reader’s fallback theme remains applied and the page never receives the normal theme/dark-theme-detection response. Reloading the page fixes it.
Expected Behavior
Dark Reader should wait for its configuration to finish loading before handling DOCUMENT_CONNECT. The page should receive a valid response and the fallback theme should always be removed without requiring a reload.
Actual Behavior
Intermittently, DOCUMENT_CONNECT is handled before the configuration indexes are initialized, causing TypeError: undefined is not an object (evaluating 'trie.regexps'). The content script receives no response, and the fallback theme remains applied until the page is reloaded.
Screenshots
Operating System
iOS 27
Web Browser name and version
Teak (internal test)
Dark Reader version
Dark Reader: 4.9.129
Additional Context
No response
Source: darkreader/darkreader