Skip to content
Merged
Show file tree
Hide file tree
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
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [Unreleased]
### Fixed
- The widget is now not displayed inside iframes if the iframe is displayed on the same origin as the main window. This prevents the widget from being displayed multiple times.
- The widget will wait for the `DOMContentLoaded` event to occur if `document.body` does not yet exist.

## [1.4.0] - 2025-06-17
### Added
Expand Down
2 changes: 1 addition & 1 deletion src/CookieConsentWrapper.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -379,7 +379,7 @@ export class CookieConsentWrapper {

let initPromise = null;

if (!this._config.pluginOptions.init_after_dom_content_loaded) {
if (!this._config.pluginOptions.init_after_dom_content_loaded && document.body) {
initPromise = doInitCookieConsent();
}

Expand Down
17 changes: 16 additions & 1 deletion src/CookieConsentWrapperFactory.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,26 @@ export class CookieConsentWrapperFactory {
},
}

cookieConsentWrapper.init(window, document);
if (this.#shouldInit()) {
cookieConsentWrapper.init(window, document);
}


return cookieConsentWrapper;
}

#shouldInit() {
try {
if (window.self === window.top) {
return true;
}

return !window.top.location.hostname;
} catch (e) { // eslint-disable-line no-unused-vars
return true;
}
}

#createGtagFunction() {
let gtag = window.gtag;

Expand Down