I came across this question:
How to find out which JavaScript events fired?
But, that method of using Firebug will help me only if I log the events of a particular element right?
Here's my situation:
I want to analyze a webpage. It displays a list of headlines, and after you scroll down at the bottom of the page, something happens and then it fetches the next 20 headlines from the server and adds it back to the page. I would like to know exactly which event is fired and which function is called as this happens. How do I do that?
Use Chrome or Firefox Developer Tools and check under the networks tab.
For Firebug check console or scripts.
It shows you all the external files that have been used in your page.
Don't forget about
console.log("event fired");
Related
everyone.
I need to parse web page, that is result of search request. I write Python script. So I need to fake search button click. So here's my question:
How can I find what script is run when the button is clicked?
The button code is (as I found in page inspection in Chrome):
<div class="submit button" data-ember-action="2">Search</div>
I feel that I should read more. I'll be grateful for ideas what direction to dig for.
The second is who to get script output. But, perhaps, the answer for the first question will be the answer for both
You can use Google Chrome's Developer Tools/Inspector to set a breakpoint that listens for any click. Once you set that breakpoint, you can click the button in Google Chrome and get more insight.
Here is a link that can show you how to get to the Google Chrome Developer Tools/Inspector (AKA DevTools).
Once you have the DevTools open, Click on the Sources tab near the top, then expand the Event Listener Breakpoints accordion. Next, you can expand the Mouse accordion and activate the click event listener breakpoint by checking the box next to it.
After that, you can go back to the web page and click the button to stop the application in its tracks. From there you can use the debugger to step through the code and see more information about the application.
You will need to run the JS for that, not just read the page code.
So use something like Spalsh: https://splash.readthedocs.io/en/stable/ for javascript rendering. Then you can inspect the JS events more like you did in Chrome.
For a real Chrome inspection experience use headless Chrome: https://developers.google.com/web/updates/2017/04/headless-chrome
I want to analyze a website that is not mine.
So, I want to use Javascript to do it at my end in the browser.
After I click a button on the website I want to trigger a timer and as soon as a notification from the website comes back, the timer should stop and save the notification that came back.
How can I do this the easiest way?
I cannot give you the link to the website, because it's hosted in a private network.
My first question would be, how I can log all events that are triggered on a website to the console, so I know the name of the button I want to wait for.
Thanks!
dave
All events on a specific DOM node:
To see all the events for a specific DOMnode, or window (only works on chrome i believe, didnt test it elsewhere):
getEventListeners(window)
this will give you an object with all the events, then you can intercept them with
window.addEventListener(eventName, fn, true);
The whole application:
this way your event will be called whenever an event on that node is triggered (window in this case)
if you want absolutely all events on the whole app, you can achieve it with using something like firebug
Specific event on a specific element:
if you want a button click only, you can do the following:
var specificButton = document.querySelector('#specific-button')
specificButton.addEventListener('click', function() {});
Implementation:
if you do not own the sourcecode, you can use something like greasemonkey or tampermonkey to inject your javascript into the page.
if you are using it on a server, you can use cheerio to parse the returned html from the get request, and apply queries on it, but you will lose the ability for listening to live events from io devices.
If I understand you, the easiest option I see is to open your browser developer tools and using the console get the button (document.getElementById, i.e.) and change its onclick callback, including a call to the old callback in your new callback, and trigger your timer.
To intercept the response to this button (I assume that it triggers a network request), you'll have to analyze a bit the code of the web to see how you can detect it.
You could also edit the website javascript throught "Sources" tab of your browser's dev tools.
It's an idea. I have never done something like that. I have to admit that it sounds a little weird to me.
I'm trying to understand the code of a chrome extension I did not write. This extension is active the entire time and working in background. Now I'd like to see which functions are being called on the different actions I do on websites.
I got so far that I have to use the Debugging Console which I open with Ctrl+Shift+I, but how exactly do I have to do this?
I would try using the "Event Listener Breakpoints". You can get to it under the sources tab on the right hand side. Just expand desired section.
For example, if you want to track a click event on a button, expand Event Listener Breakpoints -> Expand Mouse -> Select 'click'. Upon clicking the button in the tool, it should stop in the code where the action is handled.
It is worth noting that the code will probably be minified, so reading it might not be trivial.
I am debugging a web application which redirects several times on page load. Page A redirects to page B, which redirects to page C. I don't know what methodology is used (e.g. JavaScript, HTTP redirects, etc.).
What I'm looking for is a debugger to break before a page gets redirected, so that I can inspect exactly what method is being used to redirect, and what data is being sent to next page in the redirect chain.
Is there a simple way to do that? I'm debugging on Windows, so Chrome, Firefox and IE are all available.
UPDATE: It seems that Fiddler is the best option available. I marked the answer from #cgatian as a solution, since his was the Fiddler idea.
In Chrome there is Event Listener Breakpoints -> Sript -> Script First Statement:
Pressing F8 will stop on first statement of any script in page, e.g :
<script type="text/javascript">document.location.href='http://www.example.com'</script>
Also, there is Event Listener Breakpoints -> Load -> beforeUnload but not works in my case.
Alright so it sounds that you want to actually look at variables inside the browser before the redirect occurs. One way I can think of (without modifying the source directly) is to use Google Chrome Snippets.
You could create you're own snippet that binds to the onbeforeunload event.
Step By Step Instructions on Creating a Snippet
Snippet code:
window.onbeforeunload = function(){
var debug;
return;
}
All I am doing in the above code is attaching an event before the browser would be redirected.
If you then place a break point inside your snippet you will be able to break and inspect the variables on the page. (Don't forget to right click your snippet and select Run) before debugging.
In chrome, in the debug window, at the very bottom, are a series of buttons. Click the button that is a dark black circle. It will preserve the log upon navigation. I think that is what you want.
I'm trying to reverse-engineer some JavaScript and, annoyingly, the JS isn't terribly clear or well-documented. I've got a series of events that are fired (using JQuery) that I need to find where the function lives.
Is there a way of configuring Firebug (or the Opera/IE consoles - not Chrome/Safari) so that I can see what events are fired when I click a button?
Thanks
In firebug, select console tab. Click on profile, do your activity on page, again click on profile...list of called function will be listed below in firebug panel.
I suggest that you get started with the "Using FireBug Console for Faster JavaScript Development" tutorial.
You could add a console.log() to every click method. Or simply add an Event listener to the document and console.log() some details or the event when something is clicked.
You can use the Firebug Profiler, e.g. by calling profile() in the console before your action and profileEnd() after the action. Firebug will then tell you which methods have been executed in the meantime (incl. lots of information about it).