gpt4 book ai didi

javascript - nsISocketTransportService 使用 Firefox 插件 sdk

转载 作者:塔克拉玛干 更新时间:2023-11-02 21:57:27 25 4
gpt4 key购买 nike

我正在尝试使用 Firefox 阅读 SSH 横幅。 IE。当您最初连接到 SSH 服务器时,服务器会向您发送它的横幅,识别服务器软件,然后您向 SSH 服务器发送您的横幅,识别您的客户端软件。

为此,我使用了此 URL 中的示例:

Is there nsiClientSocket in firefox extension javascript?

这是我的代码:

'use strict';

const {Cc,Ci} = require("chrome")
const prefs = require("simple-prefs");


exports.main = function(options,callbacks) {
var transport = Components.classes["@mozilla.org/network/socket-transport-service;1"]
.getService(Components.interfaces.nsISocketTransportService)
.createTransport(null, 0, "localhost", 22, null);

//var output = transport.openOutputStream(0, 0, 0);
var input = transport.openInputStream(0, 0, 0);
var data = "test";
dump(stream.read());
//stream.write(data, data.length);
//stream.close();
dump("all done!");
};

当我用它执行 cfx xpi 时,我得到了这个:

The following lines from file C:\path\to\lib\main.js:
8: var transport = Components.classes["@mozilla.org/network/socket-transport-service;1"]
9: .getService(Components.interfaces.nsISocketTransportService) use 'Components' to access chrome authority. To do so, you need to add a line somewhat like the following:

const {Cc,Ci} = require("chrome");

Then you can use any shortcuts to its properties that you import from the 'chrome' module ('Cc', 'Ci', 'Cm', 'Cr', and 'Cu' for the 'classes', 'interfaces', 'manager', 'results', and 'utils' properties, respectively. And `components` for `Components` object itself).

所以我改用这个:

'use strict';

const {Cc,Ci} = require("chrome")
const prefs = require("simple-prefs");


exports.main = function(options,callbacks) {
var transport = components.classes["@mozilla.org/network/socket-transport-service;1"]
.getService(interfaces.nsISocketTransportService)
.createTransport(null, 0, "localhost", 22, null);

//var output = transport.openOutputStream(0, 0, 0);
var input = transport.openInputStream(0, 0, 0);
var data = "test";
dump(stream.read());
//stream.write(data, data.length);
//stream.close();
dump("all done!");
};

即。我使 Components 组件(小写)和 Components.interfaces 只是接口(interface)。但后来我在控制台上收到此错误:

    var transport = components.classes["@mozilla.org/network/socket-transport-service;1"]
ReferenceError: components is not defined

有什么想法吗?

最佳答案

您应该使用 Cc 而不是 Components.classesCi 而不是 Components.interfaces - 这些是您从 chrome 模块导入的变量,它们已被定义。如果您需要使用 Components 对象本身(不太可能),您也可以导入它:

const {components, Cc, Ci} = require("chrome");

供引用:chrome authority

关于javascript - nsISocketTransportService 使用 Firefox 插件 sdk,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12558983/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com