Chrome 调试 react-native 通过Network面板查看网络请求

参考 https://github.com/facebook/react-native/issues/934 三楼

真机或模拟器下 Debug JS Remotely, 会打开chrome,地址为ip:8081/debugger-ui/ 可能无法访问,手动改成 http://localhost:8081/debugger-ui/ (可以访问自动 忽略)

打开控制台查看Network面板

真机或模拟器reload 发现在Chrome面板下并没有我们的fetch网络请求

我的react-native版本是0.57.5 其他版本可以自己找找

react-native\Libraries\Core\InitializeCore.js -> 搜索 XMLHttpRequest 会有注释提醒

The native XMLHttpRequest in Chrome dev tools is CORS aware and won't let you fetch anything from the internet

(Chrome开发工具中的原生XMLHttpRequest具有CORS感知功能,不允许您从互联网上获取任何内容 谷歌翻译)

注释掉 polyfillGlobal('XMLHttpRequest', () => require('XMLHttpRequest'));

再在真机或模拟器reload 查看Network面板,此时就可以查看到我们的fetch请求了