What is the best way to trace event propagation in Chrome? [closed] - javascript

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 7 years ago.
Improve this question
Suppose an application has a chat module containing messages. There is a jQuery click handler on said chat module that fires a series of focus related events whenever it detects a click.
Now suppose that when certain messages within the chat module are clicked, the event never bubbles up and a click event is never activated on the chat module.
How would I troubleshoot such an issue? I have a theory that somewhere in the application an intermediate element between the message click handler and the chat module click handler which is capturing the event and calling e.stopPropagation on it. There is currently no tools in Chrome to trace event propagation though.
What is the best way to trace event propagation in Chrome?

Override jQuery.Event.prototype.stopPropagation with a function containing a debugger statement:
jQuery.Event.prototype.stopPropagation = function() {
debugger;
};
From there perform the user actions that will fire the stopPropagation event; this time however a the debugger statement will cause the JavaScript to pause execution and you can observe the stack trace to see where it is being called from.

Put an ever-loving crap-ton of console logs everywhere. Not the most elegant solution, but it allows me to see what information is getting passed and where any and all hiccups are.
console.log(var);

I may suggest you to open the Chrome console (F12) go to elements, select the element of your interest and with right mouse click set the subtree modification.

Related

Single firing click event listener [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question does not appear to be about programming within the scope defined in the help center.
Closed 2 years ago.
Improve this question
I am currently building a JavaScript tool that takes in an address and runs it through a series of functions that outputs a Boolean value of whether the address is within a range of addresses. From this output the tool will dynamically add cards to the page based on the output. My problem at the moment is that if the event listener is clicked more than once it just continues to add the cards to the page. Is there an event listener that will take in a click event but only fire the first time the event is triggered? If not am I better off just writing a function to remove the click event once it has been fired? I am more than happy to include the code from the project but seemed unnecessary.
addEventListener has an option to listen for an event only once:
const button = document.querySelector("button");
button.addEventListener("click", onClick, {
once: true
});
function onClick() {
window.alert("Clicked!");
}
<button>Try clicking me twice</button>
This option is supported in all major browsers except for Internet Explorer (which has been discontinued)

Which event is triggered first on form save button [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 3 years ago.
Improve this question
When you click "save" on a form , 2 jquery events I know get triggered. Actually I was using both but just today I realised one is enough :) . But still let's say you define both, which one would be triggered first. $("#btnSaveForm").click() or $("#btnSaveForm").submit()
What I also noticed as soon as a click handler is triggered, the GUI basically freezes as long as this click handler is completely executed(Even if there is a ajax call done inside the handler). But still the GUI remembers what you did and executes the clicks afterwards.
The order of which things are executed is as follows :
User clicks the submit button
The onclick function is executed
The browser submits the page to the url specified in the action of
the form
As you can see in this example, the button triggers first and the form triggers right after.
Maybe you are using sync ajax handler if you are experiencing Frozen GUI after submitting your form.

Clicking an element in a page and see the related JavaScript code(s) [duplicate]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 7 years ago.
Improve this question
This seems to be impossible with the typical "inspect element" approach, which seems great for HTML and CSS, but that's it. I can't go to a particular element and then link to the particular JavaScript that's controlling it. Is there any way to do this?
As someone else said, there is no precise notion of "the JS controlling an element". There is JS which does something to an element, and there is JS which handles an event on a element. To handle these cases:
In Chrome devtools, select the element, right-click, and select Break on.... This will break when something happens to the element, such as a change in its children or its attributes, and leave you on the line that was making the modification.
Use "Event Listener Breakpoints" and choose to break on a particular event. Then initiate that event on an element which is listening for it, such as by clicking on the element. The debugger will take you to the line handling that event (which might be deep within jQuery, but that's another story).

What is the major difference between Event and EventHandler? [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 9 years ago.
Improve this question
The reason behind of posting this question is to understand the basic differences and use cases of the Event and EvenHandler.
Event:- In computing, an event is an action or occurrence detected by the program that may be handled by the program. Typically events are handled synchronously with the program flow, that is, the program has one or more dedicated places where events are handled.
EventHandler:-
A function or method containing program statements that are executed in response to an event. An event handler typically is a software routine that processes actions such as keystrokes and mouse movements. With Web sites, event handlers make Web content dynamic. JavaScript is a common method of scripting event handlers for Web content.
Very basic example is you click on login button on facebook, there is corresponding event handler for click on login button which tells facebook app that user trying to login
You cannot compare the both Handler and event.
All Handlers are stored with a HandlerManager which also manages dispatching any type of event (including new ones you create yourself).
More over
Handlers are passed an Event object with all the Event details as their only parameter i.e Event
They may mean different things, depending on a specific context. A general meaning of an event is a an action or occurrence somewhere in the program; normally events are handled by the program in modules called handlers.
For example in Java you may an event triggered by the push of a button; what the program does when that button is call the code in the handler for that particular event.

JavaScript remove unknown listener [closed]

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 7 years ago.
Improve this question
I have my own page where I load an external third-party JavaScript that analyzes my DOM. The problem I am facing is as follows. I install some event listeners ('keypress', 'input', 'click') but after I append mentioned script (and she performs some computation), some of my listeners are not working any more. To be precise, 'click' listener is intercepting click events as expected, but other two are not intercepting anything. Is there a way for that external script to interfere with my listeners?
Btw., I am setting useCapture to true when installing my listeners, like this:
document.addEventListener('input', function...., true);
...
I don't have any other code to provide you with.
P.S. I am not able to play with the external code since it is obfuscated.
P.P.S. Installing the handlers again did not help.
It is possible, although quite unlikely, that the third-party code is capturing the event(s) before and and stopping it propagating (e.stopPropagation()). This would require the code attaching a listener to the same event on a parent element in the capturing phase.
Without more code to see, particularly this third-party code, it's hard to find the actual problem.

Categories