web-ext 6.7.0 → 7.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +17 -8
- package/bin/web-ext.js +13 -0
- package/index.js +12 -0
- package/lib/cmd/build.js +226 -0
- package/lib/cmd/build.js.map +1 -0
- package/lib/cmd/docs.js +16 -0
- package/lib/cmd/docs.js.map +1 -0
- package/lib/cmd/index.js +47 -0
- package/lib/cmd/index.js.map +1 -0
- package/lib/cmd/lint.js +50 -0
- package/lib/cmd/lint.js.map +1 -0
- package/lib/cmd/run.js +199 -0
- package/lib/cmd/run.js.map +1 -0
- package/lib/cmd/sign.js +140 -0
- package/lib/cmd/sign.js.map +1 -0
- package/lib/config.js +144 -0
- package/lib/config.js.map +1 -0
- package/{src → lib}/errors.js +26 -35
- package/lib/errors.js.map +1 -0
- package/lib/extension-runners/base.js +2 -0
- package/lib/extension-runners/base.js.map +1 -0
- package/{src → lib}/extension-runners/chromium.js +121 -178
- package/lib/extension-runners/chromium.js.map +1 -0
- package/{src → lib}/extension-runners/firefox-android.js +168 -326
- package/lib/extension-runners/firefox-android.js.map +1 -0
- package/{src → lib}/extension-runners/firefox-desktop.js +73 -114
- package/lib/extension-runners/firefox-desktop.js.map +1 -0
- package/lib/extension-runners/index.js +311 -0
- package/lib/extension-runners/index.js.map +1 -0
- package/lib/firefox/index.js +362 -0
- package/lib/firefox/index.js.map +1 -0
- package/lib/firefox/package-identifiers.js +5 -0
- package/lib/firefox/package-identifiers.js.map +1 -0
- package/{src → lib}/firefox/preferences.js +27 -70
- package/lib/firefox/preferences.js.map +1 -0
- package/{src → lib}/firefox/rdp-client.js +98 -105
- package/lib/firefox/rdp-client.js.map +1 -0
- package/{src → lib}/firefox/remote.js +55 -129
- package/lib/firefox/remote.js.map +1 -0
- package/lib/main.js +9 -0
- package/lib/main.js.map +1 -0
- package/lib/program.js +663 -0
- package/lib/program.js.map +1 -0
- package/lib/util/adb.js +322 -0
- package/lib/util/adb.js.map +1 -0
- package/lib/util/artifacts.js +52 -0
- package/lib/util/artifacts.js.map +1 -0
- package/lib/util/desktop-notifier.js +27 -0
- package/lib/util/desktop-notifier.js.map +1 -0
- package/{src → lib}/util/file-exists.js +7 -14
- package/lib/util/file-exists.js.map +1 -0
- package/{src → lib}/util/file-filter.js +31 -59
- package/lib/util/file-filter.js.map +1 -0
- package/lib/util/is-directory.js +20 -0
- package/lib/util/is-directory.js.map +1 -0
- package/lib/util/logger.js +79 -0
- package/lib/util/logger.js.map +1 -0
- package/{src → lib}/util/manifest.js +18 -50
- package/lib/util/manifest.js.map +1 -0
- package/{src → lib}/util/promisify.js +6 -9
- package/lib/util/promisify.js.map +1 -0
- package/{src → lib}/util/stdin.js +3 -7
- package/lib/util/stdin.js.map +1 -0
- package/{src → lib}/util/temp-dir.js +47 -52
- package/lib/util/temp-dir.js.map +1 -0
- package/lib/util/updates.js +16 -0
- package/lib/util/updates.js.map +1 -0
- package/lib/watcher.js +78 -0
- package/lib/watcher.js.map +1 -0
- package/package.json +50 -52
- package/CODE_OF_CONDUCT.md +0 -10
- package/bin/web-ext +0 -7
- package/dist/web-ext.js +0 -2
- package/index.mjs +0 -13
- package/src/cmd/build.js +0 -319
- package/src/cmd/docs.js +0 -33
- package/src/cmd/index.js +0 -57
- package/src/cmd/lint.js +0 -102
- package/src/cmd/run.js +0 -266
- package/src/cmd/sign.js +0 -198
- package/src/config.js +0 -187
- package/src/extension-runners/base.js +0 -40
- package/src/extension-runners/index.js +0 -381
- package/src/firefox/index.js +0 -541
- package/src/firefox/package-identifiers.js +0 -14
- package/src/main.js +0 -19
- package/src/program.js +0 -765
- package/src/util/adb.js +0 -433
- package/src/util/artifacts.js +0 -69
- package/src/util/desktop-notifier.js +0 -41
- package/src/util/is-directory.js +0 -23
- package/src/util/logger.js +0 -131
- package/src/util/updates.js +0 -21
- package/src/watcher.js +0 -114
|
@@ -1,62 +1,36 @@
|
|
|
1
|
-
/* @flow */
|
|
2
1
|
import net from 'net';
|
|
3
2
|
import EventEmitter from 'events';
|
|
4
3
|
import domain from 'domain';
|
|
5
|
-
|
|
6
|
-
export type RDPRequest = {
|
|
7
|
-
to: string,
|
|
8
|
-
type: string,
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
export type RDPResult = {
|
|
12
|
-
from: string,
|
|
13
|
-
type: string,
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
export type Deferred = {|
|
|
17
|
-
resolve: Function,
|
|
18
|
-
reject: Function,
|
|
19
|
-
|}
|
|
20
|
-
|
|
21
|
-
type ParseResult = {|
|
|
22
|
-
data: Buffer,
|
|
23
|
-
rdpMessage?: Object,
|
|
24
|
-
error?: Error,
|
|
25
|
-
fatal?: boolean,
|
|
26
|
-
|}
|
|
27
|
-
|
|
28
4
|
export const DEFAULT_PORT = 6000;
|
|
29
5
|
export const DEFAULT_HOST = '127.0.0.1';
|
|
6
|
+
const UNSOLICITED_EVENTS = new Set(['tabNavigated', 'styleApplied', 'propertyChange', 'networkEventUpdate', 'networkEvent', 'propertyChange', 'newMutations', 'frameUpdate', 'tabListChanged']); // Parse RDP packets: BYTE_LENGTH + ':' + DATA.
|
|
30
7
|
|
|
31
|
-
|
|
32
|
-
'tabNavigated',
|
|
33
|
-
'styleApplied',
|
|
34
|
-
'propertyChange',
|
|
35
|
-
'networkEventUpdate',
|
|
36
|
-
'networkEvent',
|
|
37
|
-
'propertyChange',
|
|
38
|
-
'newMutations',
|
|
39
|
-
'frameUpdate',
|
|
40
|
-
'tabListChanged',
|
|
41
|
-
]);
|
|
42
|
-
|
|
43
|
-
// Parse RDP packets: BYTE_LENGTH + ':' + DATA.
|
|
44
|
-
export function parseRDPMessage(data: Buffer): ParseResult {
|
|
8
|
+
export function parseRDPMessage(data) {
|
|
45
9
|
const str = data.toString();
|
|
46
10
|
const sepIdx = str.indexOf(':');
|
|
11
|
+
|
|
47
12
|
if (sepIdx < 1) {
|
|
48
|
-
return {
|
|
13
|
+
return {
|
|
14
|
+
data
|
|
15
|
+
};
|
|
49
16
|
}
|
|
50
17
|
|
|
51
18
|
const byteLen = parseInt(str.slice(0, sepIdx));
|
|
19
|
+
|
|
52
20
|
if (isNaN(byteLen)) {
|
|
53
21
|
const error = new Error('Error parsing RDP message length');
|
|
54
|
-
return {
|
|
22
|
+
return {
|
|
23
|
+
data,
|
|
24
|
+
error,
|
|
25
|
+
fatal: true
|
|
26
|
+
};
|
|
55
27
|
}
|
|
56
28
|
|
|
57
29
|
if (data.length - (sepIdx + 1) < byteLen) {
|
|
58
30
|
// Can't parse yet, will retry once more data has been received.
|
|
59
|
-
return {
|
|
31
|
+
return {
|
|
32
|
+
data
|
|
33
|
+
};
|
|
60
34
|
}
|
|
61
35
|
|
|
62
36
|
data = data.slice(sepIdx + 1);
|
|
@@ -64,27 +38,23 @@ export function parseRDPMessage(data: Buffer): ParseResult {
|
|
|
64
38
|
data = data.slice(byteLen);
|
|
65
39
|
|
|
66
40
|
try {
|
|
67
|
-
return {
|
|
41
|
+
return {
|
|
42
|
+
data,
|
|
43
|
+
rdpMessage: JSON.parse(msg.toString())
|
|
44
|
+
};
|
|
68
45
|
} catch (error) {
|
|
69
|
-
return {
|
|
46
|
+
return {
|
|
47
|
+
data,
|
|
48
|
+
error,
|
|
49
|
+
fatal: false
|
|
50
|
+
};
|
|
70
51
|
}
|
|
71
52
|
}
|
|
72
|
-
|
|
73
|
-
export function connectToFirefox(port: number): Promise<FirefoxRDPClient> {
|
|
53
|
+
export function connectToFirefox(port) {
|
|
74
54
|
const client = new FirefoxRDPClient();
|
|
75
55
|
return client.connect(port).then(() => client);
|
|
76
56
|
}
|
|
77
|
-
|
|
78
57
|
export default class FirefoxRDPClient extends EventEmitter {
|
|
79
|
-
_incoming: Buffer;
|
|
80
|
-
_pending: Array<{| request: RDPRequest, deferred: Deferred |}>;
|
|
81
|
-
_active: Map<string, Deferred>;
|
|
82
|
-
_rdpConnection: net.Socket;
|
|
83
|
-
_onData: Function;
|
|
84
|
-
_onError: Function;
|
|
85
|
-
_onEnd: Function;
|
|
86
|
-
_onTimeout: Function;
|
|
87
|
-
|
|
88
58
|
constructor() {
|
|
89
59
|
super();
|
|
90
60
|
this._incoming = Buffer.alloc(0);
|
|
@@ -92,12 +62,15 @@ export default class FirefoxRDPClient extends EventEmitter {
|
|
|
92
62
|
this._active = new Map();
|
|
93
63
|
|
|
94
64
|
this._onData = (...args) => this.onData(...args);
|
|
65
|
+
|
|
95
66
|
this._onError = (...args) => this.onError(...args);
|
|
67
|
+
|
|
96
68
|
this._onEnd = (...args) => this.onEnd(...args);
|
|
69
|
+
|
|
97
70
|
this._onTimeout = (...args) => this.onTimeout(...args);
|
|
98
71
|
}
|
|
99
72
|
|
|
100
|
-
connect(port
|
|
73
|
+
connect(port) {
|
|
101
74
|
return new Promise((resolve, reject) => {
|
|
102
75
|
// Create a domain to wrap the errors that may be triggered
|
|
103
76
|
// by creating the client connection (e.g. ECONNREFUSED)
|
|
@@ -108,23 +81,24 @@ export default class FirefoxRDPClient extends EventEmitter {
|
|
|
108
81
|
d.run(() => {
|
|
109
82
|
const conn = net.createConnection({
|
|
110
83
|
port,
|
|
111
|
-
host: DEFAULT_HOST
|
|
84
|
+
host: DEFAULT_HOST
|
|
112
85
|
});
|
|
113
|
-
|
|
114
86
|
this._rdpConnection = conn;
|
|
115
87
|
conn.on('data', this._onData);
|
|
116
88
|
conn.on('error', this._onError);
|
|
117
89
|
conn.on('end', this._onEnd);
|
|
118
|
-
conn.on('timeout', this._onTimeout);
|
|
119
|
-
|
|
120
|
-
// Resolve once the expected initial root message
|
|
90
|
+
conn.on('timeout', this._onTimeout); // Resolve once the expected initial root message
|
|
121
91
|
// has been received.
|
|
122
|
-
|
|
92
|
+
|
|
93
|
+
this._expectReply('root', {
|
|
94
|
+
resolve,
|
|
95
|
+
reject
|
|
96
|
+
});
|
|
123
97
|
});
|
|
124
98
|
});
|
|
125
99
|
}
|
|
126
100
|
|
|
127
|
-
disconnect()
|
|
101
|
+
disconnect() {
|
|
128
102
|
if (!this._rdpConnection) {
|
|
129
103
|
return;
|
|
130
104
|
}
|
|
@@ -139,42 +113,58 @@ export default class FirefoxRDPClient extends EventEmitter {
|
|
|
139
113
|
this._rejectAllRequests(new Error('RDP connection closed'));
|
|
140
114
|
}
|
|
141
115
|
|
|
142
|
-
_rejectAllRequests(error
|
|
116
|
+
_rejectAllRequests(error) {
|
|
143
117
|
for (const activeDeferred of this._active.values()) {
|
|
144
118
|
activeDeferred.reject(error);
|
|
145
119
|
}
|
|
120
|
+
|
|
146
121
|
this._active.clear();
|
|
147
122
|
|
|
148
|
-
for (const {
|
|
123
|
+
for (const {
|
|
124
|
+
deferred
|
|
125
|
+
} of this._pending) {
|
|
149
126
|
deferred.reject(error);
|
|
150
127
|
}
|
|
128
|
+
|
|
151
129
|
this._pending = [];
|
|
152
130
|
}
|
|
153
131
|
|
|
154
|
-
async request(requestProps
|
|
155
|
-
let request
|
|
132
|
+
async request(requestProps) {
|
|
133
|
+
let request;
|
|
156
134
|
|
|
157
135
|
if (typeof requestProps === 'string') {
|
|
158
|
-
request = {
|
|
136
|
+
request = {
|
|
137
|
+
to: 'root',
|
|
138
|
+
type: requestProps
|
|
139
|
+
};
|
|
159
140
|
} else {
|
|
160
141
|
request = requestProps;
|
|
161
142
|
}
|
|
162
143
|
|
|
163
144
|
if (request.to == null) {
|
|
164
|
-
throw new Error(
|
|
165
|
-
`Unexpected RDP request without target actor: ${request.type}`
|
|
166
|
-
);
|
|
145
|
+
throw new Error(`Unexpected RDP request without target actor: ${request.type}`);
|
|
167
146
|
}
|
|
168
147
|
|
|
169
148
|
return new Promise((resolve, reject) => {
|
|
170
|
-
const deferred = {
|
|
171
|
-
|
|
149
|
+
const deferred = {
|
|
150
|
+
resolve,
|
|
151
|
+
reject
|
|
152
|
+
};
|
|
153
|
+
|
|
154
|
+
this._pending.push({
|
|
155
|
+
request,
|
|
156
|
+
deferred
|
|
157
|
+
});
|
|
158
|
+
|
|
172
159
|
this._flushPendingRequests();
|
|
173
160
|
});
|
|
174
161
|
}
|
|
175
162
|
|
|
176
|
-
_flushPendingRequests()
|
|
177
|
-
this._pending = this._pending.filter(({
|
|
163
|
+
_flushPendingRequests() {
|
|
164
|
+
this._pending = this._pending.filter(({
|
|
165
|
+
request,
|
|
166
|
+
deferred
|
|
167
|
+
}) => {
|
|
178
168
|
if (this._active.has(request.to)) {
|
|
179
169
|
// Keep in the pending requests until there are no requests
|
|
180
170
|
// active on the target RDP actor.
|
|
@@ -182,6 +172,7 @@ export default class FirefoxRDPClient extends EventEmitter {
|
|
|
182
172
|
}
|
|
183
173
|
|
|
184
174
|
const conn = this._rdpConnection;
|
|
175
|
+
|
|
185
176
|
if (!conn) {
|
|
186
177
|
throw new Error('RDP connection closed');
|
|
187
178
|
}
|
|
@@ -190,17 +181,18 @@ export default class FirefoxRDPClient extends EventEmitter {
|
|
|
190
181
|
let str = JSON.stringify(request);
|
|
191
182
|
str = `${Buffer.from(str).length}:${str}`;
|
|
192
183
|
conn.write(str);
|
|
184
|
+
|
|
193
185
|
this._expectReply(request.to, deferred);
|
|
194
186
|
} catch (err) {
|
|
195
187
|
deferred.reject(err);
|
|
196
|
-
}
|
|
188
|
+
} // Remove the pending request from the queue.
|
|
189
|
+
|
|
197
190
|
|
|
198
|
-
// Remove the pending request from the queue.
|
|
199
191
|
return false;
|
|
200
192
|
});
|
|
201
193
|
}
|
|
202
194
|
|
|
203
|
-
_expectReply(targetActor
|
|
195
|
+
_expectReply(targetActor, deferred) {
|
|
204
196
|
if (this._active.has(targetActor)) {
|
|
205
197
|
throw new Error(`${targetActor} does already have an active request`);
|
|
206
198
|
}
|
|
@@ -208,18 +200,14 @@ export default class FirefoxRDPClient extends EventEmitter {
|
|
|
208
200
|
this._active.set(targetActor, deferred);
|
|
209
201
|
}
|
|
210
202
|
|
|
211
|
-
_handleMessage(rdpData
|
|
203
|
+
_handleMessage(rdpData) {
|
|
212
204
|
if (rdpData.from == null) {
|
|
213
205
|
if (rdpData.error) {
|
|
214
206
|
this.emit('rdp-error', rdpData);
|
|
215
207
|
return;
|
|
216
208
|
}
|
|
217
209
|
|
|
218
|
-
this.emit('error', new Error(
|
|
219
|
-
`Received an RDP message without a sender actor: ${
|
|
220
|
-
JSON.stringify(rdpData)
|
|
221
|
-
}`
|
|
222
|
-
));
|
|
210
|
+
this.emit('error', new Error(`Received an RDP message without a sender actor: ${JSON.stringify(rdpData)}`));
|
|
223
211
|
return;
|
|
224
212
|
}
|
|
225
213
|
|
|
@@ -230,40 +218,42 @@ export default class FirefoxRDPClient extends EventEmitter {
|
|
|
230
218
|
|
|
231
219
|
if (this._active.has(rdpData.from)) {
|
|
232
220
|
const deferred = this._active.get(rdpData.from);
|
|
221
|
+
|
|
233
222
|
this._active.delete(rdpData.from);
|
|
223
|
+
|
|
234
224
|
if (rdpData.error) {
|
|
235
|
-
deferred
|
|
225
|
+
deferred === null || deferred === void 0 ? void 0 : deferred.reject(rdpData);
|
|
236
226
|
} else {
|
|
237
|
-
deferred
|
|
227
|
+
deferred === null || deferred === void 0 ? void 0 : deferred.resolve(rdpData);
|
|
238
228
|
}
|
|
229
|
+
|
|
239
230
|
this._flushPendingRequests();
|
|
231
|
+
|
|
240
232
|
return;
|
|
241
233
|
}
|
|
242
234
|
|
|
243
|
-
this.emit('error', new Error(
|
|
244
|
-
`Unexpected RDP message received: ${JSON.stringify(rdpData)}`
|
|
245
|
-
));
|
|
235
|
+
this.emit('error', new Error(`Unexpected RDP message received: ${JSON.stringify(rdpData)}`));
|
|
246
236
|
}
|
|
247
237
|
|
|
248
|
-
_readMessage()
|
|
238
|
+
_readMessage() {
|
|
249
239
|
const {
|
|
250
|
-
data,
|
|
240
|
+
data,
|
|
241
|
+
rdpMessage,
|
|
242
|
+
error,
|
|
243
|
+
fatal
|
|
251
244
|
} = parseRDPMessage(this._incoming);
|
|
252
|
-
|
|
253
245
|
this._incoming = data;
|
|
254
246
|
|
|
255
247
|
if (error) {
|
|
256
|
-
this.emit(
|
|
257
|
-
|
|
258
|
-
new Error(`Error parsing RDP packet: ${String(error)}`)
|
|
259
|
-
);
|
|
260
|
-
// Disconnect automatically on a fatal error.
|
|
248
|
+
this.emit('error', new Error(`Error parsing RDP packet: ${String(error)}`)); // Disconnect automatically on a fatal error.
|
|
249
|
+
|
|
261
250
|
if (fatal) {
|
|
262
251
|
this.disconnect();
|
|
263
|
-
}
|
|
264
|
-
// Caller can parse the next message if the error wasn't fatal
|
|
252
|
+
} // Caller can parse the next message if the error wasn't fatal
|
|
265
253
|
// (e.g. the RDP packet that couldn't be parsed has been already
|
|
266
254
|
// removed from the incoming data buffer).
|
|
255
|
+
|
|
256
|
+
|
|
267
257
|
return !fatal;
|
|
268
258
|
}
|
|
269
259
|
|
|
@@ -272,20 +262,21 @@ export default class FirefoxRDPClient extends EventEmitter {
|
|
|
272
262
|
return false;
|
|
273
263
|
}
|
|
274
264
|
|
|
275
|
-
this._handleMessage(rdpMessage);
|
|
276
|
-
|
|
265
|
+
this._handleMessage(rdpMessage); // Caller can try to parse the next message from the remining data.
|
|
266
|
+
|
|
267
|
+
|
|
277
268
|
return true;
|
|
278
269
|
}
|
|
279
270
|
|
|
280
|
-
onData(data
|
|
271
|
+
onData(data) {
|
|
281
272
|
this._incoming = Buffer.concat([this._incoming, data]);
|
|
282
|
-
|
|
283
|
-
|
|
273
|
+
|
|
274
|
+
while (this._readMessage()) {// Keep parsing and handling messages until readMessage
|
|
284
275
|
// returns false.
|
|
285
276
|
}
|
|
286
277
|
}
|
|
287
278
|
|
|
288
|
-
onError(error
|
|
279
|
+
onError(error) {
|
|
289
280
|
this.emit('error', error);
|
|
290
281
|
}
|
|
291
282
|
|
|
@@ -296,4 +287,6 @@ export default class FirefoxRDPClient extends EventEmitter {
|
|
|
296
287
|
onTimeout() {
|
|
297
288
|
this.emit('timeout');
|
|
298
289
|
}
|
|
290
|
+
|
|
299
291
|
}
|
|
292
|
+
//# sourceMappingURL=rdp-client.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"rdp-client.js","names":["net","EventEmitter","domain","DEFAULT_PORT","DEFAULT_HOST","UNSOLICITED_EVENTS","Set","parseRDPMessage","data","str","toString","sepIdx","indexOf","byteLen","parseInt","slice","isNaN","error","Error","fatal","length","msg","rdpMessage","JSON","parse","connectToFirefox","port","client","FirefoxRDPClient","connect","then","constructor","_incoming","Buffer","alloc","_pending","_active","Map","_onData","args","onData","_onError","onError","_onEnd","onEnd","_onTimeout","onTimeout","Promise","resolve","reject","d","create","once","run","conn","createConnection","host","_rdpConnection","on","_expectReply","disconnect","off","end","_rejectAllRequests","activeDeferred","values","clear","deferred","request","requestProps","to","type","push","_flushPendingRequests","filter","has","stringify","from","write","err","targetActor","set","_handleMessage","rdpData","emit","get","delete","_readMessage","String","concat"],"sources":["../../src/firefox/rdp-client.js"],"sourcesContent":["/* @flow */\nimport net from 'net';\nimport EventEmitter from 'events';\nimport domain from 'domain';\n\nexport type RDPRequest = {\n to: string,\n type: string,\n}\n\nexport type RDPResult = {\n from: string,\n type: string,\n}\n\nexport type Deferred = {|\n resolve: Function,\n reject: Function,\n|}\n\ntype ParseResult = {|\n data: Buffer,\n rdpMessage?: Object,\n error?: Error,\n fatal?: boolean,\n|}\n\nexport const DEFAULT_PORT = 6000;\nexport const DEFAULT_HOST = '127.0.0.1';\n\nconst UNSOLICITED_EVENTS = new Set([\n 'tabNavigated',\n 'styleApplied',\n 'propertyChange',\n 'networkEventUpdate',\n 'networkEvent',\n 'propertyChange',\n 'newMutations',\n 'frameUpdate',\n 'tabListChanged',\n]);\n\n// Parse RDP packets: BYTE_LENGTH + ':' + DATA.\nexport function parseRDPMessage(data: Buffer): ParseResult {\n const str = data.toString();\n const sepIdx = str.indexOf(':');\n if (sepIdx < 1) {\n return {data};\n }\n\n const byteLen = parseInt(str.slice(0, sepIdx));\n if (isNaN(byteLen)) {\n const error = new Error('Error parsing RDP message length');\n return {data, error, fatal: true};\n }\n\n if (data.length - (sepIdx + 1) < byteLen) {\n // Can't parse yet, will retry once more data has been received.\n return {data};\n }\n\n data = data.slice(sepIdx + 1);\n const msg = data.slice(0, byteLen);\n data = data.slice(byteLen);\n\n try {\n return {data, rdpMessage: JSON.parse(msg.toString())};\n } catch (error) {\n return {data, error, fatal: false};\n }\n}\n\nexport function connectToFirefox(port: number): Promise<FirefoxRDPClient> {\n const client = new FirefoxRDPClient();\n return client.connect(port).then(() => client);\n}\n\nexport default class FirefoxRDPClient extends EventEmitter {\n _incoming: Buffer;\n _pending: Array<{| request: RDPRequest, deferred: Deferred |}>;\n _active: Map<string, Deferred>;\n _rdpConnection: net.Socket;\n _onData: Function;\n _onError: Function;\n _onEnd: Function;\n _onTimeout: Function;\n\n constructor() {\n super();\n this._incoming = Buffer.alloc(0);\n this._pending = [];\n this._active = new Map();\n\n this._onData = (...args) => this.onData(...args);\n this._onError = (...args) => this.onError(...args);\n this._onEnd = (...args) => this.onEnd(...args);\n this._onTimeout = (...args) => this.onTimeout(...args);\n }\n\n connect(port: number): Promise<void> {\n return new Promise((resolve, reject) => {\n // Create a domain to wrap the errors that may be triggered\n // by creating the client connection (e.g. ECONNREFUSED)\n // so that we can reject the promise returned instead of\n // exiting the entire process.\n const d = domain.create();\n d.once('error', reject);\n d.run(() => {\n const conn = net.createConnection({\n port,\n host: DEFAULT_HOST,\n });\n\n this._rdpConnection = conn;\n conn.on('data', this._onData);\n conn.on('error', this._onError);\n conn.on('end', this._onEnd);\n conn.on('timeout', this._onTimeout);\n\n // Resolve once the expected initial root message\n // has been received.\n this._expectReply('root', {resolve, reject});\n });\n });\n }\n\n disconnect(): void {\n if (!this._rdpConnection) {\n return;\n }\n\n const conn = this._rdpConnection;\n conn.off('data', this._onData);\n conn.off('error', this._onError);\n conn.off('end', this._onEnd);\n conn.off('timeout', this._onTimeout);\n conn.end();\n\n this._rejectAllRequests(new Error('RDP connection closed'));\n }\n\n _rejectAllRequests(error: Error) {\n for (const activeDeferred of this._active.values()) {\n activeDeferred.reject(error);\n }\n this._active.clear();\n\n for (const {deferred} of this._pending) {\n deferred.reject(error);\n }\n this._pending = [];\n }\n\n async request(requestProps: string | RDPRequest): Promise<RDPResult> {\n let request: RDPRequest;\n\n if (typeof requestProps === 'string') {\n request = {to: 'root', type: requestProps};\n } else {\n request = requestProps;\n }\n\n if (request.to == null) {\n throw new Error(\n `Unexpected RDP request without target actor: ${request.type}`\n );\n }\n\n return new Promise((resolve, reject) => {\n const deferred = {resolve, reject};\n this._pending.push({request, deferred});\n this._flushPendingRequests();\n });\n }\n\n _flushPendingRequests(): void {\n this._pending = this._pending.filter(({request, deferred}) => {\n if (this._active.has(request.to)) {\n // Keep in the pending requests until there are no requests\n // active on the target RDP actor.\n return true;\n }\n\n const conn = this._rdpConnection;\n if (!conn) {\n throw new Error('RDP connection closed');\n }\n\n try {\n let str = JSON.stringify(request);\n str = `${Buffer.from(str).length}:${str}`;\n conn.write(str);\n this._expectReply(request.to, deferred);\n } catch (err) {\n deferred.reject(err);\n }\n\n // Remove the pending request from the queue.\n return false;\n });\n }\n\n _expectReply(targetActor: string, deferred: Deferred): void {\n if (this._active.has(targetActor)) {\n throw new Error(`${targetActor} does already have an active request`);\n }\n\n this._active.set(targetActor, deferred);\n }\n\n _handleMessage(rdpData: Object): void {\n if (rdpData.from == null) {\n if (rdpData.error) {\n this.emit('rdp-error', rdpData);\n return;\n }\n\n this.emit('error', new Error(\n `Received an RDP message without a sender actor: ${\n JSON.stringify(rdpData)\n }`\n ));\n return;\n }\n\n if (UNSOLICITED_EVENTS.has(rdpData.type)) {\n this.emit('unsolicited-event', rdpData);\n return;\n }\n\n if (this._active.has(rdpData.from)) {\n const deferred = this._active.get(rdpData.from);\n this._active.delete(rdpData.from);\n if (rdpData.error) {\n deferred?.reject(rdpData);\n } else {\n deferred?.resolve(rdpData);\n }\n this._flushPendingRequests();\n return;\n }\n\n this.emit('error', new Error(\n `Unexpected RDP message received: ${JSON.stringify(rdpData)}`\n ));\n }\n\n _readMessage(): boolean {\n const {\n data, rdpMessage, error, fatal,\n } = parseRDPMessage(this._incoming);\n\n this._incoming = data;\n\n if (error) {\n this.emit(\n 'error',\n new Error(`Error parsing RDP packet: ${String(error)}`)\n );\n // Disconnect automatically on a fatal error.\n if (fatal) {\n this.disconnect();\n }\n // Caller can parse the next message if the error wasn't fatal\n // (e.g. the RDP packet that couldn't be parsed has been already\n // removed from the incoming data buffer).\n return !fatal;\n }\n\n if (!rdpMessage) {\n // Caller will need to wait more data to parse the next message.\n return false;\n }\n\n this._handleMessage(rdpMessage);\n // Caller can try to parse the next message from the remining data.\n return true;\n }\n\n onData(data: Buffer) {\n this._incoming = Buffer.concat([this._incoming, data]);\n while (this._readMessage()) {\n // Keep parsing and handling messages until readMessage\n // returns false.\n }\n }\n\n onError(error: Error) {\n this.emit('error', error);\n }\n\n onEnd() {\n this.emit('end');\n }\n\n onTimeout() {\n this.emit('timeout');\n }\n}\n"],"mappings":"AACA,OAAOA,GAAP,MAAgB,KAAhB;AACA,OAAOC,YAAP,MAAyB,QAAzB;AACA,OAAOC,MAAP,MAAmB,QAAnB;AAwBA,OAAO,MAAMC,YAAY,GAAG,IAArB;AACP,OAAO,MAAMC,YAAY,GAAG,WAArB;AAEP,MAAMC,kBAAkB,GAAG,IAAIC,GAAJ,CAAQ,CACjC,cADiC,EAEjC,cAFiC,EAGjC,gBAHiC,EAIjC,oBAJiC,EAKjC,cALiC,EAMjC,gBANiC,EAOjC,cAPiC,EAQjC,aARiC,EASjC,gBATiC,CAAR,CAA3B,C,CAYA;;AACA,OAAO,SAASC,eAAT,CAAyBC,IAAzB,EAAoD;EACzD,MAAMC,GAAG,GAAGD,IAAI,CAACE,QAAL,EAAZ;EACA,MAAMC,MAAM,GAAGF,GAAG,CAACG,OAAJ,CAAY,GAAZ,CAAf;;EACA,IAAID,MAAM,GAAG,CAAb,EAAgB;IACd,OAAO;MAACH;IAAD,CAAP;EACD;;EAED,MAAMK,OAAO,GAAGC,QAAQ,CAACL,GAAG,CAACM,KAAJ,CAAU,CA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