Getting JS runtime error ONLY when debugging in VS 2010 - javascript

For some reason when I am trying to debug my site in VS I get the error
JavaScript runtime error: Unable to set property 'value' of undefined
or null reference
when using a date picker. I can hit continue and everything works perfectly fine. If I run the site without debugging everything works fine, the exact same code running in production works fine so why is VS complaining about this only when I debug?
function SetDate(formName, id, newDate, postBack) {
var theform = document.getElementById(formName);
popUp.close();
theform.elements[id].value = newDate;
if (id = "txtDate3") {
theform.elements['txtDate4'].value = newDate
}
if (postBack) __doPostBack(id, '');
}

if (id = "txtDate3")
assignment is improper here, use conditional
if (id == "txtDate3")
or
if (id === "txtDate3")

Related

Why do I have an error "TypeError: Cannot read properties of null (reading 'getTracks')", but the code is working?

Here is my code :
const videoElem = document.getElementById("videoScan");
var stream = document.getElementById("videoScan").srcObject;
var tracks = stream.getTracks();
tracks.forEach(function (track) {
track.stop();
});
videoElem.srcObject = null;
I am trying to stop all camera streams in order to make ZXing work. However, I have the following error (only on android tablet) :
Problem is, I can't solve it, but everything is working well. And when I do a try/catch, code stops working. I can't figure out why this error is displaying.
When you say "everything is working well", you mean that you get what you want as output?
If the code throwing the error is the same you are showing us, then it means that streams contains null.
Since streams is a const value (thus once only) assigned on the previous instructions, it means that document.getElementById("videoScan").srcObject is null too.
I'd suggest you to do some other debug by, i.e., printing out to JS console (if you have access to it from your Android debug environment, I'm sure there's a way) what's inside stream, before trying to access its getTracks method reference.
Please do also check the compatibility with srcObject with your Android (browser?) environment: MDN has a compatibility list you can inspect.
The simplest way to catch this null reference error, is to check if tracks actually exists.
const videoElem = document.getElementById("videoScan");
const stream = videoElem.srcObject;
if (stream && stream?.getTracks()) {
const tracks = stream.getTracks();
tracks.forEach(function (track) {
track.stop();
});
} else {
console.warn('Stream object is not available');
}
videoElem.srcObject = null;
So I found the solution. The error stopped the code from continuing, which, in my case, actually made it work. I made a very basic mistake : not paying enough attention to the debug results. However, if anyone has the error "Uncaught (in promise) DOMException: Could not start video source" with ZXing on Android, you simply have to cut all video streams to allow chrome starting an other camera. It will not work otherwise.

Firebase TypeError: Cannot read property 'ac' of undefined

I use this simple code to authenticate on my web app
firebase.auth().signInWithCustomToken(token).catch(function(error) {
// Handle Errors here.
var errorCode = error.code;
var errorMessage = error.message;
// ...
});
After authentication I get the following error in my browser: 'Firebase TypeError: Cannot read property 'ac' of undefined' which seems to point to an error here:
h.set = function(a, b, c) {
var d = this.aa(a, c)
, e = this
, f = Si(this, a.B);
return f.set(d, b).then(function() {
return f.get(d)
}).then(function(b) {
"local" != a.B || this.ac || (e.W[d] = b);
})
}
;
I'm compiling my es6 code using rollup and buble. Also please note that on the server response it looks like I'm successfully authenticating.
Because I got the following response:
{
"kind": "identitytoolkit#VerifyCustomTokenResponse",
"idToken": "token",
"refreshToken": "refreshtoken",
"expiresIn": "3600"
}
Please help. Thanks.
I believe this is related to: https://github.com/firebase/firebase-js-sdk/issues/121
How to stop babel from transpiling 'this' to 'undefined'
Quoting: "The thing that is causing you trouble is that in an ES6 module, this is undefined, whereas in the "script" case, this varies depending on the environment, like window in a browser script or exports in CommonJS code."
#bojeil I actually tried your suggestion and even changed my whole transpiler from buble to babel, just to get it going. Same result.
In the end, an update from v4.2.0 to v4.3.0 was release just 13 hours before this was posted and fixed the issue.
So to whomever have the same issue, updating firebase.

