5.2 KiB
5.2 KiB
Debug Mode - 调试指南
调试模式已启用 ✅
我已经在以下文件中添加了详细的调试日志:
修改的文件
- background.js - Background script 调试日志
- popup.js - Popup UI 调试日志
新增的文件
- debug-helper.js - 调试辅助脚本
如何使用调试功能
方法一:查看自动日志(推荐)
-
重新加载扩展
- 打开
chrome://extensions/ - 找到 "Payment Automation Suite"
- 点击刷新图标 🔄
- 打开
-
打开 Background 日志
- 在扩展页面,点击 "Inspect views: service worker"
- 会打开一个新的开发者工具窗口
- 这里会显示所有
[Background DEBUG]日志
-
打开 Popup 日志
- 点击扩展图标打开 popup
- 在 popup 上右键 → "检查"
- 会打开 popup 的开发者工具
- 这里会显示所有
[Popup DEBUG]日志
-
测试切换功能
- 打开 Master Control
- 观察日志输出,你会看到:
[Popup DEBUG] handleMasterToggle: User toggled master switch to true [Popup DEBUG] handleMasterToggle: Sending TOGGLE_MASTER message [Background DEBUG] Received message: {type: "TOGGLE_MASTER", enabled: true} [Background DEBUG] toggleMaster called: true [Background DEBUG] Current config before master toggle: {...} [Background DEBUG] Updated config with all modules: {...} [Background DEBUG] Config after master toggle: {...}
-
关闭并重新打开 popup
- 观察
loadConfig的日志 - 检查是否正确加载了之前保存的配置
- 观察
方法二:使用调试辅助脚本
这个脚本可以一次性检查所有状态,非常适合诊断问题。
-
打开扩展 popup(点击扩展图标)
-
打开开发者工具(在 popup 上右键 → "检查")
-
运行调试脚本
- 打开
debug-helper.js文件 - 复制所有内容
- 粘贴到控制台中
- 按回车
- 打开
-
执行诊断
await debugExtension()这会显示完整的诊断报告:
- ✅ Storage 数据(sync 和 local)
- ✅ 所有模块的状态
- ✅ 统计数据
- ✅ Background 通信测试
- ✅ DOM 元素检查
- ✅ Storage 配额使用情况
调试辅助函数
在加载 debug-helper.js 后,你可以使用这些便捷函数:
await checkStorage()
快速查看当前 storage 状态
await checkStorage()
await enableAllModules()
一键启用所有模块
await enableAllModules()
await disableAllModules()
一键禁用所有模块
await disableAllModules()
await resetStorage()
⚠️ 清空所有 storage(慎用!)
await resetStorage()
诊断常见问题
问题 1:模块总是关闭
症状: 打开模块后,关闭 popup 再打开,所有模块都关了
检查步骤:
- 打开 Background 日志窗口
- 切换一个模块
- 查找这些日志:
[Background DEBUG] toggleModule called[Background DEBUG] Modules after save
- 关闭并重新打开 popup
- 查找:
[Popup DEBUG] loadConfig: Received config from storage- 检查
config.modules中的enabled值是否为true
可能原因:
- Storage 没有正确保存 → 会在 "Modules after save" 中显示
enabled: false - Storage 保存了但加载失败 → 会在 "Received config from storage" 中显示异常
- Background script 崩溃 → 消息发送失败,会有 error 日志
问题 2:Advanced Settings 无法打开
症状: 点击 "Advanced Settings" 按钮没反应
检查步骤:
- 打开 Popup 日志
- 点击 "Advanced Settings" 按钮
- 查找:
[Popup DEBUG] Options button clicked - 如果没有这条日志 → 按钮事件监听器未绑定
- 如果有日志但没打开 → 检查是否有错误信息
手动打开 Options 页面:
chrome.runtime.openOptionsPage()
或者直接访问:
chrome-extension://[扩展ID]/ui/options/options.html- 在
chrome://extensions/页面找到扩展,点击 "Details" → "Extension options"
问题 3:Storage 配额不足
症状: Storage 操作失败,或数据丢失
检查:
await debugExtension()
查看 "Storage quota" 部分
解决方法:
- 如果使用超过 80%,考虑清理或优化数据结构
- Chrome storage.sync 限制:100KB 总容量
关闭调试模式
如果你想关闭详细日志(提高性能),修改这两个文件:
background.js
const DEBUG = false; // 改为 false
popup.js
const DEBUG = false; // 改为 false
然后重新加载扩展。
下一步
现在请你:
- 重新加载扩展
- 打开 Background 日志窗口(Inspect service worker)
- 打开 Popup 并打开日志窗口(右键检查)
- 切换 Master Control 和几个模块
- 关闭 popup,等 2 秒,重新打开
- 截图或复制所有日志发给我
这样我就能准确看到是哪里出了问题!🔍