Problem/Motivation

With multiple tabs open at the same time, when the cookie compliance is accepted on one tab, the other isn't aware of the cookie state change and keeps wiping all cookies until the page is reloaded or the specific tab closed.

This is particularly annoying when you have multiple tabs already open, and need to start a new xdebug session on one, you end up having to hunt down the tab which is clearing the cookies.

Proposed resolution

clearInterval(euCookieComplianceBlockCookies); is only called when the accept action is triggered.

The var euCookieComplianceBlockCookies = setInterval(function () { call should check if the cookie has been accepted before blocking the cookies, if it's been accepted, then the interval check should be cancelled from there.

User interface changes

N/A

API changes

N/A

Comments

codebymikey created an issue. See original summary.

svenryen’s picture

Nice catch. Are you interested in making a patch?

codebymikey’s picture

Status: Active » Needs review
StatusFileSize
new918 bytes

Attached was my initial patch which addressed my specific use case with regards to canceling the interval.

It's not perfect since it doesn't do the rest of the logic which Drupal.eu_cookie_compliance.acceptAction typically does such as calling euCookieComplianceLoadScripts or Drupal.eu_cookie_compliance.loadCategoryScripts.

But I didn't want to duplicate or refactor the code since I wasn't currently using those options and wasn't sure about the nuance of potentially loading scripts across multiple background tabs - which would be a change in behaviour over what it's been doing for years now. Open to feedback if that's an acceptable change in behaviour, I personally think it's probably fine to load them in the background.

I removed the var in the var euCookieComplianceBlockCookies declaration because it was already declared at the top of the script.

  • svenryen committed 77ff117 on 8.x-1.x authored by codebymikey
    Issue #3143538 by codebymikey, svenryen: Cookies are always wiped when...
svenryen’s picture

Status: Needs review » Fixed

Thanks for the patch. If somebody still needs the acceptAction and loadCategoryScripts, hopefully they will open a new issue.

codebymikey’s picture

Thanks for merging it, one thing I noticed after reviewing my submitted patch logic was the lack of a return; statement. Meaning that the code clears the interval callback, but might still end up wiping the current cookies one final time.

The bug is not apparent unless a third party cookie is quickly set in between intervals - which is pretty rare, but should still be addressed nonetheless.

I meant to raise the issue/resubmit the patch after I heard your opinion on the euCookieComplianceLoadScripts issue, but given the time that's gone between then and now, it fell through the cracks.

svenryen’s picture

I see. Should I revert your patch, or will you make a new one based on the current -dev? You can open a follow-up issue if you want.

codebymikey’s picture

I think you can keep it in, the patch is still functional, and definitely better than the old behaviour. Just thought I'd make you aware of the race condition issue that can occur.

I'm not currently working today, so will try to reopen a issue for it or just update the patch here when I next work with eu_cookie_compliance.

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.

svenryen’s picture

@codebymikey - The issue was automatically closed. Do we want to reopen it, or how do you propose we proceed?

codebymikey’s picture

#3130015: Write & document public JS API for actions & events introduced a change or
regression in behaviour of the Drupal.eu_cookie_compliance.hasAgreed function.

I'm not sure if this was intentional, but this means that the hasAgreed call no longer reads off the cookies, but
instead on a local variable state (which can only be updated when the user clicks the relevant button).

I've rerolled the patch introducing a new Drupal.eu_cookie_compliance.getCookieStatus function which aims to read the cookie value without
necessarily updating the _euccCurrentStatus variable to work around this change in behaviour.

But it'll need further thought from you and other maintainers with regards to the best way to handle this going forward.

svenryen’s picture

Status: Closed (fixed) » Needs review

Status: Needs review » Needs work
svenryen’s picture

Assigned: Unassigned » svenryen
Status: Needs work » Needs review

  • svenryen committed 7c7fc2e on 8.x-1.x
    Issue #3143538 by codebymikey, svenryen: Cookies are always wiped when...
svenryen’s picture

Assigned: svenryen » Unassigned
Status: Needs review » Fixed

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.