Skip to content

fix: add maxSiblingElements to prevent HTTP 413 with large dropdowns#401

Open
octo-patch wants to merge 1 commit intoalibaba:mainfrom
octo-patch:fix/issue-348-limit-sibling-elements
Open

fix: add maxSiblingElements to prevent HTTP 413 with large dropdowns#401
octo-patch wants to merge 1 commit intoalibaba:mainfrom
octo-patch:fix/issue-348-limit-sibling-elements

Conversation

@octo-patch
Copy link
Copy Markdown
Contributor

Fixes #348

Problem

When a dropdown with many options is open (e.g. a country selector with 200+ entries), all visible option elements get indexed as interactive elements and included in the dehydrated HTML sent to the LLM. This causes the LLM API to return HTTP 413: Payload Too Large.

The maintainer confirmed this in the issue comments: "听起来所有的 options 都被放在了清洗后的数据里" (it sounds like all options are being put into the cleaned data).

Solution

Add a maxSiblingElements option to DomConfig (and consequently PageControllerConfig). When set, the flatTreeToString function limits how many same-tag children are rendered per parent node. Excess items are replaced with a single summary line, e.g.:

... 150 more <li> items not shown (maxSiblingElements=50)

This tells the LLM there are more options available, so it can scroll or search the dropdown instead of expecting all items upfront.

The option is undefined by default (no limit), preserving full backward compatibility.

Usage

const controller = new PageController({
  maxSiblingElements: 50,  // show at most 50 same-tag siblings per parent
})

Testing

  • Option is undefined by default: existing behavior is unchanged
  • When set, verifiable by logging simplifiedHTML on a page with a large dropdown open and confirming the output is truncated with a descriptive summary line
  • No existing tests broken (feature is additive)

…ixes alibaba#348)

When a dropdown with many options is open, all options are indexed as
interactive elements and included in the dehydrated HTML sent to the
LLM, causing HTTP 413 Payload Too Large errors.

Add a maxSiblingElements option to DomConfig that limits how many
same-tag children are rendered per parent node in the dehydrated output.
Excess items are replaced with a summary line. The option is off by
default to preserve backward compatibility.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

1 participant