Skip to content

Commit 7dedcad

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 26c979a commit 7dedcad

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
@@ -484,6 +484,16 @@ function replaceTrackingElement (widget, trackingElement, placeholderElement) {
484484
]
485485
elementToReplace.style.setProperty('display', 'none', 'important')
486486

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

0 commit comments

Comments
 (0)