React-snap: Conflict with cookie script

Created on 26 Mar 2018  路  7Comments  路  Source: stereobooster/react-snap

I'm using a cookie script at work that appears to be conflicting with react-snap. The script contains proprietary code and I'm not allowed to paste it publicly, is there any way I can discuss this with you on email or some other private means? Thanks.

question

Most helpful comment

Full example

<link rel="stylesheet" type="text/css" src="css/cookieconsent.min.css" />
<script src="js/cookieconsent.min.js"></script>
<script>
var isReactSnap = navigator.userAgent === 'ReactSnap';
if (!isReactSnap) {
  window.cookieconsent.initialise({
    container: document.getElementById("content"),
    palette:{
      popup: {background: "#fff"},
      button: {background: "#aa0000"},
    },
    revokable:true,
    onStatusChange: function(status) {
      console.log(this.hasConsented() ?
        'enable cookies' : 'disable cookies');
    },
    law: {
      regionalLaw: false,
    },
    location: true,
  });
}
</script>

All 7 comments

You can write me to my nickname at gmail dot com. The first question I will ask what you try to do? You should treat react-snap as web crawler, so it should not interact with cookies in any way. You can disable user specific code by sniffing user agent.

I will close this as not actionable

@lewisdonovan We've come across the same problem - what was the solution in your case?

We have a cookie consent warning that pops up and uses localStorage to determine whether to show. With react-snap, the cookie warning shows but the DOM content of the warning is replaced with some other DOM content from the app!

You mean this one https://cookieconsent.insites.com/? You should detect if the client is react-snap, if it is you should not trigger popup.

const isReactSnap = navigator.userAgent === 'ReactSnap';

Full example

<link rel="stylesheet" type="text/css" src="css/cookieconsent.min.css" />
<script src="js/cookieconsent.min.js"></script>
<script>
var isReactSnap = navigator.userAgent === 'ReactSnap';
if (!isReactSnap) {
  window.cookieconsent.initialise({
    container: document.getElementById("content"),
    palette:{
      popup: {background: "#fff"},
      button: {background: "#aa0000"},
    },
    revokable:true,
    onStatusChange: function(status) {
      console.log(this.hasConsented() ?
        'enable cookies' : 'disable cookies');
    },
    law: {
      regionalLaw: false,
    },
    location: true,
  });
}
</script>

I was facing the same issue with cookieconsent (the notice would appear but not close) and the example above fixed it.

Confirmed working in lifecycle methods too:

componentWillMount() {
    var isReactSnap = navigator.userAgent === 'ReactSnap'
    if (!isReactSnap) {
      //cookie function here
    }
  }
Was this page helpful?
0 / 5 - 0 ratings

Related issues

rohan-deshpande picture rohan-deshpande  路  5Comments

philipeatela picture philipeatela  路  3Comments

stereobooster picture stereobooster  路  6Comments

loganpowell picture loganpowell  路  9Comments

goras picture goras  路  5Comments