Skip to content

Workaround declarativeNetRequest element collapsing bug #452

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

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions src/features/click-to-load.js
Original file line number Diff line number Diff line change
Expand Up @@ -485,6 +485,16 @@ function replaceTrackingElement (widget, trackingElement, placeholderElement) {
]
elementToReplace.style.setProperty('display', 'none', 'important')

// When iframes are blocked by the declarativeNetRequest API, they are
// collapsed (hidden) automatically. Unfortunately however, there's a bug
// that stops them from being uncollapsed (shown again) if they are removed
// from the DOM after they are collapsed. As a workaround, have the iframe
// load a benign data URI, so that it's uncollapsed, before removing it from
// the DOM. See https://crbug.com/1428971
const originalSrc = elementToReplace.src
elementToReplace.src =
'data:text/plain;charset=utf-8;base64,' + btoa('https://crbug.com/1428971')

// Add the placeholder element to the page.
elementToReplace.parentElement.insertBefore(
placeholderElement, elementToReplace
Expand All @@ -504,6 +514,7 @@ function replaceTrackingElement (widget, trackingElement, placeholderElement) {
// placeholder) can finally be removed from the DOM.
elementToReplace.remove()
elementToReplace.style.setProperty('display', ...originalDisplay)
elementToReplace.src = originalSrc
})
}

Expand Down