Skip to content

Open-source Python library for AI browser agents, plus Browser Use Cloud: stealth browsers and a hosted agent API.

dont show dvd loading animation if document.body is not availble yet

Nick Sweetingccac8a593488
diff --git a/browser_use/browser/session.py b/browser_use/browser/session.py
index 388770688..a0a28855b 100644
--- a/browser_use/browser/session.py
+++ b/browser_use/browser/session.py
@@ -4430,6 +4430,15 @@ class BrowserSession(BaseModel):
try:
await page.evaluate(
"""(browser_session_label) => {
+ // Ensure document.body exists before proceeding
+ if (!document.body) {
+ // Try again after DOM is ready
+ if (document.readyState === 'loading') {
+ document.addEventListener('DOMContentLoaded', () => arguments.callee(browser_session_label));
+ }
+ return;
+ }
+
const animated_title = `Starting agent ${browser_session_label}...`;
if (document.title === animated_title) {
return; // already run on this tab, dont run again