1

In my extension I get document of 1st tab:

var doc  = gBrowser.getBrowserForTab(gBrowser.tabs[0]).contentDocument;         

doc contains iframe pointing to foreign domain, how can I emulate click on image/object inside the iframe?

Actually, I want to implement a functionality of iMacros' X/Y click. How can I do it?

2 Answers 2

2

To simulate clicks within a flash object, you will probably have to use js-ctypes.

Find the element with javascript, get the elements screenX and screenY and then add the DOMWindow's screenX and screenY (the window maybe resized to smaller window and moved) and then call click with js-ctypes.

This is how to do it in windows:

Components.utils.import("resource://gre/modules/ctypes.jsm");
var lib = ctypes.open("user32.dll");
var struct_Point = new ctypes.StructType("Point", [
  {"x": ctypes.int},
  {"y": ctypes.int}
]);

var GetCursorPos = lib.declare('GetCursorPos',
    ctypes.winapi_abi,
    ctypes.bool,
    struct_Point.ptr
);

/* Use it like this */
var point = new struct_Point;
var ret = GetCursorPos(point.address());

Components.utils.reportError(ret);
Components.utils.reportError(point);

This page has how to do it in mac os and linux: https://developer.mozilla.org/en-US/docs/Mozilla/js-ctypes/Standard_OS_Libraries


/*start setcursorpos*/
var SetCursorPos = lib.declare('SetCursorPos', ctypes.winapi_abi, ctypes.bool, ctypes.int, ctypes.int)

function doSetCursorPos() {
    var ret = SetCursorPos(10, 10);
}
/*end setcursorpos*/

/*start mouse_event*/
var mouse_event = lib.declare('mouse_event', ctypes.winapi_abi, ctypes.void_t, ctypes.uint32_t, ctypes.uint32_t, ctypes.uint32_t, ctypes.uint32_t, ctypes.uintptr_t);
var MOUSEEVENTF_LEFTDOWN = 2;
var MOUSEEVENTF_LEFTUP = 4;

function domouse_event() {
    var ret = mouse_event(MOUSEEVENTF_LEFTDOWN, 0, 0, 0, 0);
    var ret = mouse_event(MOUSEEVENTF_LEFTUP, 0, 0, 0, 0);
}
/*end mouse_event*/

Then this is how to use it. I actually made this as an autoclicker on April 1st this year for stackoverflow. They had this flash game where you had o click like 70-120 times on a boulder to get unicorn points. I thought you could unlock topics that people locked of mine, but it turned out to be scam. But got some good ctypes out of it.

Use like this:

function clickXTimesWhereCursorIs(X, everyMs) {
        var point = new struct_lpPoint;
        var ret = GetCursorPos(point.address());
        Cu.reportError(ret);
        Cu.reportError(point);
    var ret = SetCursorPos(point.x, point.y);
    for (var i=0; i<X; i++) {
          setTimeout(function() {
       var ret = mouse_event(MOUSEEVENTF_LEFTDOWN, 0, 0, 0, 0);      
       var ret = mouse_event(MOUSEEVENTF_LEFTUP, 0, 0, 0, 0);
          }, i*everyMs);
    }
}

setTimeout(function() {
    clickXTimesWhereCursorIs(90, 100);
}, 3000)
Sign up to request clarification or add additional context in comments.

6 Comments

Yet not checked, but seems to be what I'm seeking! Thanks!
Actually I accidentally posted how to get the cursor position. I'll post how to do simulate click in a second.
Actually how soon do you need it? I have the code for this at home, you actually have to use SetCursor to set its position and then send_click. Can you wait like 3 hours?
Yes, surely, I think i can handle it by myself, but when you have time, please, post it, it will not be unnecessary!
I noticed you do a lot of python, are you good with ctypes? I actually needed help with some stuff :P If you are available could we chat sometime?
|
0

Just get a references to the element in question and call .click() on it.

E.g. something like this:

var elem = gBrowser.contentDocument.querySelector("a");
elem.click();

2 Comments

No, it's impossible: stackoverflow.com/questions/10947254/… The question, how can I take advantage of being an extension to simulate click on a flash object?
And if there are say, 20 different elements the user may want to click on? how do you know which element beforehand. Say the end-user is using the gameController api and an xbox remote, you can press buttons and they are registered, but do not generate a mouseclick event.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.