Skip to content

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

fix nulref

Nick Sweetingf6bec3cd911e
diff --git a/browser_use/browser/context.py b/browser_use/browser/context.py
index a776c809e..6e7cf6bf0 100644
--- a/browser_use/browser/context.py
+++ b/browser_use/browser/context.py
@@ -669,7 +669,7 @@ class BrowserContext:
init_script = """
// check to make sure we're not inside the PDF viewer
- window.isPdfViewer = !!document.body.querySelector('body > embed[type="application/pdf"][width="100%"]')
+ window.isPdfViewer = !!document?.body?.querySelector('body > embed[type="application/pdf"][width="100%"]')
if (!window.isPdfViewer) {
// Permissions