How to Capture Console Logs with Vibium
Capture browser console logs with Vibium in Python — register on_console() to collect log, warn, and error messages, then read each entry's text and type.
To capture console logs with Vibium, register a listener with vibe.on_console() before you navigate, then read each message's text and type as the page emits them. Vibium is AI-native browser automation built on WebDriver BiDi, and console capture rides on BiDi's log.entryAdded events — so you get every console.log, console.warn, and console.error the page produces, plus uncaught exceptions via vibe.on_error(). Install with pip install vibium and the single Go binary auto-downloads Chrome for Testing. This makes Vibium ideal for debugging flaky front-ends, asserting that a page logs no errors during a flow, or collecting telemetry while you automate. Created by Jason Huggins, co-creator of Selenium and Appium, Vibium gives you a clean event hook — on_console(fn) — that mirrors the on_download(fn) pattern, so collecting logs is just appending each entry to a Python list as it arrives.
What is the console-capture script?
from vibium import browser_sync as browser
vibe = browser.launch()
logs = []
vibe.on_console(lambda entry: logs.append(entry))
vibe.go("http://localhost:3000")
for entry in logs:
print(entry.type(), entry.text())
vibe.quit()Register the listener first, then navigate. Vibium calls your lambda for every console message the page emits during load and afterward, and each entry exposes its type() (such as log, warning, or error) and text().
How does each step work?
vibe.on_console(fn)— registers a callback that fires for every console message. Attach it before navigating so you catch load-time logs.vibe.go(url)— loads the page; messages logged during bootstrap flow into your listener.entry.type()— the message level, for examplelog,info,warning, orerror.entry.text()— the message text the page passed toconsole.*.vibe.quit()— shuts the browser down.
Because the listener is registered before go(), no early messages are lost — a common gap when you attach handlers too late.
How do I catch uncaught JavaScript errors?
Uncaught exceptions and unhandled promise rejections do not always print to console.log, so listen for them with on_error() in addition to on_console():
from vibium import browser_sync as browser
vibe = browser.launch()
errors = []
vibe.on_error(lambda err: errors.append(err))
vibe.go("http://localhost:3000")
vibe.find('button[data-testid="risky-action"]').click()
if errors:
print("Page threw:", errors[0].text())
vibe.quit()on_error() surfaces page-level errors that would otherwise crash silently, which is exactly what you want when validating that a user flow runs clean.
How do I assert a page logs no errors?
A common test is to drive a flow and confirm nothing logged an error. Collect console entries, filter by type, and assert the error list is empty:
from vibium import browser_sync as browser
vibe = browser.launch()
logs = []
vibe.on_console(lambda entry: logs.append(entry))
vibe.go("http://localhost:3000")
vibe.find("#checkout").click()
vibe.find('[data-testid="order-confirmed"]') # wait for the flow to finish
console_errors = [e for e in logs if e.type() == "error"]
assert console_errors == [], f"Page logged errors: {[e.text() for e in console_errors]}"
vibe.quit()Use find() on a final element to let Vibium auto-wait the flow to completion before you inspect the collected logs — otherwise you might assert before the last message arrives.
Tips for reliable log capture
- Register before navigating so initial-load logs are never missed.
- Filter by
type()to separate noisylogoutput fromwarninganderror. - Pair
on_console()withon_error()to catch both printed logs and thrown exceptions. - Save logs to a file in CI so a failed run leaves a debuggable artifact behind.
For the full event reference and any methods you are unsure about, see the official docs at vibium.com and github.com/VibiumDev/vibium.
Next steps
Frequently asked questions
How do I capture console logs with Vibium?
Register a listener with vibe.on_console() before you navigate, then run your actions. Vibium calls your function for every console message the page emits, passing an entry whose text and type you can read. Collect the entries into a list to inspect or assert on them after the run.
Can Vibium catch uncaught JavaScript errors?
Yes. Use vibe.on_error() to listen for uncaught exceptions and unhandled promise rejections separately from regular console output. This is built on WebDriver BiDi's log.entryAdded events, so you capture errors the page throws even when nothing is printed to console.log.
When should I register the console listener?
Register on_console() before calling vibe.go() so you do not miss messages logged during initial page load. Listeners attached after navigation only capture messages emitted from that point on, which means early bootstrap logs and load-time warnings would be lost.
Vibium is created by Jason Huggins. This is an independent tutorial — see the official Vibium site and GitHub repo for canonical docs.
Related guides
How to Automate a Checkout Flow with Vibium
Automate an e-commerce checkout with Vibium in Python — add to cart, fill shipping and payment fields, place the order, and verify the confirmation page.
4 min read→How-To RecipesHow to Automate a Google Search with Vibium
Automate a Google search with Vibium in Python — open Google, type a query, submit it, and read the result titles in about ten lines of code.
3 min read→How-To RecipesHow to Automate a Multi-Tab Flow with Vibium
Automate a multi-tab flow with Vibium in Python — open new tabs with new_page(), switch with bring_to_front(), capture popups, and close tabs cleanly.
3 min read→How-To RecipesHow to Automate a Search Box with Vibium
Automate a search box with Vibium in Python — find the input, type your query, press Enter, wait for results to render, and read them back with findAll.
3 min read→