Removing all console errors

in #utopian-io7 years ago (edited)

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

Sort:  

Thank you for the contribution. It has been approved.

Thank you for making the requested edits! They make the article a lot nicer to read on mobile.

You can contact us on Discord.
[utopian-moderator]

Your contribution cannot be approved yet. Could you please clean up the screenshots to remove the large white spaces that break up your article?

You may edit your post here, as shown below:

You can contact us on Discord.
[utopian-moderator]

Thanks I have made the suggested changes!
Submitted for reapproval

Hey @ms10398 I am @utopian-io. I have just upvoted you!

Achievements

  • You have less than 500 followers. Just gave you a gift to help you succeed!
  • Seems like you contribute quite often. AMAZING!

Community-Driven Witness!

I am the first and only Steem Community-Driven Witness. Participate on Discord. Lets GROW TOGETHER!

mooncryption-utopian-witness-gif

Up-vote this comment to grow my power and help Open Source contributions like this one. Want to chat? Join me on Discord https://discord.gg/Pc8HG9x

Coin Marketplace

STEEM 0.16
TRX 0.15
JST 0.028
BTC 54681.92
ETH 2286.50
USDT 1.00
SBD 2.29