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

[Bug]: autoDetect with value 'document' is not working #607

Closed
jackdeguest opened this issue Dec 15, 2023 · 4 comments
Closed

[Bug]: autoDetect with value 'document' is not working #607

jackdeguest opened this issue Dec 15, 2023 · 4 comments
Labels
enhancement New feature or request
Milestone

Comments

@jackdeguest
Copy link

Expected Behavior

I would expect cookieconsent to take the language value from <html lang="ja-JP"> for example, as advertised, when the value of autoDetect is set to document

Current Behavior

I am using Firefox version 120.0.1 on a MacOS Ventura on a MacBook Pro M2.

When autoDetect is set to document, no cookies notification is displayed.

If I change the settings to browser, then the cookies notification is displayed, but in the browser language, not the user preferred language on the website.

Steps to reproduce

  1. Set your browser prime language to anything but English.
  2. Ensure the property autoDetect is set to document
  3. Create an HTML file, such as:
<!DOCTYPE html>
<html lang="en-GB">
    <head>
        <meta charset="utf-8" />
        <title>Cookies Consent</title>
        <link rel="stylesheet" href="https://cdn.jsdelivr.net/gh/orestbida/cookieconsent@v3.0.0-rc.17/dist/cookieconsent.css">
    </head>
    <body>
        <script type="module" src="cookieconsent-config.js"></script>
    </body>
</html>
  1. Load the page, of course using an http location.

Proposed fix or additional info.

No response

Version

v3.0.0-rc.17

On which browser do you see the issue?

Firefox

@jackdeguest jackdeguest added the bug Something isn't working label Dec 15, 2023
@github-actions github-actions bot added the triage yet to be reviewed label Dec 15, 2023
@orestbida orestbida removed the triage yet to be reviewed label Dec 15, 2023
@orestbida
Copy link
Owner

This works just fine on my end, can you post your configuration?

@jackdeguest
Copy link
Author

jackdeguest commented Dec 15, 2023

Sure, here it is below. Here the value is set to browser, because otherwise it would not work:

import 'https://cdn.jsdelivr.net/gh/orestbida/cookieconsent@v3.0.0-rc.17/dist/cookieconsent.umd.js';

CookieConsent.run({
    root: '#wrapper',
    cookie: {
        name: 'ai_gdpr',
        domain: ( window.DOMAIN_NAME || window.location.hostname ),
        path: '/',
        expiresAfterDays: function(acceptType)
        {
            return( acceptType === 'all' ? 400 : 182 );
        },
        sameSite: 'Lax',
    },
    onFirstConsent: function(cookie)
    {
        // todo
    },
    onConsent: function(cookie)
    {
    },
    onChange: function(cookie, changedCategories, changedPreferences)
    {
        // todo
    },
    onModalShow: function(modalName)
    {
    },
    onModalHide: function(modalName)
    {
        // todo
    },
    onModalReady: function(modalName, modal)
    {
        // todo
    },
    guiOptions: {
        consentModal: {
            layout: "cloud inline",
            position: "bottom right",
            equalWeightButtons: true,
            flipButtons: false
        },
        preferencesModal: {
            layout: "box",
            position: "right",
            equalWeightButtons: true,
            flipButtons: false
        }
    },
    categories: {
        necessary: {
            readOnly: true
        },
        functionality: {
            enabled: true,
            readOnly: false,
        },
        analytics: {
            enabled: true,
            readOnly: false,
            autoClear: {
                cookies: [
                    {
                        name: /^(_ga)/      // regex
                        // path: string
                        // domain: string
                    },
                    {
                        name: '_gid'        // string
                    }
                ]
            },
            services: {
                ga: {
                    label: 'Google Analytics',
                    onAccept: function()
                    {
                        // enable ga
                    },
                    onReject: function()
                    {
                        // disable ga
                    },
                    cookies: [
                        {
                            name: /^(_ga|_gid)/
                        }
                    ]
                },
            },
        },
        marketing: {
            enabled: true,
            readOnly: false,
        }
    },
    language: {
        default: "en",
        autoDetect: "browser",
        translations: {
            "en-GB": "/public/cookieconsent-en_GB.json",
            "fr-FR": "/public/cookieconsent-fr_FR.json",
            "ja-JP": "/public/cookieconsent-ja_JP.json",
        }
    }
});

@jackdeguest
Copy link
Author

Ok, I could pinpoint the root cause, which was a comma at the end of a line as last property of an hash in the JSON file. In the JavaScript configuration file, it is permissible, but not under JSON.

You can close it. Although I think it would be helpful if your software could log a warning or an error in the console if upon parsing the JSON data an error is caught.

@orestbida
Copy link
Owner

You're right, it would be better to throw a visible error in the console since I also have encountered this issue.

@orestbida orestbida added enhancement New feature or request and removed bug Something isn't working labels Dec 16, 2023
@orestbida orestbida modified the milestones: v3.0.0-rc.17, v3.0.0 Dec 16, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants