3
我想使用Firefox來閱讀SSH橫幅。即。當您最初連接到SSH服務器時,服務器向您發送其橫幅,標識服務器軟件,並向SSH服務器發送您的橫幅,以識別您的客戶端軟件。nsisocketTransportService使用Firefox插件sdk
要做到這一點我使用的例子,在這個網址:
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!");
};
ie。我使組件組件(小寫)和Components.interfaces只是接口。但後來我在控制檯上得到這個錯誤:
var transport = components.classes["@mozilla.org/network/socket-transport-service;1"]
ReferenceError: components is not defined
任何想法?