Mohit Sharma avatar

Removing all console errors

ms10398

Published: 29 Dec 2017 › Updated: 29 Dec 2017Removing all console errors

Removing all console errors

Console Errors

image.png

Susi is a personal assistant developed by FOSSASIA. It has many clients including web chat, andoid and iOS app, and many chatbots.
Now we are developing a chrome extension for it which is named as chromebot.

There were many errors in console.
ss1.png

The errors were-

Uncaught TypeError: Cannot read property 'addEventListener` of null at allowmic.js :5
Failed to load resource: net:: ERR_FILE_NOT_FOUND

Following the stack trace of the first error I found out that two elements were present on login page and was only present in DOM when the login page gets opened.

And the allowmic.js was necessary to be included in the main extension window.

So for figuring out the solution I put all the event listeners in a if clause

if(micAccess) {
    micAccess.addEventListener("click", () => {
        navigator.webkitGetUserMedia({
            audio: true
        }, function (stream) {
            stream.stop();
        }, function () {
            console.log("no access");
        });
    });
}
if(preDefThemes) {
preDefThemes.addEventListener("click",(e) => {
    if(e.target!==e.currentTarget){
        theme= e.target.id;
        console.log(theme);
    }
    e.stopPropagation;
    });
}
if(submit) {
    submit.addEventListener("click",()=>{
         localStorage.setItem("theme",theme);
         console.log("success");
         alert("success");
    });
}
if(backgroundChange) {
    backgroundChange.addEventListener("submit", (e) => {
        e.preventDefault();
        theValue = backUrl.value;
        if (!theValue) {
            alert("Error: No value specified");
        } else {
            localStorage.setItem("theValue", theValue);
            alert("Successfully stored");
        }
    });
}

Which solved my first issue of errors due to Uncaught TypeError.
Second Error was due to there was a custom background variable which was used in setting custom background which was only set when user chose a custom background.
So I put it as optional.

Then the console was free of errors.
ss.png

For Browsing the code of susi chromebot, Click here



Posted on Utopian.io - Rewarding Open Source Contributors

Leave Removing all console errors to:

Written by

Full Stack Web Developer | Utopian Community Manager

Read more #utopian-io posts


Best Posts From Mohit Sharma

We have not curated any of ms10398's posts yet. But you can encourage our curation team to review posts by visiting them regularly and by referring other readers. Because we give priority to frequently read content.

More Posts From Mohit Sharma