[Feature Request] Revive the service worker on chrome.idle state change to fix unresponsive popup and partial theming after system sleep

未关闭
#15,852 7 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

维护者通常 2 天内回复

还没有人认领这个 Issue。

评估

难度
4/5
预计耗时
3-5 天
新手友好度
48/100
Issue 类型
功能
描述清晰度
基本清楚
活跃度
冷清
技术栈
typescript
领域
frontend

调研方向

首先检查后台 service worker 入口点和 ui/popup/index.html,然后检查扩展清单如何声明权限,以及当前如何使用 chrome.alarms。验证 macOS 休眠后 Chrome 中的行为:popup 应该能够渲染,并且页面应接收到完整的 Dynamic mode theme,而不只是 fallback background。

由索引模型根据 Issue 内容生成。

描述

Prerequisites
Is this feature request related to a problem?

Yes

Feature Request Description

Problem

Occasionally — most often after macOS wakes from sleep — Dark Reader's MV3 background service worker gets stuck in an unresponsive state. When this happens, two symptoms always appear together:

  1. Clicking the toolbar icon does nothing: the popup never renders (stuck before or at "Loading, please wait"). Since the options page is the same page (ui/popup/index.html), settings become completely inaccessible.
  2. Pages loaded during this state are only partially themed: the fallback dark background is applied, but the full Dynamic mode theme never arrives, leaving a half-dark page.

Toggling the extension off/on in chrome://extensions immediately fixes both symptoms, which points to the background service worker as the single shared failure point (both the popup and the content scripts depend on it for state/theme data).

This looks related to a known Chromium platform issue where an extension service worker becomes inactive and no longer wakes on incoming events (chromium-extensions thread). One reported trigger mechanism is that time spent in system sleep appears to be counted into the service worker's idle timer, which matches the "after wake from sleep" pattern I observe.

Proposed solution

Add the idle permission and register a chrome.idle.onStateChanged listener in the background service worker. chrome.idle.onStateChanged is a documented wake signal that Chrome delivers on OS resume / screen unlock, so it wakes the suspended worker directly:

chrome.idle.onStateChanged.addListener((newState) => {
    if (newState === 'active') {
        // lightweight state refresh / no-op extension API call
        // to revive the worker and re-sync state
    }
});

Dark Reader already uses chrome.alarms, but alarm ticks can be skipped across a deep sleep, so an idle-state hook is a more reliable revival trigger for this specific scenario. Prior art: another extension fixed the same post-sleep dead-worker problem this way (OpenCLI PR #1737).

Screenshots

No response

Additional Context

Environment:

  • Dark Reader 4.9.129 (from Chrome Web Store)
  • Chrome 151.0.7922.138 (stable), macOS
  • Engine: Dynamic mode; "Detect dark theme" disabled; default theme values; settings storage healthy (verified locally)

Related reports:

  • Discussion #13769 describes the same symptom (icon click does not open the popup while other extensions work fine, recovers by itself after a while)
  • The 4.9.128 changelog entry "Fixed not working popup for some users" improved things, but the post-sleep case still occurs on 4.9.129

If a new install-time permission warning is a concern, idle could be requested as an optional permission and enabled from settings.

主要语言
TypeScript
星标
22.6k
派生
2.8k
平均合并
1 天 17 小时
30 天内合并 PR
82

环境准备

  • 没有 Dockerfile 或 Docker Compose 文件
  • 没有 Pull Request 模板
  • 阅读贡献指南

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

darkreader/darkreader 的其他 Issue

查看 darkreader/darkreader 的全部 Issue

相似的 Issue

更多 TypeScript Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。