Skip to content

Conversation

@jspanjers
Copy link

@jspanjers jspanjers commented Dec 12, 2025

User description

🔗 Related Issues

Provides a quickfix for #14116.

💥 What does this PR do?

Implements full page screenshots for Chromium browsers for the Ruby language.

It extends the Chromium driver with full page screenshot functionality, similar to how it was implemented before for the Firefox driver. It uses Chrome's session/:session_id/screenshot/full endpoint.

🔧 Implementation Notes

Issue #14116 was originally opened to raise the issue that full page screenshots are not working for the ruby bindings in Chrome/Edge using driver.save_screenshot(path, full_page: true). This is fixed here.

💡 Additional Considerations

In Issue #14116 there is discussion about rewriting Selenium's screenshot functionality to use BiDi, and changing the API to something like driver.page.screenshot(params). I believe rewriting to use BiDi can be done later, as well as changing the API. I am also not sure that there is a specification for taking full page screenshots with BiDi yet.

🔄 Types of changes

  • New feature (non-breaking change which adds functionality and tests!)

PR Type

Enhancement


Description

  • Adds full page screenshot support for Chrome in Ruby bindings

  • Implements full_screenshot method in Chromium driver bridge

  • Registers new full_page_screenshot endpoint for Chrome driver

  • Includes integration test validating full page screenshot functionality


Diagram Walkthrough

flowchart LR
  A["Chrome Driver"] -->|extends with| B["FullPageScreenshot Extension"]
  B -->|calls| C["full_screenshot method"]
  C -->|executes| D["session/:session_id/screenshot/full endpoint"]
  D -->|returns| E["Full page screenshot PNG"]
Loading

File Walkthrough

Relevant files
Enhancement
driver.rb
Register FullPageScreenshot extension in Chromium driver 

rb/lib/selenium/webdriver/chromium/driver.rb

  • Adds DriverExtensions::FullPageScreenshot to the EXTENSIONS list for
    Chromium driver
  • Enables full page screenshot functionality for Chrome and Edge drivers
+1/-0     
features.rb
Implement full page screenshot bridge and endpoint             

rb/lib/selenium/webdriver/chromium/features.rb

  • Adds full_page_screenshot command mapping to Chrome's screenshot/full
    endpoint
  • Implements full_screenshot method in Bridge module to execute the
    command
  • Enables direct access to Chrome's native full page screenshot
    capability
+6/-1     
Tests
driver_spec.rb
Add full page screenshot integration test                               

rb/spec/integration/selenium/webdriver/chrome/driver_spec.rb

  • Adds integration test for full page screenshot functionality
  • Verifies screenshot height exceeds viewport height for full page
    capture
  • Tests save_screenshot with full_page: true parameter
  • Validates PNG file creation and size
+13/-0   

@CLAassistant
Copy link

CLAassistant commented Dec 12, 2025

CLA assistant check
All committers have signed the CLA.

@selenium-ci selenium-ci added the C-rb Ruby Bindings label Dec 12, 2025
@qodo-code-review
Copy link
Contributor

qodo-code-review bot commented Dec 12, 2025

PR Compliance Guide 🔍

Below is a summary of compliance checks for this PR:

Security Compliance
🟢
No security concerns identified No security vulnerabilities detected by AI analysis. Human verification advised for critical code.
Ticket Compliance
🎫 No ticket provided
  • Create ticket/issue
Codebase Duplication Compliance
Codebase context is not defined

Follow the guide to enable codebase context checks.

Custom Compliance
🟢
Generic: Meaningful Naming and Self-Documenting Code

Objective: Ensure all identifiers clearly express their purpose and intent, making code
self-documenting

Status: Passed

Learn more about managing compliance generic rules or creating your own custom rules

Generic: Secure Error Handling

Objective: To prevent the leakage of sensitive system information through error messages while
providing sufficient detail for internal debugging.

Status: Passed

Learn more about managing compliance generic rules or creating your own custom rules

Generic: Secure Logging Practices

