首页 > 解决方案 > Chrome 扩展程序 - 调试模式后清除信息栏标签

问题描述

在基于 Chrome 的浏览器的最新版本中,出于某种原因(可能不是错误,它是一项功能),在 debug mode is detached之后,Chrome 会留下此通知:

“程序开始调试此浏览器”

截屏

基本上,我运行这段代码

let debugee = {tabId: sender.tab.id};
chrome.debugger.attach(debugee, '1.2', ()=>{});
chrome.debugger.detach(debugee);

并见上图。detachChrome 在80 版(左右)之前删除了此通知。

我找到了问题的描述: https ://chromium.googlesource.com/chromium/src/+/HEAD/chrome/app/generated_resources.grd

<!-- DevTools attached infobar -->
      <message name="IDS_DEV_TOOLS_INFOBAR_LABEL" desc="Label displayed in an infobar when external debugger is attached to the browser.  The label does not disappear until the user dismisses it, even if the debugger is detached, and so should not imply that the debugger must still be debugging the browser, only that it was, and could still be.">
        "<ph name="CLIENT_NAME">$1<ex>Extension Foo</ex></ph>" started debugging this browser
      </message>

我正在寻找有关如何从 chrome 扩展中自动清除或禁用此消息的建议。

标签: google-chromegoogle-chrome-extensiongoogle-chrome-devtoolsgoogle-chrome-app

解决方案


TL; DR 没有这样的方法。

Chrome 中的新行为是对安全问题的尴尬修复的结果:恶意扩展程序可以通过 chrome.debugger API 快速造成大量破坏,即使工作完成时间也不长,没有人会知道发生了什么事情100 毫秒。

由于涉及安全问题,旧行为将不会恢复,但他们同意 UI 至少应反映当前调试器状态,请参阅https://crbug.com/1096262。他们目前的计划是如果扩展程序已分离并更新按钮/字符串以与状态同步,则在可见 >=5 秒后自动关闭信息栏。

--silent-debugger-extension-api一种解决方法是使用命令行开关运行 chrome 。这是一个危险的开关,但从某种意义上说,您必须小心不要安装使用debugger权限的恶意扩展程序,无论是立即使用还是在更新时使用。


推荐阅读