Search code examples
javascriptconfigurationcookieconsent

Klaro configuration, there is a way to disable the 'auto script execution' after giving the consent?


I'm using Klaro to manage consent: https://klaro.org/docs/getting-started.

There are some scripts in the configuration that are loaded at runtime. These scripts are defined within the Klaro configuration variable and can be allowed or blocked based on user consent.

If you accept these scripts, they should be executed. However, this doesn't happen. When inspecting the HTML code, the script tags are still marked as type="text/plain" instead of being converted into actual scripts, as Klaro does with the scripts that are initially present on the page.

This occurs because the new scripts are loaded after Klaro's initial processing, and Klaro doesn't re-check or manipulate these newly added scripts.

I believe the solution could be to disable Klaro's automatic manipulation of the HTML page immediately after cookies are accepted or declined, and instead trigger it manually after all the necessary scripts are loaded. I couldn't find any feature for this in the documentation.

Calling consents = consents.concat(script_config); executes the manipulation, but this causes the re-execution of the scripts already in the page at the first time. So I would like to trigger this manually just once.

Can you help me find this feature?

I tried to check documentation on their website: https://klaro.org/docs/getting-started
even on the Releases page, some features are documented only there: https://klaro.org/docs/releases
I checked GitHub issues: https://github.com/klaro-org/klaro-js/issues?q=disable


Solution

  • Inside the klaro config object I'm setting the option to noAutoLoad=true. Triggering klaro.getManager(klaroConfig).saveConsents(); on window 'onload' event works. Of course I also call klaro.setup(klaroConfig); before, but it doesn't load thanks to the setting "noAutoLoad".