Skip to content

Commit 91f89e7

Browse files
committed
feat: initialize browser and close it to resolve UnboundLocalError.
1 parent db6348d commit 91f89e7

File tree

1 file changed

+8
-3
lines changed

1 file changed

+8
-3
lines changed

webui.py

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -199,6 +199,7 @@ async def run_custom_agent(
199199
controller = CustomController()
200200
playwright = None
201201
browser_context_ = None
202+
browser = None # Initialize browser to None
202203
try:
203204
if use_own_browser:
204205
playwright = await async_playwright().start()
@@ -278,14 +279,18 @@ async def run_custom_agent(
278279
model_actions = ""
279280
model_thoughts = ""
280281
finally:
281-
# 显式关闭持久化上下文
282+
# Close persistent context if it was initialized
282283
if browser_context_:
283284
await browser_context_.close()
284285

285-
# 关闭 Playwright 对象
286+
# Stop Playwright if it was started
286287
if playwright:
287288
await playwright.stop()
288-
await browser.close()
289+
290+
# Close the browser if it was initialized
291+
if browser:
292+
await browser.close()
293+
289294
return final_result, errors, model_actions, model_thoughts
290295

291296
# Define the theme map globally

0 commit comments

Comments
 (0)