Really-Simple-Plugins / complianz-gdpr

Complianz Privacy Suite (GDPR/CCPA)
https://complianz.io
Other
90 stars 39 forks source link

JavaScript error probably caused by Prototype.JS #411

Closed tomnoir closed 6 months ago

tomnoir commented 6 months ago

We have an issue on some pages with Complianz 7.0.7 premium.

It seems like that on all pages that use Prototype.JS, there is a JS error in the cmplz_set_category_as_body_class function, preventing the banner from being shown. It iterates over the cookie categories and tries to add these as classes to the body tag. Yet it seems, that in this case it not only iterates over the array of strings, but also over built-in methods of the JS array (like the .each-function), which the errors in trying to add them to the classes list of the body tag.

If you could add a check to cmplz_set_category_as_body_class whether the current element in the iterator is a string, this would probably solve the problem.

image image

Best, Thomas

rlankhorst commented 6 months ago

@tomnoir Thanks for reporting the issue. In regular foreach loops I always add a .hasOwnproperty check, which catches this kind of stuff, but in this case your solution works fine. I have created a branch in premium and free. We'll include it in the next update. In the meantime, you can copy over the complianz.min.js and complianz.js files from cookiebanner/js in this branch from the free plugin:

https://github.com/Really-Simple-Plugins/complianz-gdpr/tree/fix-non-string-in-set_category_as_body_class

Let me know if this resolves your issue!

tomnoir commented 6 months ago

@rlankhorst Yes, this fixes it and the banner works. Thank you for the quick reply and fix!

rlankhorst commented 6 months ago

@tomnoir great, thanks for confirming! I'll close this issue, it will get merged in one of the coming releases.