diff --git a/CHANGELOG.md b/CHANGELOG.md index f4d046b..7b89db7 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [Unreleased] +### Fixed + +- Fixed initialization of the original plugin when a page is too small and DOM is already loaded before an event `window.addEventListener('load', ...)` is attached. + ## [0.3.0] - 2021-12-28 ### Added diff --git a/package.json b/package.json index f590386..d0d1fc1 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "68publishers-cookie-consent", - "version": "0.3.0", + "version": "0.3.1-beta.0", "description": "Cookie consent wrapper based on orestbida/cookieconsent with GTM integration.", "homepage": "http://www.68publishers.io/", "main": "index.js", diff --git a/src/CookieConsentWrapper.js b/src/CookieConsentWrapper.js index 50d845d..663468b 100644 --- a/src/CookieConsentWrapper.js +++ b/src/CookieConsentWrapper.js @@ -109,7 +109,7 @@ class CookieConsentWrapper { } } - window.addEventListener('load', function () { + const windowLoadedCallback = function () { // init cookie consent self._cookieConsent = initCookieConsent(); const consentManager = new ConsentManager(self._cookieConsent, self._storagePool, Object.values(self._eventTriggers), self._gtag); @@ -138,7 +138,13 @@ class CookieConsentWrapper { } self._eventBus.dispatch(Events.ON_INIT, self); - }); + }; + + if ('complete' === document.readyState) { + windowLoadedCallback(); + } else { + window.addEventListener('load', windowLoadedCallback); + } this._initialized = true; }