Skip to content

Infinite loop in prettyDOM calls crashes test when locator.element() is not found #7249

@tsirlucas

Description

@tsirlucas

Describe the bug

In

const pretty = stringify(dom, Number.POSITIVE_INFINITY, {
Infinity is sent as parameter to stringify and in
? stringify(object, Math.floor(maxDepth / 2))
the stop condition to the recursion is done by dividing the maxDepth by 2. Considering Infinity / 2 = Infinity, the code enters in a loop and ends up crashing the page.

Reproduction

Found it in private big project (can only be reproduced if the DOM is large enough to enter the result.length >= MAX_LENGTH check. Maybe we can reproduce it by adding a unit test where we send a really small maxDepth and the whole page as object.

System Info

System:
    OS: macOS 15.1.1
    CPU: (14) arm64 Apple M3 Max
    Memory: 6.47 GB / 36.00 GB
    Shell: 5.9 - /bin/zsh
  Binaries:
    Node: 20.12.2 - ~/.nvm/versions/node/v20.12.2/bin/node
    Yarn: 4.6.0 - ~/.nvm/versions/node/v20.12.2/bin/yarn
    npm: 10.5.0 - ~/.nvm/versions/node/v20.12.2/bin/npm
    pnpm: 9.15.2 - ~/.nvm/versions/node/v20.12.2/bin/pnpm
  Browsers:
    Chrome: 131.0.6778.265
    Safari: 18.1.1

Used Package Manager

yarn

Validations

Metadata

Metadata

Assignees

No one assigned

    Labels

    feat: browserIssues and PRs related to the browser runnerp3-minor-bugAn edge case that only affects very specific usage (priority)

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions