Skip to content

fix(dom): keep unparseable deeply nested lines during markdown extraction - #5534

Open
pacocartones wants to merge 1 commit into
browser-use:mainfrom
pacocartones:fix/markdown-extract-recursionerror
Open

pacocartones wants to merge 1 commit into
browser-use:mainfrom
pacocartones:fix/markdown-extract-recursionerror

Conversation

@pacocartones

@pacocartones pacocartones commented Aug 24, 2026 •

Copy link
Copy Markdown

The SPA-JSON-blob filter in _preprocess_markdown_content drops long lines that parse as JSON, keeping the rest. It guards json.loads with except ValueError, but json.loads raises RecursionError — not a ValueError subclass — once a line nests past the scanner's limit.

So a page whose text contains a long deeply nested run (e.g. [[[[…) makes the exception escape _preprocess_markdown_content, propagate through convert_html_to_markdown and extract_clean_markdown, and fail the entire extract action for that page. Page content is untrusted input, so this is trivially triggerable.

Treating RecursionError like a decode error matches the intent: if we can't parse it, it isn't a blob we should drop.

Test: tests/ci/test_markdown_extractor.py::TestPreservesLinksAndEncoding::test_preserves_deeply_nested_bracket_lines — fails with RecursionError before the change, passes after. Pure unit test, no browser: uv run pytest goes from 1 failed, 14 passed to 15 passed. ruff format --check and ruff check clean.


Summary by cubic

Prevents markdown extraction from failing on deeply nested bracket runs by treating json.loads RecursionError as a decode failure in the SPA-JSON-blob filter. Previously such lines raised RecursionError, escaped _preprocess_markdown_content, and aborted extract_clean_markdown; now they are kept and extraction continues.

  • Catch (ValueError, RecursionError) around json.loads and keep unparseable lines.
  • Add unit test tests/ci/test_markdown_extractor.py::TestPreservesLinksAndEncoding::test_preserves_deeply_nested_bracket_lines.

Written for commit 22b4211. Summary will update on new commits.

View guided diff

@CLAassistant

CLAassistant commented Aug 24, 2026 •

Copy link
Copy Markdown

CLA assistant check
All committers have signed the CLA.

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

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

No issues found across 2 files

Re-trigger cubic

@pacocartones
pacocartones force-pushed the fix/markdown-extract-recursionerror branch from 648eb12 to c93da2b Compare August 28, 2026 08:10
@github-actions

Copy link
Copy Markdown

👋 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 Oct 13, 2026
…tion

json.loads raises RecursionError, not ValueError, once a line nests past
its scanner limit. The SPA-JSON-blob filter in _preprocess_markdown_content
only caught ValueError, so page text such as a long run of [[[[... escaped
the handler and propagated out of extract_clean_markdown, failing the whole
extract action for that page.

Treat RecursionError the same way as a decode error: the line is not JSON we
can parse, so keep it.

This branch has not been deployed

No deployments
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.

2 participants