Skip to main content

其他调试方法

本页介绍如何使用旧版 JavaScript 调试方法。如果你正在开始使用新的 React Native 或 Expo 应用,我们建议使用 React Native DevTools

¥This page covers how to use legacy JavaScript debugging methods. If you are getting started with a new React Native or Expo app, we recommend using React Native DevTools.

Safari 开发者工具(直接 JSC 调试)

¥Safari Developer Tools (direct JSC debugging)

当使用 JavaScript 核心 (JSC) 作为应用的运行时时,你可以使用 Safari 来调试应用的 iOS 版本。

¥You can use Safari to debug the iOS version of your app when using JavaScriptCore (JSC) as your app's runtime.

  1. 仅物理设备:打开“设置”应用,导航至 Safari > 高级,并确保 "网页检查器" 已打开。

    ¥Physical devices only: Open the Settings app, and navigate to Safari > Advanced, and make sure "Web Inspector" is turned on.

  2. 在 Mac 上,打开 Safari 并启用“开发”菜单。这可以在 Safari > 设置... 下找到,然后在高级选项卡中找到,然后选择 "为 Web 开发者展示功能"。

    ¥On your Mac, open Safari and enable the Develop menu. This can be found under Safari > Settings..., then the Advanced tab, then selecting "Show features for web developers".

  3. 在开发菜单下找到你的设备,然后从子菜单中选择 "JSContext" 项。这将打开 Safari 的 Web Inspector,其中包括类似于 Chrome DevTools 的控制台和源面板。

    ¥Find your device under the Develop menu, and select the "JSContext" item from the submenu. This will open Safari's Web Inspector, which includes Console and Sources panels similar to Chrome DevTools.

Opening Safari Web Inspector

提示

虽然默认情况下源映射可能未启用,但你可以按照 本指南video 启用它们并在源代码中的正确位置设置断点。

¥While source maps may not be enabled by default, you can follow this guide or video to enable them and set break points at the right places in the source code.

提示

每次重新加载应用时,都会创建一个新的 JSContext。选择 "自动显示 JSContext 的 Web 检查器" 可以让你不必手动选择最新的 JSContext。

¥Every time the app is reloaded, a new JSContext is created. Choosing "Automatically Show Web Inspectors for JSContexts" saves you from having to select the latest JSContext manually.

远程 JavaScript 调试(已移除)

¥Remote JavaScript Debugging (removed)

重要的

远程 JavaScript 调试已从 React Native 0.79 版本中删除。查看原始 弃用公告

¥Remote JavaScript Debugging has been removed as of React Native 0.79. See the original deprecation announcement.

如果你使用的是旧版本的 React Native,请转到文档 适用于你的版本

¥If you are on an older version of React Native, please go to the docs for your version.

The remote debugger window in Chrome