Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cookiebar unable to load parameters if another script with "cookiebar" in name is loaded (first) on the same page. #136

Closed
cemerson opened this issue Mar 13, 2023 · 2 comments
Labels

Comments

@cemerson
Copy link

cemerson commented Mar 13, 2023

Original Issue

I have two servers - both call cookiebar-latest.min.js using the same method w/the same parameters:

**Server 1 **

  • This seems to work fine - no issues.

**Server 2 **

  • This is where the odd parameter issue is happening.
  • Somehow when the cookiebar-lates.min.js loads all the parameters seem to be empty or something.
  • I did a console log tests (w/a local copy of the cookiebar js) to see what the parameters were coming up as - and they all show up as 'false' - screenshot below.

Console log check of what parameter values appear as on Server 2:
image

Solution

After bit more testing I figured this out - mostly my fault I guess.

Issue was that I had a custom JS file (w/internal logic scripts) also loading on the same page and it also had "cookiebar" in the filename. So when cookiebar-latest.min.js tried to pull the parameters from the script src attribute it pulled from my JS file instead of the actual cookiebar-latest.min.js file. Again I blame myself and will just rename my file but FYI in case you want to tighten the logic there or throw an error if multiples are found or something?

script 1: <script src="cookiebar-internal-logic.js"></script>
script 2: <script src="cookiebar-latest.min.js?refreshPage=1&tracking=1&remember=30&etc..."></script>

This is the line in cookiebar-latest.min.js that tries to get the parameters from the "src" line but grabs #1 above instead of #2.
if (e[i].hasAttribute("src") && (path = e[i].src, path.indexOf("cookiebar") > -1)){

Thank you again for making this handy plugin! 🙏🏻

@cemerson cemerson changed the title Cookiebar losing parameter values on Linux server but not .NET server? Cookiebar unable to load parameters if another script with "cookiebar" in name is loaded (first) on the same page. Mar 13, 2023
@ToX82
Copy link
Owner

ToX82 commented Mar 13, 2023

Well you are right, though!

That logic should be checking for the exact filename and not just "cookiebar", which could lead to some weird behaviors such as the one you saw.

I'm reopening this issue, if you could help me with a pull request I'll be more than happy to merge it, or I will do it myself in the next few days.

@ToX82 ToX82 reopened this Mar 13, 2023
@ToX82 ToX82 added the bug label Mar 13, 2023
cemerson added a commit to cemerson/cookie-bar that referenced this issue Mar 13, 2023
Changed line 351 from 'cookiebar' to 'cookiebar-latest'. May be a slicker way to deal w/it but this would resolve the issue I had.
(ToX82#136)
@cemerson
Copy link
Author

#137 Here's a quick stab at it - feel free to do something more elaborate. BTW I only updated the cookiebar-latest.js not the minified file (assume that's automated?)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants