reactjs - 如何将 console.log 消息从 Firefox/Chrome webbrowser 控制台重定向到终端
问题描述
正如标题中所说,我想将出现在浏览器控制台中的 console.log 消息重定向到我的 windows 终端——例如 VSCode 中的内置终端。有没有办法通过一些内置的浏览器功能来实现这个结果,或者它宁愿需要我运行一些外部工具、代理后端或像 Selenium 这样的虚拟浏览器?问题涉及使用 webpack 制作的 React 应用程序。谢谢。
解决方案
driver.manage().logs().get(logging.Type.BROWSER)
.then(function(entries) {
entries.forEach(function(entry) {
console.log('[%s] %s', entry.level.name, entry.message);
});
});
** 注意:** 只有少数浏览器支持远程日志记录 API(尤其是 Firefox 和 Chrome)。Firefox 支持基本的日志记录功能,而 Chrome 提供了强大的性能日志记录选项。远程日志记录仍然被认为是一个非标准特性,并且该模块为其公开的 API 是非冻结的。一旦 W3C WebDriver 规范正式定义日志记录,此模块将被更新,可能会破坏向后兼容性。
https://www.selenium.dev/selenium/docs/api/javascript/module/selenium-webdriver/lib/logging.html
你的问题被标记为 JavaScript,但你写的是关于 python,你可以在 Python 中以类似的方式记录日志,请参阅:Getting console.log output from Chrome with Selenium Python API bindings和https://docs.python.org/3/如何/logging.html
推荐阅读
- netlogo - 用 where 询问 - 我找不到语法
- java - 如何在 XML 中使用 java 方法的返回值
- html - 如何在悬停元素期间制作上拉效果?只需查看此代码一次
- python - Discord.py 如何跟踪所有公会
- c# - 没有数据库的 .NET Core 基准测试
- c# - 为什么在使用 ASP.NET Core 时,对于等效于工作同步控制器的异步控制器,HttpContext.User.Identity.Name 显示为空?
- arrays - 使用处理随机重新排列图像的部分
- r - 使用 R 中的 data.table 转换多列并返回所有列
- android - 从 SQLitE 数据库加载的数据未保存在模型类 ArrayList android 中
- javascript - 使用 javascript 或 jquery 左右句柄的文本选择