Skip to content

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

simplify and remove chinese comments in source code

Nick Sweeting1c4f523630dd
diff --git a/browser_use/agent/gif.py b/browser_use/agent/gif.py
index 470b0d58e..72056306e 100644
--- a/browser_use/agent/gif.py
+++ b/browser_use/agent/gif.py
@@ -22,13 +22,8 @@ def decode_unicode_escapes_to_chinese(text: str) -> str:
try:
# Try to decode Unicode escape sequences
return text.encode('latin1').decode('unicode_escape')
- except UnicodeEncodeError:
- # If encoding to latin1 fails, return the original text
- logger.warning(f"Failed to encode text to latin1: {text}")
- return text
- except UnicodeDecodeError:
- # If decoding from unicode_escape fails, return the original text
- logger.warning(f"Failed to decode Unicode escape sequences: {text}")
+ except (UnicodeEncodeError, UnicodeDecodeError):
+ # logger.debug(f"Failed to decode unicode escape sequences while generating gif text: {text}")
return text
def create_history_gif(
@@ -64,14 +59,13 @@ def create_history_gif(
try:
# Try different font options in order of preference
# ArialUni is a font that comes with Office and can render most non-alphabet characters
- # 添加更多字体
font_options = [
'Microsoft YaHei', # 微软雅黑
'SimHei', # 黑体
'SimSun', # 宋体
'Noto Sans CJK SC', # 思源黑体
'WenQuanYi Micro Hei', # 文泉驿微米黑
- """ ↑ 中文字符 ↑ """
+ # ↑ 中文字符 ↑
'Helvetica', 'Arial', 'DejaVuSans', 'Verdana' # 原有字体
]
font_loaded = False
@@ -251,7 +245,7 @@ def _add_overlay_to_image(
from PIL import Image, ImageDraw
# 转码为中文
- goal_text = decode_unicode_escapes_to_chinese(goal_text)
+ goal_text = decode_unicode_escapes_to_utf8(goal_text)
image = image.convert('RGBA')
txt_layer = Image.new('RGBA', image.size, (0, 0, 0, 0))
draw = ImageDraw.Draw(txt_layer)
@@ -347,8 +341,7 @@ def _wrap_text(text: str, font: 'ImageFont.FreeTypeFont', max_width: int) -> str
Returns:
Wrapped text with newlines
"""
- # 转码为中文
- text = decode_unicode_escapes_to_chinese(text)
+ text = decode_unicode_escapes_to_utf8(text)
words = text.split()
lines = []
current_line = []