Skip to content
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

cy.screenshot is not capturing canvas element on Chrome #30775

Open
KrzGruszcz opened this issue Dec 17, 2024 · 1 comment
Open

cy.screenshot is not capturing canvas element on Chrome #30775

KrzGruszcz opened this issue Dec 17, 2024 · 1 comment

Comments

@KrzGruszcz
Copy link

Current behavior

I'm running a test where a canvas screenshot is taken.
A screenshot is saved as a result. But the resulting file image is different for different browsers:

  • Chrome v131
    canvas_chrome

  • Electron v118
    canvas_electron

Desired behavior

Canvas graphics should be saved when running tests on Chrome.

Test code to reproduce

it('canvas screenshot', () => {
  Cypress.on('uncaught:exception', () => {
    return false;
  });

  cy.visit('https://www.mapbox.com/maps');
  cy.get('.mapboxgl-canvas').last().wait(5000).screenshot('canvas');
});

Cypress Version

13.16.1

Node version

v22.12.0

Operating System

cypress/factory:5.1.1 image

Debug Logs

No response

Other

No response

@jennifer-shehane
Copy link
Member

jennifer-shehane commented Dec 17, 2024

Hmm, I am able to recreate this in run mode, which uses the headless Chrome browser.

Running via cypress open does not result in an empty canvas in the screenshot and running cypress run --browser chrome --headed also does not result in an empty canvas.

I wanted to rule out the possibility that the canvas was not being rendered in headless mode, so I did record the run (where Test Replay is recorded) and the Test Replay displayed the canvas properly while the screenshot is blank. So this means the problem is with the screenshot somehow.

Test Replay

Screenshot 2024-12-17 at 9 46 43 AM

Screenshot in same test
Screenshot 2024-12-17 at 9 45 34 AM

It's strange that someone wouldn't have reported this before though, so I'm not sure it's a widespread issue with canvas. I know customers that do use screenshots for canvas since it's difficult to test the contents of.

I don't have a solution atm. Test Replay might be nice to use though since it accurately portrays the canvas, but that depends on your use case.

@jennifer-shehane jennifer-shehane changed the title cy.screenshot is not printing graphics on Chrome cy.screenshot is not capturing canvas element on Chrome Dec 17, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants