Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

dohyun-ko
Copy link

@dohyun-ko dohyun-ko commented Jun 9, 2025

Summary

  • This PR introduces support for rendering Korean and Japanese characters correctly in GIFs generated by gif.py.

Problem

  • Korean texts are garbled when rendering GIF.
  • Simply adding Korean fonts to the fonts array has some limitations
    • Scenario: Suppose Chinese fonts have higher priority than Korean fonts. Both Chinese and Korean fonts are installed on the machine, and the user wants to render Korean text. -> Using Chinese font for Korean text, therefore texts are garbled.

Solution

  • To resolve this, this PR implements a language detection mechanism using regular expressions. A dedicated font array is now defined for each language (Korean and Japanese). When rendering text, its language is first detected, and the corresponding font set is used, ensuring correct character display.

Known Issues & Limitations

Screenshots

Cursor 2025-06-09 14 01 24 Cursor 2025-06-09 11 54 13

Test Script

from langchain_google_genai import ChatGoogleGenerativeAI
from browser_use import Agent
from dotenv import load_dotenv
load_dotenv()

import asyncio

llm = ChatGoogleGenerativeAI(model="gemini-2.5-flash-preview-05-20")

prompt_gif_test_korean = """
당신은 QA 엔지니어입니다. google.com에 방문해 화면이 잘 나오는지 확인하세요. 그리고 종료하세요.
"""

prompt_gif_test_japanese = """
あなたはQAエンジニアです。 google.comにアクセスして、画面が正常に表示されるか確認してください。そして、終了してください。
"""

prompt_gif_test_chinese = """
你是一名QA工程师。访问google.com. 检查屏幕是否正常显示。然后关闭。
"""

async def main():
    agent = Agent(
        task=prompt_gif_test_japanese,
        llm=llm,
        generate_gif=True,
    )
    result = await agent.run()
    print(result)

asyncio.run(main())

Summary by cubic

Added support for Korean and Japanese fonts in GIF rendering by detecting text language and selecting the correct font, so characters display properly.

  • New Features
    • Detects Korean, Japanese, and Chinese text using regular expressions.
    • Chooses a dedicated font set for each language to prevent garbled text.

@CLAassistant
Copy link

CLAassistant commented Jun 9, 2025

CLA assistant check
All committers have signed the CLA.

Copy link
Contributor

@cubic-dev-ai cubic-dev-ai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

cubic found 2 issues across 1 file. Review them in cubic.dev

React with 👍 or 👎 to teach cubic. Tag @cubic-dev-ai to give specific feedback.

@dohyun-ko
Copy link
Author

Help needed from Japanese/Chinese/Windows users to test the new GIF rendering! Please let me know if the text displays correctly for you. 🥺

Copy link

👋 This PR has been automatically marked as stale because it hasn't had activity for 45 days.

To keep this PR open:

  • Rebase against the latest main branch
  • Address any review feedback or merge conflicts
  • Add a comment explaining the current status
  • Add the work-in-progress label if you're still actively working on this

This will be automatically closed in 14 days if no further activity occurs.

Thanks for contributing to browser-use! 🤖

@github-actions github-actions bot added the stale label Aug 29, 2025
Co-authored-by: cubic-dev-ai[bot] <191113872+cubic-dev-ai[bot]@users.noreply.github.com>
@MagMueller
Copy link
Collaborator

@dohyun-ko Sorry we did not prioritize this so far.

Can you solve the conflicts, I am happy to merge it!

font_size = base_font_size

larger_font = ImageFont.truetype(regular_font.path, font_size)
larger_font = ImageFont.truetype(task_font.path, font_size) if hasattr(task_font, "path") else task_font
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Bug: Dynamic Font Sizing Fails Without Path

It looks like the dynamic font sizing for task text isn't working as expected when a default font is loaded. If task_font lacks a path attribute, the code uses task_font directly, which means the dynamically calculated font_size based on text length isn't applied. This can cause task text to render at an incorrect, non-dynamic size.

Fix in Cursor Fix in Web

@github-actions github-actions bot removed the stale label Sep 7, 2025
@mertunsall
Copy link
Collaborator

Hi - happy to take a look again if you resolve merge conflicts. Please try to keep the code clean and not AI-generated and separate the functions to acommodate for this scenario clearly.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants