简体   繁体   English

将Firefox附加组件转换为便签本格式

[英]Converting a Firefox add-on to scratchpad format

Debugging Firefox add-on in scratchpad returns some errors in following cases: 在以下情况下,在暂存器中调试Firefox加载项会返回一些错误:

  1. Using require 使用要求
  2. Defining some GUI such as icons, buttons and etc. 定义一些GUI,例如图标,按钮等。
  3. Interacting with another pages (ie content scripts) 与其他页面进行交互(即内容脚本)
  4. (Possibility some other cases) (可能还有其他情况)

Consider the following example which Get Cursor Position : 考虑以下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. 对于SDK插件,我建议您改用jpm watchpost + extension自动安装程序

That will automatically create an xpi and reinstall it in your browser every time you save a file. 每次保存文件时,这将自动创建一个xpi并将其重新安装在浏览器中。 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") 在chrome上下文中,可以通过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 如果您使用插件调试器,我认为插件的要求应该可用

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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