-
Notifications
You must be signed in to change notification settings - Fork 1.3k
fix: setInputFiles() not working on Browserbase
#1267
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix: setInputFiles() not working on Browserbase
#1267
Conversation
🦋 Changeset detectedLatest commit: 6e1378c The changes in this PR will be included in the next version bump. This PR includes changesets to release 2 packages
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
9 files reviewed, 1 comment
Greptile OverviewGreptile SummaryThis PR fixes file uploads on Browserbase by implementing a dual-path strategy: remote browsers now serialize files to base64 and reconstruct them client-side via JavaScript injection, while local browsers continue using CDP's Key Changes:
Implementation Quality:
Confidence Score: 5/5
Important Files ChangedFile Analysis
Sequence DiagramsequenceDiagram
participant User
participant Locator
participant FileUtils as normalizeInputFiles
participant Frame
participant CDP as CDP Session
participant Browser as Browser/Page
User->>Locator: setInputFiles(files)
Locator->>CDP: Validate element is input[type=file]
CDP-->>Locator: Validation OK
Locator->>FileUtils: normalizeInputFiles(files)
alt File path provided
FileUtils->>FileUtils: Resolve absolute path
FileUtils->>FileUtils: Read file from disk
FileUtils-->>Locator: NormalizedFilePayload with buffer & path
else Payload object provided
FileUtils->>FileUtils: Convert buffer to Node Buffer
FileUtils-->>Locator: NormalizedFilePayload with buffer
end
Locator->>Frame: isBrowserRemote()
alt Remote Browser (Browserbase)
Frame-->>Locator: true
Locator->>Locator: Check file size < 50MB
Locator->>Locator: Serialize files to base64
Locator->>CDP: callFunctionOn(assignFilePayloadsToInputElement)
CDP->>Browser: Execute in page context
Browser->>Browser: Decode base64 to bytes
Browser->>Browser: Create File objects via DataTransfer
Browser->>Browser: Assign to input.files
Browser->>Browser: Dispatch input/change events
Browser-->>CDP: Success
CDP-->>Locator: Upload complete
else Local Browser
Frame-->>Locator: false
alt File has absolutePath
Locator->>Locator: Use existing path
else Payload without path
Locator->>Locator: Write buffer to temp file
end
Locator->>CDP: DOM.setFileInputFiles(filePaths)
CDP->>Browser: Set files via CDP
Browser-->>CDP: Success
CDP-->>Locator: Upload complete
Locator->>Locator: Cleanup temp files
end
Locator-->>User: Success
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
9 files reviewed, no comments
This PR was opened by the [Changesets release](https://github.com/changesets/action) GitHub action. When you're ready to do a release, you can merge this and the packages will be published to npm automatically. If you're not ready to do a release yet, that's fine, whenever you add more changesets to main, this PR will be updated. # Releases ## @browserbasehq/stagehand@3.0.3 ### Patch Changes - [#1273](#1273) [`ab51232`](ab51232) Thanks [@seanmcguire12](https://github.com/seanmcguire12)! - fix: trigger shadow root rerender in OOPIFs by cloning & replacing instead of reloading - [#1268](#1268) [`c76ade0`](c76ade0) Thanks [@tkattkat](https://github.com/tkattkat)! - Expose reasoning, and cached input tokens in stagehand metrics - [#1267](#1267) [`ffb5e5d`](ffb5e5d) Thanks [@seanmcguire12](https://github.com/seanmcguire12)! - fix: file uploads failing on Browserbase - [#1269](#1269) [`772e735`](772e735) Thanks [@tkattkat](https://github.com/tkattkat)! - Add example using playwright screen recording ## @browserbasehq/stagehand-evals@1.1.3 ### Patch Changes - Updated dependencies \[[`ab51232`](ab51232), [`c76ade0`](c76ade0), [`ffb5e5d`](ffb5e5d), [`772e735`](772e735)]: - @browserbasehq/stagehand@3.0.3 Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
why
setInputFiles()was not serializing the file payloadwhat changed
changed business logic of
setInputFiles()to:normalizeInputFiles(), which returns a serializable/base64 encoded fileassignFilesViaPayloadInjection()is called, which then callsassignFilePayloadsToInputElement()(browser-side JS) and reconstructs the base64 back into a file, and directly assigns the reconstructed files to theinputelementDOM.setInputFiles(CDP command)test plan