Skip to content

page.observe() sometimes results in: Cannot read properties of undefined (reading 'replace') at trimTrailingTextNode #854

@motoki317

Description

@motoki317

Description

When running await page.observe({ instruction: "find search element" }), it sometimes results in the following error.

trace: "TypeError: Cannot read properties of undefined (reading 'replace')
    at trimTrailingTextNode (./node_modules/@browserbasehq/stagehand/dist/index.js:2330:16)
    at StagehandObserveHandler.<anonymous> (./node_modules/@browserbasehq/stagehand/dist/index.js:3328:32)
    at Generator.next (<anonymous>)
    at ./node_modules/@browserbasehq/stagehand/dist/index.js:79:61
    at new Promise (<anonymous>)
    at __async (./node_modules/@browserbasehq/stagehand/dist/index.js:63:10)
    at ./node_modules/@browserbasehq/stagehand/dist/index.js:3313:55
    at Array.map (<anonymous>)
    at StagehandObserveHandler.<anonymous> (./node_modules/@browserbasehq/stagehand/dist/index.js:3313:38)
    at Generator.next (<anonymous>)"

I'm trying to replicate this behavior, but it seems to be inherently flaky.

Replication Code

#854 (comment)

Version

  • stagehand v2.4.0
    • also confirmed in 2.4.1-alpha-64c10727bda50470483a3eb175c02842db0923a1

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions