3

I need to simulate trusted mousemove event in JavaScript. As I read there:

http://help.dottoro.com/ljoljvsn.php

In Firefox, an event is trusted if it is invoked by the user and not trusted if it is invoked by script.

And after that I started search other solution. I found this:

Are events generated by Firefox extension 'trusted'?

Yes, events generated by extensions are always trusted.

So, now I want write FireFox extension to allow me create mousemove trusted event. Unfortunately, I've never written extensions FireFox, so I need to clarify some points. What I have:

  1. I downloaded example of XPI file
  2. I created install.rdf and bootstrap.js for bootstraped extension (like FireBug)

But now I don't understand:

  1. In this article: https://developer.mozilla.org/en-US/Add-ons/Code_snippets/Miscellaneous#Simulating_mouse_and_key_events

i see code:

var utils = window.QueryInterface(Components.interfaces.nsIInterfaceRequestor)
                      .getInterface(Components.interfaces.nsIDOMWindowUtils);
utils.sendMouseEvent("mousedown", 10, 10, 0, 1, 0); utils.sendMouseEvent("mouseup", 10, 10, 0, 1, 0);

what point in bootstrap.js I must insert this code? How I understand I must attach it in some active(or specified?) window.

  1. How can I can run extension code in my JavaScript like global object "console" in FireBug extension?

I would appreciate an explanation

Community
  • 1
  • 1
stepozer
  • 1,143
  • 1
  • 10
  • 22
  • You can put that in the startup of your bootstrap addon. It will run right away. You need to access a `window` because bootstrap scope has access to no window. You can access the most recent `navigator:browser` window (a window which has tabs) by toing `var window = Services.wm.getMostRecentWindow('navigator:browser')`. Make sure to import `Services.jsm` like this: `var {interfaces: Ci, utils: Cu} = Components; Cu.import('resource://gre/modules/Services.jsm');` – Noitidart Nov 19 '14 at 09:54
  • Thank you. I another question: how can i create global JS object in extension? Because when i try: var window = Services.wm.getMostRecentWindow('navigator:browser'); window.test = {}; I don't see it in my FF console. – stepozer Nov 19 '14 at 10:52
  • You can access bootstrap scope of addon from everywhere: http://stackoverflow.com/questions/22057888/controlling-a-firefox-extension-via-javascript/22099148#22099148 – Noitidart Nov 24 '14 at 18:21

0 Answers0