Console Errors
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.
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.
For Browsing the code of susi chromebot, Click here
Posted on Utopian.io - Rewarding Open Source Contributors