jackwener / jackwener/OpenCLI

[autofix] xiaohongshu/search: COMMAND_EXEC MutationObserver TypeError when document.body is null

Open Beginner friendly
#2,495 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
JavaScript
Stars
29.5k
Forks
2.9k
Avg merge
15h 36m
Merged PRs (30d)
70

Description

[autofix] xiaohongshu/search: COMMAND_EXEC MutationObserver TypeError when document.body is null

## Summary
Local autofix repair verified — retry passes the crash stage after this patch.

## Adapter
- Site: `xiaohongshu`
- Command: `xiaohongshu/search` (`clis/xiaohongshu/search.js`)
- OpenCLI version: `1.8.8`

## Failure
```
COMMAND_EXEC: Xiaohongshu search failed: TypeError: Failed to execute 'observe' on
'MutationObserver': parameter 1 is not of type 'Node'.
at :18:14
at new Promise ()
at :1:1
```
Reproduces consistently since ~2026-09-13 evenings (UTC+8), across all keywords,
even with default args. Trace `:18` maps to `WAIT_FOR_CONTENT_JS`
line `observer.observe(document.body, { childList: true, subtree: true })` —
`document.body` is null at evaluation time because the xiaohongshu search_result
page now performs an extra client-side redirect before committing a body, so the
evaluate lands in a document where only `documentElement` exists.

Note the same script already null-guards `document.body?.innerText` in `detect()`
two lines above — only the `observe()` target lacks the guard.

## Local fix
Guard both MutationObserver targets with a fallback (`document.body || documentElement`),
`search.js` lines 39 and 598:
```js
observer.observe(document.body || document.documentElement, { childList: true, subtree: true });
```
A subtree observer on `documentElement` fires when `` is inserted, so
content detection resumes normally. Also raised the content-wait ceiling from 5s
to 20s, which absorbs the extra redirect hop on slower sessions. Output shape
unchanged.

Related: #2470 (umbrella), #2445 (filter ambiguous_option — separate root cause,
same command).

_Issue filed by OpenCLI autofix after a verified local repair._

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start in clis/xiaohongshu/search.js, especially WAIT_FOR_CONTENT_JS around lines 39 and 598, and review the existing body guard in detect(). Run the xiaohongshu/search command with default and keyword arguments to reproduce the redirect timing, then verify the retry passes without a MutationObserver TypeError and preserves the existing output shape.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript
Domain
cli
Issue type
Bug
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Active
Clarity
Clearly specified
Newbie friendliness
88/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.