Skip to content
GitLab
  • Menu
Projects Groups Snippets
  • Help
    • Help
    • Support
    • Community forum
    • Submit feedback
    • Contribute to GitLab
  • Sign in / Register
  • S sg_cookie_optin
  • Project information
    • Project information
    • Activity
    • Labels
    • Members
  • Repository
    • Repository
    • Files
    • Commits
    • Branches
    • Tags
    • Contributors
    • Graph
    • Compare
  • Issues 17
    • Issues 17
    • List
    • Boards
    • Service Desk
    • Milestones
  • Merge requests 0
    • Merge requests 0
  • Deployments
    • Deployments
    • Releases
  • Monitor
    • Monitor
    • Incidents
  • Analytics
    • Analytics
    • Value stream
    • Repository
  • Activity
  • Graph
  • Create a new issue
  • Commits
  • Issue Boards
Collapse sidebar
  • TYPO3
  • sg_cookie_optin
  • Issues
  • #187
Closed
Open
Created Oct 08, 2021 by Henrik@henrik.ahrens

JavaScript-Error on pages with added array methods

Hi, on a page with extended Array-Prototype (a "each"-method is added to arrays) i got an JS-Error when accepting anything else than all cookies. I already had this error a few weeks ago after i added a filter-method to arrays, but there i was able to remove that code and thought this error was too specific to report. Here i'm not able to remove the method because the JS code that adds the .each is inaccessible to me.

Uncaught TypeError: documentCookies[documentCookieIndex].split is not a function
    at Object.deleteCookiesForUnsetGroups (cookieOptin.js:619)
    at Object.setCookieWrapper (cookieOptin.js:1635)
    at Object.acceptEssentialCookies (cookieOptin.js:1030)
    at HTMLButtonElement.<anonymous> (cookieOptin.js:696)

This error occurs only on the first click on the button (private window or first page view). After the click and a page reload, the Consent window is not displayed until I delete the LocalStorage items.

I solved the problem by adding an isNaN/parseInt check to the two For loops (the same error also occurs two lines above with the cookieIndex):

        deleteCookiesForUnsetGroups: function() {
                for (var groupIndex in SgCookieOptin.jsonData.cookieGroups) {
                        if (!SgCookieOptin.jsonData.cookieGroups.hasOwnProperty(groupIndex)) {
                                continue;
                        }
                        var documentCookies = document.cookie.split('; ');
                        if (!SgCookieOptin.checkIsGroupAccepted(SgCookieOptin.jsonData.cookieGroups[groupIndex].groupName)) {
                                for (var cookieIndex in SgCookieOptin.jsonData.cookieGroups[groupIndex].cookieData) {
                                        if (isNaN(parseInt(cookieIndex))) continue;
                                        for (var documentCookieIndex in documentCookies) {
                                                if (isNaN(parseInt(documentCookieIndex))) continue;
                                                var cookieName = documentCookies[documentCookieIndex].split('=')[0];
                                                var regExString = SgCookieOptin.jsonData.cookieGroups[groupIndex].cookieData[cookieIndex]
                                                        .Name.trim();

                                                if (!regExString) {
                                                        continue;
                                                }

                                                var regEx = new RegExp(regExString);
                                                if (regEx.test(cookieName)) {
                                                        // delete the cookie
                                                        document.cookie = cookieName + '=; path=/; Max-Age=-99999999;';
                                                }
                                        }
                                }
                        }
                }
        },
Assignee
Assign to
Time tracking