如何捕获所有控制台错误日志剧作家

发布于 2025-01-12 14:34:59 字数 727 浏览 0 评论 0原文

输入图像描述这里

我尝试了所有这些,

page.on("console", lambda msg: print(f"error: {msg.text}") if msg.type == "error" else None)
page.on("console", lambda msg: print(msg.text))
page.on("pageerror", lambda exc: print(f"uncaught exception: {exc}"))

没有任何效果

终端输出

python main.py 
/home/xxx/.local/lib/python3.9/site-packages/trio/_core/_multierror.py:511: RuntimeWarning: You seem to already have a custom sys.excepthook handler installed. I'll skip installing Trio's custom handler, but this means MultiErrors will not show full tracebacks.
  warnings.warn(

enter image description here

I tried all of this,

page.on("console", lambda msg: print(f"error: {msg.text}") if msg.type == "error" else None)
page.on("console", lambda msg: print(msg.text))
page.on("pageerror", lambda exc: print(f"uncaught exception: {exc}"))

Nothing works

Terminal output

python main.py 
/home/xxx/.local/lib/python3.9/site-packages/trio/_core/_multierror.py:511: RuntimeWarning: You seem to already have a custom sys.excepthook handler installed. I'll skip installing Trio's custom handler, but this means MultiErrors will not show full tracebacks.
  warnings.warn(

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

ペ泪落弦音 2025-01-19 14:34:59

在没有最低限度可重现的示例的情况下,使用示例场景代码来说明用法:

# Listen for all console logs
page.on("console", lambda msg: print(msg.text))

# Listen for all console events and handle errors
page.on("console", lambda msg: print(f"error: {msg.text}") if msg.type == "error" else None)




# Get the next console log
async with page.expect_console_message() as msg_info:
    # Issue console.log inside the page
    await page.evaluate("console.log('hello', 42, { foo: 'bar' })")
msg = await msg_info.value

# Deconstruct print arguments
await msg.args[0].json_value() # hello
await msg.args[1].json_value() # 42

参考: https://playwright.dev/python/docs/api/class-consolemessage

In the absence of a minimally reproducible example , a sample scenario code to illustrate the usage:

# Listen for all console logs
page.on("console", lambda msg: print(msg.text))

# Listen for all console events and handle errors
page.on("console", lambda msg: print(f"error: {msg.text}") if msg.type == "error" else None)




# Get the next console log
async with page.expect_console_message() as msg_info:
    # Issue console.log inside the page
    await page.evaluate("console.log('hello', 42, { foo: 'bar' })")
msg = await msg_info.value

# Deconstruct print arguments
await msg.args[0].json_value() # hello
await msg.args[1].json_value() # 42

Reference: https://playwright.dev/python/docs/api/class-consolemessage

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文