Error with extension after website update (Javascript)

  google-chrome-extension, javascript

I have a problem with my Chrome Extension. After the website has received an update, I get an error message.
This is the error message.

These are the updates of the website.

if (/^https://(lichess.org|lichess.dev|mskchess.ru)/(w{8}|w{12})(/white|/black)?$/.test(window.location.href)) {
    let nonce, src, text;
    const observer = new MutationObserver((mutations, observer) => {
        mutations.forEach((mutation) => {
            if (mutation.addedNodes[0] && mutation.addedNodes[0].tagName && mutation.addedNodes[0].tagName.toLowerCase() === 'script') {
                let script = mutation.addedNodes[0];
                if (script.src.indexOf('round') !== -1) {
                    src = script.src;
                    script.parentElement.removeChild(script)
                } else if (script.innerText.indexOf('lichess.load.then(()=>{LichessRound') !== -1) {
                    nonce = script.getAttribute('nonce');
                    text = script.innerText;
                    script.parentElement.removeChild(script)
                    observer.disconnect();
                    finishLoading();
                }
            }
        })
    });
    observer.observe(document.documentElement, { childList: true, subtree: true });

    const finishLoading = () => {
        Promise.all([src].map(u => fetch(u))).then(responses =>
            Promise.all(responses.map(res => res.text()))
        ).then(info => {
            let completed;
            let tIndex = info[0].search(/!w{1}.isT/);
            if (tIndex !== -1) {
                let dIndex = info[0].search(/.isT/);
                let numberOfLetters = dIndex - tIndex - 1;
                completed = info[0].replace(/!w.isTw{6}/, `(${info[0].substr(tIndex, numberOfLetters + 11)} && (!${info[0].substr(tIndex + 1, numberOfLetters)}.data || ${info[0].substr(tIndex + 1, numberOfLetters)}.data[5] !== '-'))`);
            } else {
                completed = info[0];
            }
            let firstOne = document.createElement('script');
            let secondOne = document.createElement('script');
            firstOne.innerHTML = `console.log(2);${completed}`;
            secondOne.innerHTML = `console.log(3);${text}`;
            firstOne.setAttribute('nonce', nonce)
            firstOne.setAttribute('defer', 'defer')
            secondOne.setAttribute('nonce', nonce)
            document.body.appendChild(firstOne);
            document.body.appendChild(secondOne);
            let windowScript = document.createElement('script');
            windowScript.setAttribute('nonce', nonce)
            windowScript.innerHTML = `(${innerContent.toString()})()`
            document.body.appendChild(windowScript);
        });
    }

}

This is the code where my debugger stops.

Source: Ask Javascript Questions

LEAVE A COMMENT