Skip to content

Commit 83185ec

Browse files
authored
fix: Remove loading attributes from cloned iframes (#555)
This attribute causes asset discovery to hang and eventually timeout since we don't scroll the page. Removing the attribute is ideally what we want (to load the iframe).
1 parent 45b27ee commit 83185ec

File tree

2 files changed

+8
-1
lines changed

2 files changed

+8
-1
lines changed

src/percy-agent-client/dom.ts

+3-1
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,6 @@ class DOM {
169169
// rerendered and do not effect the visuals of a page
170170
if (clonedDOM.head.contains(cloned)) {
171171
cloned!.remove()
172-
173172
// if the frame document is accessible, we can serialize it
174173
} else if (frame.contentDocument) {
175174
// js is enabled and this frame was built with js, don't serialize it
@@ -188,6 +187,9 @@ class DOM {
188187
} else if (!enableJavaScript && builtWithJs) {
189188
cloned!.remove()
190189
}
190+
191+
// Remove any lazy loading attributes, since they hang asset discovery
192+
cloned!.removeAttribute('loading')
191193
}
192194
}
193195

test/unit/percy-agent-client/dom.test.ts

+5
Original file line numberDiff line numberDiff line change
@@ -336,6 +336,7 @@ describe('DOM -', () => {
336336
createExample(`
337337
<iframe id="frame-external" src="https://example.com"></iframe>
338338
<iframe id="frame-input" srcdoc="<input/>"></iframe>
339+
<iframe id="frame-lazy" srcdoc="<input/>" loading="lazy"></iframe>
339340
<iframe id="frame-js" src="javascript:void(
340341
this.document.body.innerHTML = '<p>made with js src</p>'
341342
)"></iframe>
@@ -386,6 +387,10 @@ describe('DOM -', () => {
386387
expect($dom('#frame-js-inject')).to.not.have.length
387388
})
388389

390+
it('removes loading attributes on iframes', () => {
391+
expect($dom('#frame-lazy').attr('loading')).to.be.undefined
392+
})
393+
389394
it('does not serialize iframes with CORS', () => {
390395
expect($dom('#frame-external').attr('src')).to.equal('https://example.com')
391396
expect($dom('#frame-external').attr('srcdoc')).to.be.undefined

0 commit comments

Comments
 (0)