Skip to content

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

fix: remove redundant local tempfile imports

Laith Weinbergere239d1f523bc
diff --git a/browser_use/browser/profile.py b/browser_use/browser/profile.py
index fd8e34171..4d8858a2d 100644
--- a/browser_use/browser/profile.py
+++ b/browser_use/browser/profile.py
@@ -430,14 +430,14 @@ class BrowserLaunchArgs(BaseModel):
if self.downloads_path is None:
import uuid
- # Create unique directory in /tmp for downloads
+ # Create unique directory in system temp folder for downloads
unique_id = str(uuid.uuid4())[:8] # 8 characters
- downloads_path = Path(f'/tmp/browser-use-downloads-{unique_id}')
+ downloads_path = Path(tempfile.gettempdir()) / f'browser-use-downloads-{unique_id}'
# Ensure path doesn't already exist (extremely unlikely but possible)
while downloads_path.exists():
unique_id = str(uuid.uuid4())[:8]
- downloads_path = Path(f'/tmp/browser-use-downloads-{unique_id}')
+ downloads_path = Path(tempfile.gettempdir()) / f'browser-use-downloads-{unique_id}'
self.downloads_path = downloads_path
self.downloads_path.mkdir(parents=True, exist_ok=True)
@@ -1153,7 +1153,6 @@ async function initialize(checkInitialized, magic) {{
zip_data = f.read()
# Write ZIP data to temp file and extract
- import tempfile
with tempfile.NamedTemporaryFile(suffix='.zip', delete=False) as temp_zip:
temp_zip.write(zip_data)
diff --git a/browser_use/code_use/service.py b/browser_use/code_use/service.py
index e4f5b54d3..440a4a984 100644
--- a/browser_use/code_use/service.py
+++ b/browser_use/code_use/service.py
@@ -6,6 +6,7 @@ import html
import json
import logging
import re
+import tempfile
import traceback
from pathlib import Path
from typing import Any
@@ -175,7 +176,7 @@ class CodeAgent:
# Initialize screenshot service for eval tracking
self.id = uuid7str()
timestamp = datetime.datetime.now().strftime('%Y%m%d_%H%M%S')
- base_tmp = Path('/tmp')
+ base_tmp = Path(tempfile.gettempdir())
self.agent_directory = base_tmp / f'browser_use_code_agent_{self.id}_{timestamp}'
self.screenshot_service = ScreenshotService(agent_directory=self.agent_directory)