这个错误来自
Smart TOC
扩展(v0.12.2),是一个已知的 Chrome 扩展 API 限制问题。
## 问题分析
错误信息
This function must be called during a user gesture
表示
chrome.permissions.request()
在非用户手势上下文中被调用了。
### 调用链路:
  1. 用户点击登录按钮(
    用户手势上下文)
  2. 代码先
    await
    调用
    hasIdentityPermission()
    (异步操作)
  3. 然后再调用
    requestIdentityPermission()
    chrome.permissions.request()
  4. 此时用户手势上下文已丢失
    (因为中间有
    await
    ),Chrome 拒绝执行
### 根本原因
在扩展的 index.js 中,登录按钮的
onclick
处理器:
```javascript
async onclick(){
let d = await s.extensionClient.auth.browser.hasIdentityPermission(); // ← await 导致用户手势上下文丢失
if(!d) try {
d = await s.extensionClient.auth.browser.requestIdentityPermission(); // ← 此时已不在用户手势中
} catch(g) { ... }
}
`chrome.permissions.request()` 要求在用户点击事件的**同步调用栈**中执行,任何 `await` 都会使手势上下文失效。
## 解决方案
由于这是第三方扩展的编译代码,你无法直接修改。建议:
1. **向开发者反馈 Bug**:在 [Smart TOC Canny](https://smart-toc.canny.io/bug-report) 提交 bug 报告,说明 `requestIdentityPermission` 在 `await` 之后调用导致用户手势上下文丢失。
2. **临时绕过方法**:手动在 Chrome 地址栏中授予权限:
- 打开 `chrome://extensions/`
- 找到 Smart TOC 扩展
- 点击"详细信息"
- 在"权限"部分,手动启用 `identity` 和 `identity.email` 权限
3. **使用邮箱登录**:在登录弹窗中选择 "Continue with Email + Auth Code" 而非 "Continue with Browser Profile",这样可以绕过 `chrome.permissions.request()` 的调用。
### 开发者应修复的方式
正确的做法是在 `await` 之前就发起权限请求,或者直接在 options page 中调用 `chrome.permissions.request()` 而不通过 background script 代理:
```javascript
// 修复:直接调用 Chrome API,不经过 await
async onclick() {
// 先请求权限(在用户手势上下文中)
const hasPermission = await chrome.permissions.request({
permissions: ["identity", "identity.email"]
});
if (!hasPermission) return;
// 然后再做其他异步操作
}