How to debug JS calls [duplicate] - javascript

This question already has answers here:
JavaScript: Is there a way to get Chrome to break on all errors?
(5 answers)
Closed 6 years ago.
I'm trying to implement Metronic admin theme in my app, but when I click on a button, I get Empty string passed to getElementById(). and the buttons don't work.
I'm trying to track down which piece of code triggers this error. How can I find out where the problem is?

write debugger; right before the javascript code that you feel is troublesome. Also keep the inspect tools open (usually F12)
This will create a breakpoint in the code execution with which you can then debug your code and look for errors.

Related

window.open() doesn't open the website, what to do? [duplicate]

This question already has answers here:
How to open multiple webpages in separate tabs within a browser using selenium-webdriver and python
(1 answer)
What is the fastest way to open urls in new tabs via Selenium - Python?
(2 answers)
Closed 3 years ago.
I have this piece of code:
((JavascriptExecutor)driver).executeScript("Object.assign(document.createElement('a'), { target: '_blank', href: 'https://facebook.com'}).click()");
((JavascriptExecutor)driver).executeScript("window.open('https://google.com')'");
First command is meant to create a new tab and open facebook.com and it does, first is meant to open google.com but nothing happens, am I doing anything wrong?
Disclaimer:
1.I am not familiar with Javascript at all, this is a Java Selenium project (hence why the (JavascriptExecutor)driver).executeScript part and I need to use Javascript for these few lines.
2.I tried multiple simpler piece of codes instead of this one but nothing worked hence why I ended up with this which is not the simplest.
you have extra single quotation in your second line.
you should write ((JavascriptExecutor)driver).executeScript("window.open('https://google.com')");

Mixpanel error: "mixpanel" object not initialized [duplicate]

This question already has answers here:
mixpanel-2-latest.min.js:9 Mixpanel error: "mixpanel" object not initialized
(7 answers)
Closed 5 years ago.
I am getting the below error.
I am using Angular - I have not imported a mix panel library - if I do a search I cannot find this.
Why am I getting this error/how can get rid of it?
Mixpanel error: "mixpanel" object not initialized. Ensure you are
using the latest version of the Mixpanel JS Library along with the
snippet we provide.
If you are not using mixpanel in your code, you should check whether it is one of your extensions.
In my case it was the PageRuler extension and started happening only today.
Check your extensions, for me it was 'Page Ruler'
["https://chrome.google.com/webstore/detail/page-ruler/jlpkojjdgbllmedoapgfodplfhcbnbpn?hl=nl"] that caused this error.
Disable all extensions until the error does not occur anymore.

When we get Javascript errors in chrome console, which windows event will get fired [duplicate]

This question already has answers here:
How to get errors stack trace in Chrome extension content script?
(2 answers)
Access variables and functions defined in page context using a content script
(6 answers)
Closed 6 months ago.
I have a website, which is running fine. But sometimes due to some JS break we encounter some errors. In chrome console these errors are logged.
I want to capture these errors using Javascript and log them into file. I dont want to use chrome logging.
For this I have written a code for adding a eventhandler in js::
window.addEventListener('error', ChromeErrorCollector.onError, true);
where onError is the function handling functionality.
But when error occure in Js files this event dont fire.
Where Am I doing wrong??

javascript function in source code, but not 'not defined' [duplicate]

This question already has answers here:
Is it possible to load new Javascript files with AJAX?
(7 answers)
Closed 7 years ago.
Below, i have included a screenshot form the F12 view in chrome.
My problem is: Uncaught ReferenceError: callModal282876547 is not defined.
The other errors are not an issue.
I don't know if this is relevant, but the code that is shown was loaded into the page by an ajax call (including the javascript).
The error occurs when i click the button, and tells me the function is not defined, but it is clearly present in the code? What can cause this, and how would i solve this problem?
The browser doesn't know anything about the new function you brought with ajax response. So, you must eval() your declaration code returned by the Ajax callback and make it available to DOM.

How can i debug jquery object [duplicate]

This question already has an answer here:
Closed 10 years ago.
Possible Duplicate:
Debug Javascript
Every now and then i have one jquery object and i am not able to find whats inside it.
I had to try many combinations like see the class name , id and other attributes to see what is that variable and sometime by hiding it.
Is there any proper way of debugging the jquery object to see whats inside it?
Firebug, Internet Explorer Developer Toolbar, Chrome Developer Tools. These are some of the tools for some of the respective browsers.
Some IDES like eclipse let you debug inline.
Also there is a javascript statement : debugger;, which you can use for this purpose .
Using firebug or the chrome developer tools you can debug any javascript object.
You need to add a breakpoint just after the object initialization and then add the object to the watch panel.
Object members are displayed in a tree view.

Categories

Resources