Store a userId in a local Chrome extension

52 Views Asked by At

I try to store locally a unique identifier to each of my users and this is what I do

const rand = function() {
    return Math.random().toString(36).substr(2); // remove `0.`
};

const getRandomToken = function() {
    return rand() + rand(); // to make it longer
};

window.chrome.storage.local.get('userId', (items) => {
    let userId = items.userId;
    
    if (userId === undefined) 
    {
        userId = getRandomToken();
        window.chrome.storage.local.set({userId: newId});//Line that causes an error message
    };
});

I put the right permission in the manifest I specify that I am on a minifest v3, I have an error that appears I do not understand why. It is this error : https://ibb.co/J7HzbH5 ; If you have a question or even another idea to be able to generate a random token, I am interested thank you in advance for your help.

0

There are 0 best solutions below