Skip to content

Commit

Permalink
Don't serialize canvas elements with JS enabled
Browse files Browse the repository at this point in the history
  • Loading branch information
Robdel12 committed Mar 13, 2020
1 parent 77eb8e9 commit 503968d
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 3 deletions.
4 changes: 2 additions & 2 deletions src/percy-agent-client/dom.ts
Original file line number Diff line number Diff line change
Expand Up @@ -94,11 +94,11 @@ class DOM {
private stabilizeDOM(clonedDOM: HTMLDocument): HTMLElement {
this.serializeInputElements(clonedDOM)
this.serializeFrameElements(clonedDOM)
this.serializeCanvasElements(clonedDOM)

// We only want to serialize the CSSOM if JS isn't enabled.
// We only want to serialize the CSSOM or canvas if JS isn't enabled.
if (!this.options.enableJavaScript) {
this.serializeCSSOM(clonedDOM)
this.serializeCanvasElements(clonedDOM)
}

return clonedDOM.documentElement
Expand Down
15 changes: 14 additions & 1 deletion test/integration/agent-integration.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,20 @@ describe('Integration test', () => {
// I cannot think of a nicer way to let the canvas animations/drawing settle
// so sadly, use a timeout
await page.waitFor(1000)
await snapshot(page, 'Canvas elements')
const domSnapshot = await snapshot(page, 'Canvas elements')
const $ = cheerio.load(domSnapshot)

expect($('[data-percy-canvas-serialized]').length).to.equal(2)
})

it("doesn't serialize with JS enabled", async () => {
await page.goto(`http://localhost:${PORT}/serialize-canvas.html`)
await page.waitFor('#webgl canvas')
await page.waitFor(1000)
const domSnapshot = await snapshot(page, 'Canvas elements -- no JS', { enableJavaScript: true })
const $ = cheerio.load(domSnapshot)

expect($('[data-percy-canvas-serialized]').length).to.equal(0)
})
})
})
Expand Down

0 comments on commit 503968d

Please sign in to comment.