简体   繁体   中英

Converting a Firefox add-on to scratchpad format

Debugging Firefox add-on in scratchpad returns some errors in following cases:

  1. Using require
  2. Defining some GUI such as icons, buttons and etc.
  3. Interacting with another pages (ie content scripts)
  4. (Possibility some other cases)

Consider the following example which Get Cursor Position :

Components.utils.import("resource://gre/modules/ctypes.jsm");
var lib = ctypes.open("user32.dll");

/* note: if you go to GetCursorPos page on MSDN, it says first argument is of structure POINT, so lets create that structure,
 * the link here shows that that x and y are type Long which is ctypes.long
 */
// https://msdn.microsoft.com/en-us/library/windows/desktop/dd162805%28v=vs.85%29.aspx
var POINT = new ctypes.StructType("tagPOINT", [
  { "x": ctypes.long },
  { "y": ctypes.long }
]);

/* Declare the signature of the function we are going to call */
var GetCursorPos = lib.declare('GetCursorPos',
    ctypes.winapi_abi,
    ctypes.bool,
    POINT.ptr
);

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

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

lib.close();

Any helps to editing and completing the question with better examples or something else, would be appreciated.

For SDK addons I would recommend using jpm watchpost + extension auto installer instead.

That will automatically create an xpi and reinstall it in your browser every time you save a file. Simply keeping the browser console open will get you any potential error outputs.

Interacting with another pages (ie content scripts)

The browser toolbox's scratchpad can select the target environment in which it is executed

Using require

In chrome contexts require can be imported via let { require } = Cu.import("resource://gre/modules/commonjs/toolkit/require.js")

If you use the addon debugger I think the addon's require should be available

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM