Task: I am opening chrome(with my extension installed) with selenium webdriver in python. I want to attach a listener when selenium opens the window of chrome.
Already Tried: I have already tried chrome.windows.onCreated event in background of my extension, but it is not firing.
I have done a work around of it. May be helpful for others aswell. First, chrome.windows.onCreated will fire only if a new window is created from current window. Since I wanted to run some logic when selenium creates a fresh window therefore I put the code in a myFunction and call that function directly in background page. As a fresh chrome is created by a code in background page executes once and calls myfunction.
Related
I'm web scraping in electron using puppeteer and whenever I encounter a download button with an onclick event triggering a 'downloadCourseDocs(....)' function, I emulate a click on it. This, in a normal browser opens a new tab for downloading that file.
In electron, I see that it opens a new blank, white window.
How do I prevent this/ hide the newly created window?
I tried playing around with the "browser-window-created" and "new-window-for-tab" events on the app and window instance but to no luck.
Thank you for your time.
In case someone is looking for an answer to this, here's how I fixed it:
window.webContents.on("did-create-window", (windowCreated) => windowCreated.hide());
You could probably also close the window.
I have some React app here that has a malfunction that causes the page to open a new tab with itself. Recursive. and that is rather annoying as the number of tabs runs quickly into an out of memory situation. I want to debug the code to see the stack when the window.open call happens. I do not know where in the application the call happens and so wonder if there is a way to trigger Chrome to jump into script debug mode when something wants to open a window/tab?
So you can use the debugger of chrome, and then add some breakpoint to exactly decide when the code should stop, and then you use the control to jump to the next execution and decide when to go a step back and forth.
it's available for free, all you need to do is to inspect your React app and then visit the Sources tab, there you will see the code in javascript and you can start adding breakpoint and so.
You can also add mouse event listener , like click , dbclick...
You can also trigger and debug how a specific function si running.
In my wordpress site, some hacker has embedded a script into it somewhere.
The problem I'm having now is, whenever the site is opened, the first time a user clicks anywhere on it, a spam popup appears, due to the hacker's script.
Is there any way I can prevent the popup window from being created with Javascript?
If I can't prevent it, is there any way that I can close the popup using JS? Unfortunately, since the other script is creating it, I don't have a reference to the opened window. I've seen other scripts calling .close() on an opened window, but I don't have a reference to the new window, so I don't know how to close it.
Here's my site.
The popup on your site is opened by something calling window.open. You can prevent it by assigning something else to window.open and running your script before the other script does:
window.open = () => undefined;
(This does work, if I run this code on your site before your site's Javascript runs, no windows get opened)
It's not uncommon for a client to want to implement this, but if you're the server, it'd be better to fix the server to remove the malicious code, rather than try to patch around it.
I wonder if it's possible to know which code is executed when I click on an element of the current web page in Firefox. The element does not show any [EV] pointer inside the web tool "Analyse page" panel, so I think that the event is managed in another way.
Is there a way to understand what function in what script is called?
I have a website with javascript and when I move my mouse on that website, there is function triggered. I need to debug whole javascript code step by step when it is executed. I need to find out which function is called (and parameters too).
How can I do this - what should I use for this?
Any real time debugger?
EDIT: Now I see it is script loaded from another url (my site is mydomain.tld, second script loads from seconddomain.tld). Second script is obfuscated/minimized and it control clicks on website (when clicked, it triggers one function).
Is it possible with javascript on my site to call function in that second script? If yes, how please.
Just put the command debugger anywhere and Chrome will stop there when it happens to pass that place by.
Don't forget to keep the debugger open by pressing F12
I need to find out which function is called
In console (Firebug, Developer tools, etc.) you can click Profile button or use commands:
console.profile();
//...
console.profileEnd();
And it will display what functions were called during the profiling.
Then you can use debugger; command inside the functions as everyone mentions.
If site uses jQuery then you can go to the function source with Chrome DevTools. Go to event listener sidebar in elements panel, expand interesting event and click the link to source.
E.g. input#new-todo has internal jQuery listener but DevTools has resolved it and show link to user defined function outside framework.
You can use Chrome for that. You can add breakpoint.
See the doc https://developer.chrome.com/devtools/docs/javascript-debugging
you can track mouse move event by
<script>
$(document).mousemove(function(event){console.log(event);});
</script>
and open console window in browser when mouse move it will display all things...