Objective: To ensure logs are useful for debugging and auditing without exposing sensitive
information like PII, PHI, or cardholder data.

Status: Passed

Learn more about managing compliance generic rules or creating your own custom rules

Generic: Security-First Input Validation and Data Handling

Objective: Ensure all data inputs are validated, sanitized, and handled securely to prevent
vulnerabilities

Status: Passed

Learn more about managing compliance generic rules or creating your own custom rules

Generic: Comprehensive Audit Trails

Objective: To create a detailed and reliable record of critical system actions for security analysis
and compliance.

Status:
No auditing: The new full page screenshot action is introduced without any explicit audit logging,
though this SDK code may rely on higher-level logging not shown in the diff.

Referred Code
def full_screenshot
  execute :full_page_screenshot
end

Learn more about managing compliance generic rules or creating your own custom rules

Generic: Robust Error Handling and Edge Case Management

Objective: Ensure comprehensive error handling that provides meaningful context and graceful
degradation

Status:
Missing handling: The new full_screenshot command delegates directly to execute without explicit error
handling or edge case management, which may be acceptable if execute handles errors
centrally.

Referred Code
def full_screenshot
  execute :full_page_screenshot
end

Learn more about managing compliance generic rules or creating your own custom rules

  • Update
Compliance status legend 🟢 - Fully Compliant
🟡 - Partial Compliant
🔴 - Not Compliant
⚪ - Requires Further Human Verification
🏷️ - Compliance label

@qodo-code-review
Copy link
Contributor

qodo-code-review bot commented Dec 12, 2025

PR Code Suggestions ✨

Explore these optional code suggestions:

CategorySuggestion                                                                                                                                    Impact
General
Verify screenshot file was created
Suggestion Impact:The commit added assertions checking File.exist?(path) and File.size(path).to be_positive around the screenshot save operation, aligning with the suggestion.

code diff:

             expect(File.exist?(path)).to be true
             expect(File.size(path)).to be_positive

Add assertions to the save_screenshot test to verify that the screenshot file is
created on disk and has a size greater than zero.

rb/spec/integration/selenium/webdriver/chrome/driver_spec.rb [94-98]

 path = "#{Dir.tmpdir}/test#{SecureRandom.urlsafe_base64}.png"
 screenshot = driver.save_screenshot(path, full_page: true)
+
+expect(File.exist?(path)).to be true
+expect(File.size(path)).to be_positive
 
 _width, height = png_size(screenshot)
 expect(height).to be > viewport_height

[Suggestion processed]

Suggestion importance[1-10]: 6

__

Why: The suggestion correctly identifies an omission in the new test case; it fails to verify that save_screenshot actually creates a file, which is a primary function of the method being tested.

Low
  • Update

@cgoldberg
Copy link
Member

interesting... has Chrome always supported this? The reason in #14116 that this was Firefox-only was that Chrome didn't provide this endpoint.

If this now works, I'm going to add the same thing in the Python bindings.

@cgoldberg
Copy link
Member

@jspanjers Edge browser inherits this same functionality and it probably works there also. Can you add the same test for that?

@cgoldberg cgoldberg changed the title [rb] add support for Chrome full page screenshot [rb] Add support for full page screenshots in Chrome and Edge Dec 14, 2025
width, height = png_size(screenshot)

expect(width).to be >= viewport_width
expect(width).to be <= viewport_width
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why this change?

@cgoldberg
Copy link
Member

@jspanjers can you check the failed screenshot tests in CI?

@titusfortner
Copy link
Member

Firstly, thank you for tracking down the implementation details for this and submitting a code fix.

The problem with the screenshot endpoint in Chrome (and Edge) is that it is not w3c compliant. It must be namespaced correctly for us to implement it. I requested it be updated by them several years ago and they declined - https://issues.chromium.org/issues/42322971

Also, the log endpoint is no longer supported, so we can't add that back, either.

We hope to have a better future-compatible implementation for this soon using the w3c WebDriver BiDi specification.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants