orestbida / cookieconsent

:cookie: Simple cross-browser cookie-consent plugin written in vanilla js
https://playground.cookieconsent.orestbida.com/
MIT License
3.87k stars 406 forks source link

[Bug]: The selection is empty if prototype framework is used #727

Closed claudiuj closed 1 week ago

claudiuj commented 2 weeks ago

Expected Behavior

I know that Prototype is an old framework but it is still used by Magento 1.9.

Current Behavior

When I use cookieconsent with Prototype (the latest version), the selection saved in the cookie is empty (the categories array is empty)

Steps to reproduce

  1. Create a config file using GUI interface

  2. Create a simple HTML file that includes Prototype framework (I've attached a screenshot of the source

    Screenshot 2024-09-01 at 22 15 42

    )

  3. Run HTML file in browser

  4. Set cookie preference

  5. Check the cookie value (categories array)

Proposed fix or additional info.

No response

Version

3.0.1

On which browser do you see the issue?

No response

orestbida commented 1 week ago

@claudiuj, this is due to prototype modifying the standard Array.from function, see https://github.com/prototypejs/prototype/issues/338.

You can restore the default Array.from as suggested in https://github.com/prototypejs/prototype/issues/362:

<script>
  const iframe = document.body.appendChild(
    document.createElement('iframe')
  );
  const iframeArray = iframe.contentWindow.Array;
  document.body.removeChild(iframe);
  Array.from = iframeArray.from;
</script>

<script type="module" src="cookieconsent-config.js"></script>

This might break other things in your page though.

claudiuj commented 1 week ago

it is working;

Thank you.