Skip to content

Commit 63165ae

Browse files
committed
Workaround declarativeNetRequest element collapsing bug
There's a bug[1] with the declarativeNetRequest API that means that after blocked iframes are collapsed (hidden) they sometimes can't be uncollapsed (shown again) after they load successfully. That causes Click to Load to get messed up for Chrome MV3 builds of the extension, as the content is sometimes not shown to the user again after it has been unblocked. The bug is triggered when the collapsed iframe is removed from the DOM. As a workaround, let's load a benign data URI in blocked iframes before removing them from the DOM. That way they are uncollapsed, and so if they are added back to the page they will be visible to the user. 1 - https://crbug.com/1428971
1 parent 324b846 commit 63165ae

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

src/features/click-to-load.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -485,6 +485,16 @@ function replaceTrackingElement (widget, trackingElement, placeholderElement) {
485485
]
486486
elementToReplace.style.setProperty('display', 'none', 'important')
487487

488+
// When iframes are blocked by the declarativeNetRequest API, they are
489+
// collapsed (hidden) automatically. Unfortunately however, there's a bug
490+
// that stops them from being uncollapsed (shown again) if they are removed
491+
// from the DOM after they are collapsed. As a workaround, have the iframe
492+
// load a benign data URI, so that it's uncollapsed, before removing it from
493+
// the DOM. See https://crbug.com/1428971
494+
const originalSrc = elementToReplace.src
495+
elementToReplace.src =
496+
'data:text/plain;charset=utf-8;base64,' + btoa('https://crbug.com/1428971')
497+
488498
// Add the placeholder element to the page.
489499
elementToReplace.parentElement.insertBefore(
490500
placeholderElement, elementToReplace
@@ -504,6 +514,7 @@ function replaceTrackingElement (widget, trackingElement, placeholderElement) {
504514
// placeholder) can finally be removed from the DOM.
505515
elementToReplace.remove()
506516
elementToReplace.style.setProperty('display', ...originalDisplay)
517+
elementToReplace.src = originalSrc
507518
})
508519
}
509520

0 commit comments

Comments
 (0)