FireFoxDriver JavaScript errors does not show in FireFox browser

I'm using the following code to capture JavaScript errors when running Selenium tests:
public static void AssertNoJavaScriptErrorsInLog(this RemoteWebDriver driver)
{
var errorStrings = new List<string> { "SyntaxError", "EvalError", "ReferenceError", "RangeError", "TypeError", "URIError" };
var jsErrors = driver.Manage().Logs.GetLog(LogType.Browser).Where(x => errorStrings.Any(e => x.Message.Contains(e))).ToList();
if (jsErrors.Any())
{
Assert.Fail("JavaScript error(s):" + Environment.NewLine + jsErrors.Aggregate("", (s, entry) => s + entry.Message + Environment.NewLine));
}
}
One of my tests intermittently reports an error:
Assert.Fail failed. JavaScript error(s):
TypeError: doc.documentElement is null
TypeError: doc.documentElement is null
Trying to locate the error I look in the console of the FireFox browser which just ran the failed tests, but it's empty!
Why can't I see the JavaScript error in the browser console?
You might be experiencing the following fresh selenium issue:
Some new browser logs are not captured
As a workaround, consider downgrading selenium to 2.52.
Also, from time to time there are compatibility issues between selenium and firefox with a wide range of symptoms - play around with firefox versions (you can download older versions here) and see if you still cannot catch the js error on the console.

Chrome extension console.log override

I'm building a chrome extension that reads the console log and find where an ip appears, after the string "Connecting to", and gets the ip.
store = [];
var oldf = console.log;
console.log = function(){
store.push(arguments);
oldf.apply(console, arguments);
};
pos = 0
server = ""
setTimeout(function(){
for(i = 0; i < store.length; i++){
if(store[i][0].indexOf("Connecting to") != -1){
pos = i
}
}
var goal = store[pos][0].split(" ")[self.length-1];
server = goal
console.log(server);
}, 3000);
I have tried this code with Tampermonkey and works ok, but as chrome extension it doesn't work.The override for the console.log function works right so it might be something about permissions with the chrome extension. Is my first so I don't know much about. I get Uncaught TypeError: Cannot read property '0' of undefined If you need anything else just tell me
The reason is because Tampermonkey injects code into a site's document, whereas in Chrome Extension no, if you do this, you edit Chrome extension's console. To do this, you should use a method to inject the script, you can see here

JavaScript Chrome does not seem to support adding an id through setAttributeNode

So I am working on a JavaScript searcher for my website, and It's been up for a few days, when I realized that it is not compatible with Chrome, so i checked a few other browsers and realized it works in Firefox and IE9, but does not work in Chrome or Safari.
I've been pouring over the debugger in Chrome and Firefox side by side for hours, and cannot for the life of me figure out what the problem is. It keeps giving me an error. I know exactly what the error means, and why it is giving me the error, but I cannot figure out what is causing it.
This is the error: Uncaught TypeError: Cannot set property 'innerHTML' of null
I know it means that there is no object with that Id, but I set an object to have that Id right before. In Firefox's debugger at that line of code it says that the Id has been set, but at the same line in Chrome's debugger it says it has not.
Here is an excerpt of the code:
arrayFinal[arrayln2]="end";
var displayNumber=0;
while(arrayFinal[displayNumber].charAt(0) != "e"){
var boxPath="camper_htmls/"+arrayFinal[displayNumber]+".txt";
boxhttp = new XMLHttpRequest();
boxhttp.open("GET",boxPath,false);
boxhttp.send(null);
var boxHTML = boxhttp.responseText;
var setDivId=document.createAttribute("Id");
setDivId.value=("div_"+displayNumber);
var node = document.createElement("div");
node.setAttributeNode(setDivId);
document.getElementById("resultContainer").appendChild(node);
var divIdNumber = ("div_"+displayNumber);
document.getElementById(divIdNumber).innerHTML=boxHTML;
displayNumber++;
}
although a version of this code is being used on almost every page of the site, and none of them work.
Use id instead of Id as in
var setDivId=document.createAttribute("id");
DEMO

Categories