Skip to content

[BUG] 无后台脚本时不要让Chrome退出后在后台运行 #1047

Description

@fireattack

问题描述

似乎是升级到1.2.0之后,chrome退出后会依然挂载在托盘,检查了下是因为ScriptCat导致。

我并未安装任何后台或者定时脚本,感觉这种情况是否应该不要阻止Chrome正常关闭。

(我知道Chrome设置里里有个后台运行的总开关,不过我有些别的App还是需要这个功能的。)

重现步骤

  1. 安装ScriptCat最新版

脚本猫版本

v1.2.0

操作系统以及浏览器信息

Windows 10 + Chrome Version 143.0.7499.41 (Official Build) (64-bit)

补充信息 (选填)

No response

Activity

  1. added theissue type on Dec 3, 2025
  2. CodFrm commented on Dec 3, 2025

    @CodFrm
    Member

    https://developer.chrome.com/docs/extensions/reference/permissions-list?hl=zh-cn#:~:text=%E7%9A%84%E8%AE%BF%E9%97%AE%E6%9D%83%E9%99%90%E3%80%82-,%22background%22,-%E4%BD%BF%20Chrome%20%E6%8F%90%E5%89%8D

    扩展配置了 "background" 后,就会出现这个情况,我尝试了一下,将 "background" 放在 optional_permissions 中,然后需要时再使用 chrome.permissions.request 申请,似乎也是可以的

    我理解大部分用户其实是不用后台脚本的,固定这个模式会造成一些困扰,我在下一个修复版本中增加一个选项用于控制是否持续在后台运行(默认关闭)

  3. added
    P0🚑 需要紧急处理的内容
    hotfix需要尽快更新到扩展商店
    on Dec 3, 2025
  4. cyfung1031 commented on Dec 3, 2025

    @cyfung1031
    Collaborator
  5. changed the issue type fromtoon Dec 3, 2025
  6. cyfung1031 commented on Jan 1, 2026

    @cyfung1031
    Collaborator

    @CodFrm

    从 1.2.0 升上 1.2.3 的用户,会维持准许状态

    我感觉这个就是最近一堆 userscript 警告提示无法关掉 报告出现的原因
    即使现在是 optional
    之前 1.2.0 是准许的,所以升级后还是维持准许状态
    因此到了 1.2.3, 还是一直有这样的报告出现
    因为关掉浏览器也不会真正关掉,所以警告提示一直维持,除非用户重启电脑。

    我發現現在已經有這個開關按鈕。
    不過如果没有背景脚本的話,自動移除 permission 會比較好。

    • 结论:由1.2.0升上来的用户,现在还是维持 background 准许状态

    验证

    Step 0

    先下载 1.2.0 和 1.2.3 zip包

    scriptcat-v1.2.0-chrome.zip

    scriptcat-v1.2.3-chrome.zip

    各自解压

    Step 1

    打开 chrome,

    移除 ScriptCat ,重启Chrome (不止关浏览器。如有残留,需要force quit)

    用 chrome://extensions/ -> Developer Mode -> Load unpacked -> 安装 1.2.0

    (如没有打开 https://docs.scriptcat.org/en/docs/use/install_comple 随便打开一个网站,例如 https://www.google.com/ )

    在 chrome://extensions/ 点 service_worker 的 DevTools

        chrome.permissions.contains({ permissions: ["background"] }, (result) => {
          if (chrome.runtime.lastError) {
            console.error(chrome.runtime.lastError);
            return;
          }
          console.log(result);
        });

    显示 true

    把 1.2.3 的解压内容覆盖 1.2.0 的解压内容

    用 chrome://extensions/ -> Developer Mode -> Load unpacked -> 安装同一个资料夹

    (如没有打开 https://docs.scriptcat.org/en/docs/use/install_comple 随便打开一个网站,例如 https://www.google.com/ )

    在 chrome://extensions/ 点 service_worker 的 DevTools

        chrome.permissions.contains({ permissions: ["background"] }, (result) => {
          if (chrome.runtime.lastError) {
            console.error(chrome.runtime.lastError);
            return;
          }
          console.log(result);
        });

    显示 true

    Step 2

    移除 ScriptCat ,重启Chrome (不止关浏览器。如有残留,需要force quit)

    用 chrome://extensions/ -> Developer Mode -> Load unpacked -> 安装同一个资料夹

    (如没有打开 https://docs.scriptcat.org/en/docs/use/install_comple 随便打开一个网站,例如 https://www.google.com/ )

    在 chrome://extensions/ 点 service_worker 的 DevTools

        chrome.permissions.contains({ permissions: ["background"] }, (result) => {
          if (chrome.runtime.lastError) {
            console.error(chrome.runtime.lastError);
            return;
          }
          console.log(result);
        });

    显示 false

    相关

    Gemini

    In short: Yes, Chrome will keep the permission "granted" for existing users during the upgrade from 1.2.0 to the latest version.

    Chrome tracks the "granted" state of permissions, not just their declaration in the manifest. Since your existing users already explicitly or implicitly granted the background permission (as it was a required permission in 1.2.0), that "granted" flag remains in Chrome's internal database for your extension ID.

    The Upgrade Behavior

    • Existing Users: When they update, Chrome sees that the permission was previously granted. It doesn't "revoke" it just because you moved it to optional_permissions. The extension will continue to have access to the background functionality without prompting the user again.
    • New Users: Users who install the "latest" version for the first time will not have the permission granted by default. You will need to programmatically call chrome.permissions.request() to trigger the prompt for them.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

P0🚑 需要紧急处理的内容hotfix需要尽快更新到扩展商店

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions