sandstorm / Sandstorm.CookiePunch

Neos Package for content-first consent management built on top of klaro.js.
MIT License
5 stars 3 forks source link

Script is never unblocked #3

Closed mgrundkoetter closed 3 years ago

mgrundkoetter commented 3 years ago

We use the NEOS package "WebExcess.OpenStreetMap" on the website (just an example). Integration as in their readme. Now we added the CookiePunch (also as in readme) and use this config:

Sandstorm:
  CookiePunch:
    consent:
      privacyPolicyUrl: "/de/meta/datenschutz"
      storageMethod: cookie
      cookieName: cookie_punch
      cookieExpiresAfterDays: 30
      mustConsent: true
      acceptAll: true
      hideDeclineAll: false
      default: false
    purposes:
      mediaembeds: "Einbindung von externen Medien"
    groups:
      default:
        title: "notwendige Cookies"
        description: "Speichert Ihre Cookie-Auswahl, sowie weitere technisch notwendige Einstellungen."
        consent:
          required: true
      media:
        title: "externen Medien"
        purposes:
          - mediaembeds
        description: "Videos von YouTube oder Vimeo, Kartendaten von OpenStreetMaps."
        consent:
          default: false
    elements:
      patterns:
        "Packages/Neos.Neos":
          type: script
          block: false
          group: default
        "Packages/Networkteam.Neos.MailObfuscator":
          type: script
          block: false
          group: default
        "https://www.youtube.com/embed/":
          type: iframe
          block: true
          group: media
        "Packages/WebExcess.OpenStreetMap":
          type: script
          block: true
          group: media
        "openstreetmap.org":
          type: script
          block: true
          group: media

The cookie banner is shown as expected, everything looks fine. All the "default" scripts also appear as normal in the html source code. The problem is, that even after activating the "media" group (with or without reloading the page), the Main.js file still remains blocked:

<script data-src="https://xyz.local/_Resources/Static/Packages/WebExcess.OpenStreetMap/Assets/Main.js" data-name="media">

Am I missing something in the configuration? I can't get the "unblock" step to work :-( What am I doing wrong?

fheinze commented 3 years ago

Unblocking is done by Klaro Consent Manager. Are there any JS-Errors in the console?

Could you run the following command in the inspector and check if the value changes when switching between "on" and "off" for the media group in the consent modal.

window.klaro.getManager().getConsent("media")

You can easily open the modal with

window.klaro.show()
mgrundkoetter commented 3 years ago

The result, if I accepted all the groups is:

window.klaro.getManager().getConsent("media")
true

This is also correct in the UI dialogue. There are no errors in the JS console. The Element Browser shows this html if I did not accept:

<script data-src="https://xyz.local/_Resources/Static/Packages/WebExcess.OpenStreetMap/Assets/Main.js" data-name="media" type="text/plain" id="" async="" style=""></script>

and after I accepted it looks like this:

<script data-src="https://xyz.local/_Resources/Static/Packages/WebExcess.OpenStreetMap/Assets/Main.js" data-name="media" type="undefined" id="" async="" src="https://xyz.local/_Resources/Static/Packages/WebExcess.OpenStreetMap/Assets/Main.js" style=""></script>

The Main.js is never loaded, says the network tab, no matter what I chose in the klaro dialogue.

fheinze commented 3 years ago

I was able to reproduce this bug. Klaro seems to look for a corresponding data attribute to "repair" the tags.

<script data-src="index.js" data-type="application/javascript" type="text/plain"></script>

Can be repaired as Klaro can recover the original type.

<script data-src="index.js" type="text/plain"></script>

This fails and will lead to this markup

<script data-src="index.js" type="undefined"></script>

Because it cannot recover the original type.

This needs to be fixed in CookiePunch. It seems that Klaro adds the type="text/plain" and then fails, because there is nothing to recover the original value from.