Greasemonkey - need to simulate mouse click, I think

Scorpion Ghost

Elite Member
Executive VIP
Jr. VIP
Joined
Mar 22, 2013
Messages
8,676
Reaction score
10,228
I have a weird problem. I'm using Firefox. There's a website I visit sometimes and I click a button whenever it appears. The button normally opens in a popup, but I have set Firefox to open all popups as tabs.

This particular button, when I start the browser and I do one click manually, then as long as the browser stays open my Greasemonkey script can click the button whenever it appears and it works fine.

Here is what I use now:

JavaScript:
document.elementFromPoint(900, 421).click();

But if I open the browser and I don't do a click manually, when Greasemonkey does the click I get this in Firefox:

Firefox prevented this site from opening a pop-up window

I have the option to add the site to the whitelist/exceptions, and then popups will be allowed and it will always work. But I can't do that because this creates a new problem for me.

The new problem is that sometimes this website sort of "autoclicks" this button on its own, and when it does, and the site is added to whitelist/exceptions, the browser automatically redirects me to that other tab (like focusing a popup I guess). But I don't want this. I want to stay on the first tab always. I tried finding a way to prevent Firefox from allowing automatic tab switches, to make it load popups in background, but nothing works.

The code on the website for this button is this:

Code:
<a class="bla_ble_blue asd3-wer" onclick="openWinPopupTimeNetw(123, 'yadayada==', 'rty-dfg', '654dhfdfh8', '9', '15', ma na ta ra', 'dsf6845ASD84!@$dfg56');"><span>&nbsp;</span><div class="lala">tra sta</div></a>

I think the problem is that it's an "onclick" event thing, and Firefox handles it weirdly. Not like the usual buttons I'm used to automating clicks for anyway :D

So I'm thinking the solution is either some sort of Firefox edit, or a Greasemonkey click that stimulates a mouse click for real (some fancy ajax/jquery/black magic, not my noob methods).

Any ideas? @TomTheCat @Gogol
 
I tried this extension, and again - Firefox prevented this site from opening a pop-up window

But I restart the browser, I go to the page, I click with my mouse, and poof it opens normally (and from that point on Greasemonkey and other scripts can open it normally too, for as long as the browser stays open)
 
So after my usual genocide on my time, I think I found a solution. Workaround-ish type thing.

This:

JavaScript:
    setInterval(function() {
       
window.focus();
     
        }, 4000);

So I know you guys don't understand this higher level professional coding stuffs, so let me explain.

What this code does is it focuses the tab on which Greasemonkey is active. So now I get to enable (whitelist, add to exception) pop-ups for this website, and then my original script that does the clicks will always work.

And what will happen is, wheneve Firefox moves to another tab for whatever reason, after 5 seconds this script here will bring the focus back to the first tab.

So whenever I need to switch to this browser and do what I need to do, I will be looking at the first tab.

This will allow me to not waste any time switching from tab 2 to tab 1 over and over again, or having to remember to disable Greasemonkey each time I open the browser, do 1 click on the button manually, and then enable Greasemonkey again.


It's still not perfect, because sometimes I open another page on these browsers in a new tab, and now Greasemonkey will keep stealing focus taking it back to tab 1. But I'll just have to remember to disable GM when I do the other stuff, or just do my other stuff over the page where the window.focus happens, and when I'm done continue with the clicking and focusing.

Yeah, I'm no @Gogol or @TomTheCat over here haha, so it ain't perfect, but it's done and it's a solution I can live with (unless somebody has a superior solution, I'm all ears) :p

Ok now I have to actually test this in action, and shit happens sometimes. But I am a pro, so what could go wrong... :D
 
I absolutely love these threads where you post a problem, continue tinkering with things and then figure out a solution all on your own.

Cheers man!
 
I absolutely love these threads where you post a problem, continue tinkering with things and then figure out a solution all on your own.

Cheers man!

Yeah bro, you know that I am professional :D

9dc0619765ffaf19bec4b68594dc9ff8--tech-support-help-desk.jpg


I never ask here and just leave it at that. I keep trying to fix it myself. And if someone out of the kindness of their heart pops in and helps me out, great. If not, I'll figure something out, eventually, probably, hopefully :o :p

Anyway things seem to be working with what I did. All is as expected. I increased the Interval to 20000 (20 seconds). I never need to switch to tab 1 before that anyway, and it will give me a little more time with no obstructions (automatic switching of tabs) whenever I need to switch to one of these browsers and do some other stuff.
 
JavaScript:
document.getElementsByClassName('bla_ble_blue asd3-wer').click();

I tried that bro, it didn't work.

I mean, it does work, the click does happen, but the browser blocks the tab from opening because popup.

It seems only a click with the mouse allows me to open the tab, the first time after starting a browser. After I do the manual click, I can have Greasemonkey clicking the button.

But my solution gets around it anyway. I added the website to the whitelist for popups in the browser, and I have Greasemonkey focusing back tab 1 every 20 seconds. Works fine, it's good :)
 
Back
Top