Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

插件开发指南:更新调试代码关于开发者工具的描述 #238

Merged
merged 2 commits into from
Jul 24, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
63 changes: 46 additions & 17 deletions plugin-dev-guide/development/debug.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,18 +17,55 @@ author:

如果代码中包含异步语法(async),需要将结果 return 才能在右侧看见。

## 通过 Zotero.debug 输出日志
## 通过 `Zotero.debug` 输出日志

- 使用 `Zotero.debug` 输出到 `菜单栏` -> `帮助` -> `输出日志排错` -> `查看输出文件`;
- 使用 `Zotero.log` 输出到 `菜单栏` -> `工具` -> `开发者` -> `Error Console`。

::: tip 不推荐使用 `console` 作为调试/日志输出

- Zotero 插件环境没有默认将 `console` 作为一个全局对象
- `console.log` 是性能昂贵的

如果可能,请使用辅助函数,仅在开发环境打印日志,可参考 `ztoolkit.log`。

:::

## 通过开发者工具

如果你不熟悉开发者工具,可参看[什么是浏览器开发者工具? - 学习 Web 开发 | MDN](https://developer.mozilla.org/zh-CN/docs/Learn/Common_questions/What_are_browser_developer_tools)
由于 Zotero 基于 Firefox,因此可以使用 [Firefox 开发者工具](https://developer.mozilla.org/zh-CN/docs/Learn/Common_questions/What_are_browser_developer_tools) 与 DOM 交互、设置代码断点、跟踪网络请求等。

Zotero 7 beta 版本内建 Firefox 115 开发者工具。要在启动 Zotero 时打开开发者工具,请在命令行上传递 `-jsdebugger` 标志:

```bash
/Applications/Zotero\ Beta.app/Contents/MacOS/zotero -ZoteroDebugText -jsdebugger
```

::: tip 依赖 beta 版本 Zotero

需要 [Zotero beta builds](https://www.zotero.org/support/beta_builds) 。Windows 开发者可下载 zip 版本,解压缩后即可使用,不会将正式版覆盖。

:::

::: info 即将实现:在菜单栏中直接打开开发者工具

Zotero 团队正在添加“浏览器工具箱”菜单,以便直接从菜单呼出开发者工具,而无需在启动时传入 `--jsdebugger` 标志,见 [PR #3387](https://github.com/zotero/zotero/pull/3387)。

:::

::: tip 远程调试依赖 beta 版本 Zotero
::: info 模板用户无需手动配置

远程调试需要 [Zotero beta builds](https://www.zotero.org/support/beta_builds) 。Windows 开发者可下载 zip 版本,解压缩后即可使用,不会将正式版覆盖。
模板的启动脚本中已经进行了相关配置,`npm start` 后即可打开开发者工具。

:::

## 通过火狐浏览器远程调试 <Badge text='已弃用' />

:::: details 已过时:通过火狐浏览器远程调试连接到 Zotero

::: warning 该方法已过时

该方法已过时,Zotero 测试版现已内建 `Browser Toolbox`,请参阅 [通过开发者工具](#通过开发者工具)。

:::

Expand All @@ -39,24 +76,16 @@ author:
2. 使用 `--debugger` 参数启动 Zotero。
也可以将启动参数写入快捷方式。

3. 在 FireFox 115 ESR 中,找到`设置` -> `更多工具` -> `远程调试`(或者浏览器中输入:`about:debugging#/setup`),找到网络位置,输入 `localhost:6000`,点击确定添加即可。
3. 在 FireFox 115 ESR 中,找到`设置` -> `更多工具` -> `远程调试`(或者浏览器中输入:`about:debugging#/setup`),找到网络位置,输入 `localhost:6100`,点击确定添加即可。

::: tip

端口与第一步打开的高级编辑器中 `devtools.debugger.remote-port` 一致。

:::

4. 选择 `localhost:6000`,然后点击进程中的多线程工具箱进行检查,可进入控制台、无障碍环境等进行调试

::: tip Zotero 正在包含此功能
注意,自 Zotero 7.0.0-beta.104 开始,Zotero 不再固定使用 6100 作为端口号,而是使用随机端口号。

Zotero 团队正在将开发者工具嵌入 Zotero,见 [PR #3387](https://github.com/zotero/zotero/pull/3387),此 PR 合并后即可直接从菜单呼出开发者工具,而无需安装 FireFox。

:::

::: tip 模板用户无需手动配置
:::

模板的启动脚本中已经进行了相关配置,部分实现了上述 PR 的功能,因此你无需再手动执行以上步骤,也不需要安装 Firefox,`npm start` 后即可打开开发者工具。
4. 选择 `localhost:6100`,然后点击进程中的多线程工具箱进行检查,可进入控制台、无障碍环境等进行调试

:::
::::