gologin-commonjs 3.0.1 → 3.0.2
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/dist/src/gologin.js +735 -373
- package/gologin/src/gologin.js +1 -1
- package/package.json +4 -2
- package/tes.js +1 -0
package/dist/src/gologin.js
CHANGED
|
@@ -1,21 +1,21 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
4
|
+
value: true,
|
|
5
5
|
});
|
|
6
6
|
exports.GoLogin = void 0;
|
|
7
7
|
Object.defineProperty(exports, "GologinApi", {
|
|
8
8
|
enumerable: true,
|
|
9
9
|
get: function () {
|
|
10
10
|
return _gologinApi.GologinApi;
|
|
11
|
-
}
|
|
11
|
+
},
|
|
12
12
|
});
|
|
13
13
|
exports.default = void 0;
|
|
14
14
|
Object.defineProperty(exports, "exitAll", {
|
|
15
15
|
enumerable: true,
|
|
16
16
|
get: function () {
|
|
17
17
|
return _gologinApi.exitAll;
|
|
18
|
-
}
|
|
18
|
+
},
|
|
19
19
|
});
|
|
20
20
|
var _child_process = require("child_process");
|
|
21
21
|
var _debug = _interopRequireDefault(require("debug"));
|
|
@@ -32,10 +32,14 @@ var _url = require("url");
|
|
|
32
32
|
var _fonts = require("../fonts.js");
|
|
33
33
|
var _utils = require("./bookmarks/utils.js");
|
|
34
34
|
var _browserApi = require("./browser/browser-api.js");
|
|
35
|
-
var _browserChecker = _interopRequireDefault(
|
|
35
|
+
var _browserChecker = _interopRequireDefault(
|
|
36
|
+
require("./browser/browser-checker.js")
|
|
37
|
+
);
|
|
36
38
|
var _browserUserDataManager = require("./browser/browser-user-data-manager.js");
|
|
37
39
|
var _cookiesManager = require("./cookies/cookies-manager.js");
|
|
38
|
-
var _extensionsManager = _interopRequireDefault(
|
|
40
|
+
var _extensionsManager = _interopRequireDefault(
|
|
41
|
+
require("./extensions/extensions-manager.js")
|
|
42
|
+
);
|
|
39
43
|
var _profileArchiver = require("./profile/profile-archiver.js");
|
|
40
44
|
var _browser = require("./utils/browser.js");
|
|
41
45
|
var _common = require("./utils/common.js");
|
|
@@ -45,22 +49,17 @@ var _gologinApi = require("./gologin-api.js");
|
|
|
45
49
|
var _zeroProfileBookmarks = require("./utils/zero-profile-bookmarks.js");
|
|
46
50
|
var _zeroProfilePreferences = require("./utils/zero-profile-preferences.js");
|
|
47
51
|
var _timezone = require("./utils/timezone.js");
|
|
48
|
-
function _interopRequireDefault(e) {
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
writeFile,
|
|
53
|
-
readFile,
|
|
54
|
-
mkdir,
|
|
55
|
-
copyFile
|
|
56
|
-
} = _fs.promises;
|
|
52
|
+
function _interopRequireDefault(e) {
|
|
53
|
+
return e && e.__esModule ? e : { default: e };
|
|
54
|
+
}
|
|
55
|
+
const { access, unlink, writeFile, readFile, mkdir, copyFile } = _fs.promises;
|
|
57
56
|
const SEPARATOR = _path.sep;
|
|
58
57
|
const OS_PLATFORM = process.platform;
|
|
59
58
|
const TIMEZONE_URL = "https://geolocation-db.com/json/";
|
|
60
59
|
// const TIMEZONE_URL = 'https://geo.myip.link';
|
|
61
60
|
const PROXY_NONE = "none";
|
|
62
61
|
const debug = (0, _debug.default)("gologin");
|
|
63
|
-
const delay = time => new Promise(resolve => setTimeout(resolve, time));
|
|
62
|
+
const delay = (time) => new Promise((resolve) => setTimeout(resolve, time));
|
|
64
63
|
class GoLogin {
|
|
65
64
|
constructor(options = {}) {
|
|
66
65
|
this.browserLang = "en-US";
|
|
@@ -83,14 +82,16 @@ class GoLogin {
|
|
|
83
82
|
this.tmpdir = (0, _os.tmpdir)();
|
|
84
83
|
this.autoUpdateBrowser = !!options.autoUpdateBrowser;
|
|
85
84
|
this.checkBrowserUpdate = options.checkBrowserUpdate ?? true;
|
|
86
|
-
this.browserChecker = new _browserChecker.default(
|
|
85
|
+
this.browserChecker = new _browserChecker.default(
|
|
86
|
+
options.skipOrbitaHashChecking
|
|
87
|
+
);
|
|
87
88
|
this.uploadCookiesToServer = options.uploadCookiesToServer || false;
|
|
88
89
|
this.writeCookiesFromServer = options.writeCookiesFromServer;
|
|
89
90
|
this.remote_debugging_port = options.remote_debugging_port || 0;
|
|
90
91
|
this.timezone = options.timezone;
|
|
91
92
|
this.extensionPathsToInstall = [];
|
|
92
93
|
this.customArgs = options.args || [];
|
|
93
|
-
this.restoreLastSession = options.restoreLastSession
|
|
94
|
+
this.restoreLastSession = options.restoreLastSession ?? true;
|
|
94
95
|
this.processSpawned = null;
|
|
95
96
|
this.processKillTimeout = 1 * 1000;
|
|
96
97
|
if (options.tmpdir) {
|
|
@@ -98,52 +99,87 @@ class GoLogin {
|
|
|
98
99
|
if (!(0, _fs.existsSync)(this.tmpdir)) {
|
|
99
100
|
debug("making tmpdir", this.tmpdir);
|
|
100
101
|
(0, _fs.mkdirSync)(this.tmpdir, {
|
|
101
|
-
recursive: true
|
|
102
|
+
recursive: true,
|
|
102
103
|
});
|
|
103
104
|
}
|
|
104
105
|
}
|
|
105
|
-
this.profile_zip_path = (0, _path.join)(
|
|
106
|
-
|
|
106
|
+
this.profile_zip_path = (0, _path.join)(
|
|
107
|
+
this.tmpdir,
|
|
108
|
+
`gologin_${this.profile_id}.zip`
|
|
109
|
+
);
|
|
110
|
+
this.bookmarksFilePath = (0, _path.join)(
|
|
111
|
+
this.tmpdir,
|
|
112
|
+
`gologin_profile_${this.profile_id}`,
|
|
113
|
+
"Default",
|
|
114
|
+
"Bookmarks"
|
|
115
|
+
);
|
|
107
116
|
debug("INIT GOLOGIN", this.profile_id);
|
|
108
117
|
}
|
|
109
118
|
async checkBrowser() {
|
|
110
|
-
return this.browserChecker.checkBrowser(
|
|
119
|
+
return this.browserChecker.checkBrowser(
|
|
120
|
+
this.autoUpdateBrowser,
|
|
121
|
+
this.checkBrowserUpdate
|
|
122
|
+
);
|
|
111
123
|
}
|
|
112
124
|
async setProfileId(profile_id) {
|
|
113
125
|
this.profile_id = profile_id;
|
|
114
|
-
this.cookiesFilePath = await (0, _cookiesManager.getCookiesFilePath)(
|
|
115
|
-
|
|
116
|
-
|
|
126
|
+
this.cookiesFilePath = await (0, _cookiesManager.getCookiesFilePath)(
|
|
127
|
+
profile_id,
|
|
128
|
+
this.tmpdir
|
|
129
|
+
);
|
|
130
|
+
this.profile_zip_path = (0, _path.join)(
|
|
131
|
+
this.tmpdir,
|
|
132
|
+
`gologin_${this.profile_id}.zip`
|
|
133
|
+
);
|
|
134
|
+
this.bookmarksFilePath = (0, _path.join)(
|
|
135
|
+
this.tmpdir,
|
|
136
|
+
`gologin_profile_${this.profile_id}`,
|
|
137
|
+
"Default",
|
|
138
|
+
"Bookmarks"
|
|
139
|
+
);
|
|
117
140
|
}
|
|
118
141
|
async getToken(username, password) {
|
|
119
|
-
const data = await _requestretry.default.post(
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
142
|
+
const data = await _requestretry.default.post(
|
|
143
|
+
`${_common.API_URL}/user/login`,
|
|
144
|
+
{
|
|
145
|
+
json: {
|
|
146
|
+
username,
|
|
147
|
+
password,
|
|
148
|
+
},
|
|
123
149
|
}
|
|
124
|
-
|
|
150
|
+
);
|
|
125
151
|
if (!Reflect.has(data, "body.access_token")) {
|
|
126
|
-
throw new Error(
|
|
152
|
+
throw new Error(
|
|
153
|
+
`gologin auth failed with status code, ${
|
|
154
|
+
data.statusCode
|
|
155
|
+
} DATA ${JSON.stringify(data)}`
|
|
156
|
+
);
|
|
127
157
|
}
|
|
128
158
|
}
|
|
129
159
|
async getNewFingerPrint(os) {
|
|
130
160
|
debug("GETTING FINGERPRINT");
|
|
131
|
-
const fpResponse = await _requestretry.default.get(
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
161
|
+
const fpResponse = await _requestretry.default.get(
|
|
162
|
+
`${_common.API_URL}/browser/fingerprint?os=${os}`,
|
|
163
|
+
{
|
|
164
|
+
json: true,
|
|
165
|
+
headers: {
|
|
166
|
+
Authorization: `Bearer ${this.access_token}`,
|
|
167
|
+
"User-Agent": "gologin-api",
|
|
168
|
+
},
|
|
136
169
|
}
|
|
137
|
-
|
|
170
|
+
);
|
|
138
171
|
return fpResponse?.body || {};
|
|
139
172
|
}
|
|
140
173
|
async profiles() {
|
|
141
|
-
const profilesResponse = await _requestretry.default.get(
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
174
|
+
const profilesResponse = await _requestretry.default.get(
|
|
175
|
+
`${_common.API_URL}/browser/v2`,
|
|
176
|
+
{
|
|
177
|
+
headers: {
|
|
178
|
+
Authorization: `Bearer ${this.access_token}`,
|
|
179
|
+
"User-Agent": "gologin-api",
|
|
180
|
+
},
|
|
145
181
|
}
|
|
146
|
-
|
|
182
|
+
);
|
|
147
183
|
if (profilesResponse.statusCode !== 200) {
|
|
148
184
|
throw new Error("Gologin /browser response error");
|
|
149
185
|
}
|
|
@@ -152,16 +188,17 @@ class GoLogin {
|
|
|
152
188
|
async getProfile(profile_id) {
|
|
153
189
|
const id = profile_id || this.profile_id;
|
|
154
190
|
debug("getProfile", this.access_token, id);
|
|
155
|
-
const profileResponse = await _requestretry.default.get(
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
191
|
+
const profileResponse = await _requestretry.default.get(
|
|
192
|
+
`${_common.API_URL}/browser/features/${id}/info-for-run`,
|
|
193
|
+
{
|
|
194
|
+
headers: {
|
|
195
|
+
Authorization: `Bearer ${this.access_token}`,
|
|
196
|
+
"User-Agent": "gologin-api",
|
|
197
|
+
},
|
|
159
198
|
}
|
|
160
|
-
|
|
199
|
+
);
|
|
161
200
|
debug("profileResponse", profileResponse.statusCode, profileResponse.body);
|
|
162
|
-
const {
|
|
163
|
-
body: errorBody = ""
|
|
164
|
-
} = profileResponse;
|
|
201
|
+
const { body: errorBody = "" } = profileResponse;
|
|
165
202
|
const backendErrorHeader = "backend@error::";
|
|
166
203
|
if (errorBody.includes(backendErrorHeader)) {
|
|
167
204
|
const errorData = errorBody.replace(backendErrorHeader, "").slice(1, -1);
|
|
@@ -174,7 +211,9 @@ class GoLogin {
|
|
|
174
211
|
throw new Error(JSON.parse(profileResponse.body).message);
|
|
175
212
|
}
|
|
176
213
|
if (profileResponse.statusCode !== 200) {
|
|
177
|
-
throw new Error(
|
|
214
|
+
throw new Error(
|
|
215
|
+
`Gologin /browser/${id} response error ${profileResponse.statusCode} INVALID TOKEN OR PROFILE NOT FOUND`
|
|
216
|
+
);
|
|
178
217
|
}
|
|
179
218
|
if (profileResponse.statusCode === 401) {
|
|
180
219
|
throw new Error("invalid token");
|
|
@@ -182,7 +221,9 @@ class GoLogin {
|
|
|
182
221
|
return JSON.parse(profileResponse.body);
|
|
183
222
|
}
|
|
184
223
|
async emptyProfile() {
|
|
185
|
-
return readFile(
|
|
224
|
+
return readFile(
|
|
225
|
+
(0, _path.resolve)(__dirname, "gologin_zeroprofile.b64")
|
|
226
|
+
).then((res) => res.toString());
|
|
186
227
|
}
|
|
187
228
|
async getProfileS3() {
|
|
188
229
|
const token = this.access_token;
|
|
@@ -192,12 +233,14 @@ class GoLogin {
|
|
|
192
233
|
const profileResponse = await fetch(downloadURL, {
|
|
193
234
|
headers: {
|
|
194
235
|
Authorization: `Bearer ${token}`,
|
|
195
|
-
browserId: this.profile_id
|
|
196
|
-
}
|
|
236
|
+
browserId: this.profile_id,
|
|
237
|
+
},
|
|
197
238
|
});
|
|
198
239
|
const profileResponseBody = await profileResponse.arrayBuffer();
|
|
199
240
|
if (profileResponse.status !== 200) {
|
|
200
|
-
debug(
|
|
241
|
+
debug(
|
|
242
|
+
`Gologin S3 BUCKET ${downloadURL} response error ${profileResponse.statusCode} - use empty`
|
|
243
|
+
);
|
|
201
244
|
return "";
|
|
202
245
|
}
|
|
203
246
|
return Buffer.from(profileResponseBody);
|
|
@@ -212,7 +255,7 @@ class GoLogin {
|
|
|
212
255
|
Authorization: `Bearer ${this.access_token}`,
|
|
213
256
|
browserId: this.profile_id,
|
|
214
257
|
"Content-Type": "application/zip",
|
|
215
|
-
"Content-Length": bodyBufferBiteLength
|
|
258
|
+
"Content-Length": bodyBufferBiteLength,
|
|
216
259
|
},
|
|
217
260
|
body: fileBuff,
|
|
218
261
|
maxBodyLength: Infinity,
|
|
@@ -220,43 +263,73 @@ class GoLogin {
|
|
|
220
263
|
maxAttempts: 3,
|
|
221
264
|
retryDelay: 2000,
|
|
222
265
|
timeout: 30 * 1000,
|
|
223
|
-
fullResponse: false
|
|
266
|
+
fullResponse: false,
|
|
224
267
|
});
|
|
225
268
|
console.log("Profile has been uploaded to S3 successfully");
|
|
226
269
|
}
|
|
227
270
|
async emptyProfileFolder() {
|
|
228
271
|
debug("get emptyProfileFolder");
|
|
229
|
-
const currentDir = (0, _path.dirname)(
|
|
230
|
-
|
|
272
|
+
const currentDir = (0, _path.dirname)(
|
|
273
|
+
(0, _url.fileURLToPath)(
|
|
274
|
+
require("url").pathToFileURL(__filename).toString()
|
|
275
|
+
)
|
|
276
|
+
);
|
|
277
|
+
const zeroProfilePath = (0, _path.join)(
|
|
278
|
+
currentDir,
|
|
279
|
+
"..",
|
|
280
|
+
"zero_profile.zip"
|
|
281
|
+
);
|
|
231
282
|
const profile = await readFile((0, _path.resolve)(zeroProfilePath));
|
|
232
283
|
debug("emptyProfileFolder LENGTH ::", profile.length);
|
|
233
284
|
return profile;
|
|
234
285
|
}
|
|
235
286
|
convertPreferences(preferences) {
|
|
236
287
|
if ((0, _utils2.get)(preferences, "navigator.userAgent")) {
|
|
237
|
-
preferences.userAgent = (0, _utils2.get)(
|
|
288
|
+
preferences.userAgent = (0, _utils2.get)(
|
|
289
|
+
preferences,
|
|
290
|
+
"navigator.userAgent"
|
|
291
|
+
);
|
|
238
292
|
}
|
|
239
293
|
if ((0, _utils2.get)(preferences, "navigator.doNotTrack")) {
|
|
240
|
-
preferences.doNotTrack = (0, _utils2.get)(
|
|
294
|
+
preferences.doNotTrack = (0, _utils2.get)(
|
|
295
|
+
preferences,
|
|
296
|
+
"navigator.doNotTrack"
|
|
297
|
+
);
|
|
241
298
|
}
|
|
242
299
|
if ((0, _utils2.get)(preferences, "navigator.hardwareConcurrency")) {
|
|
243
|
-
preferences.hardwareConcurrency = (0, _utils2.get)(
|
|
300
|
+
preferences.hardwareConcurrency = (0, _utils2.get)(
|
|
301
|
+
preferences,
|
|
302
|
+
"navigator.hardwareConcurrency"
|
|
303
|
+
);
|
|
244
304
|
}
|
|
245
305
|
if ((0, _utils2.get)(preferences, "navigator.deviceMemory")) {
|
|
246
|
-
preferences.deviceMemory =
|
|
306
|
+
preferences.deviceMemory =
|
|
307
|
+
(0, _utils2.get)(preferences, "navigator.deviceMemory") * 1024;
|
|
247
308
|
}
|
|
248
309
|
if ((0, _utils2.get)(preferences, "navigator.language")) {
|
|
249
|
-
preferences.langHeader = (0, _utils2.get)(
|
|
250
|
-
|
|
310
|
+
preferences.langHeader = (0, _utils2.get)(
|
|
311
|
+
preferences,
|
|
312
|
+
"navigator.language"
|
|
313
|
+
);
|
|
314
|
+
preferences.languages = (0, _utils2.get)(
|
|
315
|
+
preferences,
|
|
316
|
+
"navigator.language"
|
|
317
|
+
).replace(/;|q=[\d\.]+/gim, "");
|
|
251
318
|
}
|
|
252
319
|
if ((0, _utils2.get)(preferences, "navigator.maxTouchPoints")) {
|
|
253
|
-
preferences.navigator.max_touch_points = (0, _utils2.get)(
|
|
320
|
+
preferences.navigator.max_touch_points = (0, _utils2.get)(
|
|
321
|
+
preferences,
|
|
322
|
+
"navigator.maxTouchPoints"
|
|
323
|
+
);
|
|
254
324
|
}
|
|
255
325
|
if ((0, _utils2.get)(preferences, "isM1")) {
|
|
256
326
|
preferences.is_m1 = (0, _utils2.get)(preferences, "isM1");
|
|
257
327
|
}
|
|
258
328
|
if ((0, _utils2.get)(preferences, "os") == "android") {
|
|
259
|
-
const devicePixelRatio = (0, _utils2.get)(
|
|
329
|
+
const devicePixelRatio = (0, _utils2.get)(
|
|
330
|
+
preferences,
|
|
331
|
+
"devicePixelRatio"
|
|
332
|
+
);
|
|
260
333
|
const deviceScaleFactorCeil = Math.ceil(devicePixelRatio || 3.5);
|
|
261
334
|
let deviceScaleFactor = devicePixelRatio;
|
|
262
335
|
if (deviceScaleFactorCeil === devicePixelRatio) {
|
|
@@ -266,19 +339,22 @@ class GoLogin {
|
|
|
266
339
|
enable: true,
|
|
267
340
|
width: parseInt(this.resolution.width, 10),
|
|
268
341
|
height: parseInt(this.resolution.height, 10),
|
|
269
|
-
device_scale_factor: deviceScaleFactor
|
|
342
|
+
device_scale_factor: deviceScaleFactor,
|
|
270
343
|
};
|
|
271
344
|
}
|
|
272
345
|
preferences.mediaDevices = {
|
|
273
346
|
enable: preferences.mediaDevices.enableMasking,
|
|
274
347
|
videoInputs: preferences.mediaDevices.videoInputs,
|
|
275
348
|
audioInputs: preferences.mediaDevices.audioInputs,
|
|
276
|
-
audioOutputs: preferences.mediaDevices.audioOutputs
|
|
349
|
+
audioOutputs: preferences.mediaDevices.audioOutputs,
|
|
277
350
|
};
|
|
278
351
|
preferences.webRtc = {
|
|
279
352
|
...preferences.webRtc,
|
|
280
353
|
fill_based_on_ip: !!(0, _utils2.get)(preferences, "webRTC.fillBasedOnIp"),
|
|
281
|
-
local_ip_masking: !!(0, _utils2.get)(
|
|
354
|
+
local_ip_masking: !!(0, _utils2.get)(
|
|
355
|
+
preferences,
|
|
356
|
+
"webRTC.local_ip_masking"
|
|
357
|
+
),
|
|
282
358
|
};
|
|
283
359
|
return preferences;
|
|
284
360
|
}
|
|
@@ -288,32 +364,49 @@ class GoLogin {
|
|
|
288
364
|
await (0, _rimraf.default)(this.orbitaExtensionPath(), () => null);
|
|
289
365
|
const extPath = this.orbitaExtensionPath();
|
|
290
366
|
debug("extension folder sanitized");
|
|
291
|
-
const extension_source = (0, _path.resolve)(
|
|
367
|
+
const extension_source = (0, _path.resolve)(
|
|
368
|
+
__dirname,
|
|
369
|
+
"gologin-browser-ext.zip"
|
|
370
|
+
);
|
|
292
371
|
await (0, _decompress.default)(extension_source, extPath, {
|
|
293
372
|
plugins: [(0, _decompressUnzip.default)()],
|
|
294
|
-
filter: file => !file.path.endsWith("/")
|
|
295
|
-
})
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
373
|
+
filter: (file) => !file.path.endsWith("/"),
|
|
374
|
+
})
|
|
375
|
+
.then(() => {
|
|
376
|
+
debug("extraction done");
|
|
377
|
+
debug("create uid.json");
|
|
378
|
+
return writeFile(
|
|
379
|
+
(0, _path.join)(extPath, "uid.json"),
|
|
380
|
+
JSON.stringify(
|
|
381
|
+
{
|
|
382
|
+
uid: that.profile_id,
|
|
383
|
+
},
|
|
384
|
+
null,
|
|
385
|
+
2
|
|
386
|
+
)
|
|
387
|
+
).then(() => extPath);
|
|
388
|
+
})
|
|
389
|
+
.catch(async (e) => {
|
|
390
|
+
debug("orbita extension error", e);
|
|
391
|
+
});
|
|
304
392
|
debug("createBrowserExtension done");
|
|
305
393
|
}
|
|
306
394
|
extractProfile(path, zipfile) {
|
|
307
395
|
debug(`extactProfile ${zipfile}, ${path}`);
|
|
308
396
|
return (0, _decompress.default)(zipfile, path, {
|
|
309
397
|
plugins: [(0, _decompressUnzip.default)()],
|
|
310
|
-
filter: file => !file.path.endsWith("/")
|
|
398
|
+
filter: (file) => !file.path.endsWith("/"),
|
|
311
399
|
});
|
|
312
400
|
}
|
|
313
401
|
async downloadProfileAndExtract(profile, local) {
|
|
314
402
|
let profile_folder;
|
|
315
|
-
const profilePath = (0, _path.join)(
|
|
316
|
-
|
|
403
|
+
const profilePath = (0, _path.join)(
|
|
404
|
+
this.tmpdir,
|
|
405
|
+
`gologin_profile_${this.profile_id}`
|
|
406
|
+
);
|
|
407
|
+
const profileZipExists = await access(this.profile_zip_path)
|
|
408
|
+
.then(() => true)
|
|
409
|
+
.catch(() => false);
|
|
317
410
|
if (!(local && profileZipExists)) {
|
|
318
411
|
try {
|
|
319
412
|
profile_folder = await this.getProfileS3();
|
|
@@ -337,7 +430,9 @@ class GoLogin {
|
|
|
337
430
|
await this.extractProfile(profilePath, this.profile_zip_path);
|
|
338
431
|
}
|
|
339
432
|
const singletonLockPath = (0, _path.join)(profilePath, "SingletonLock");
|
|
340
|
-
const singletonLockExists = await access(singletonLockPath)
|
|
433
|
+
const singletonLockExists = await access(singletonLockPath)
|
|
434
|
+
.then(() => true)
|
|
435
|
+
.catch(() => false);
|
|
341
436
|
if (singletonLockExists) {
|
|
342
437
|
debug("removing SingletonLock");
|
|
343
438
|
await unlink(singletonLockPath);
|
|
@@ -345,47 +440,72 @@ class GoLogin {
|
|
|
345
440
|
}
|
|
346
441
|
}
|
|
347
442
|
async createZeroProfile(createCookiesTableQuery) {
|
|
348
|
-
const profilePath = (0, _path.join)(
|
|
443
|
+
const profilePath = (0, _path.join)(
|
|
444
|
+
this.tmpdir,
|
|
445
|
+
`gologin_profile_${this.profile_id}`
|
|
446
|
+
);
|
|
349
447
|
const defaultFilePath = (0, _path.resolve)(profilePath, "Default");
|
|
350
|
-
const preferencesFilePath = (0, _path.resolve)(
|
|
448
|
+
const preferencesFilePath = (0, _path.resolve)(
|
|
449
|
+
defaultFilePath,
|
|
450
|
+
"Preferences"
|
|
451
|
+
);
|
|
351
452
|
const bookmarksFilePath = (0, _path.resolve)(defaultFilePath, "Bookmarks");
|
|
352
|
-
const cookiesFilePath = (0, _path.resolve)(
|
|
353
|
-
|
|
453
|
+
const cookiesFilePath = (0, _path.resolve)(
|
|
454
|
+
defaultFilePath,
|
|
455
|
+
"Network",
|
|
456
|
+
"Cookies"
|
|
457
|
+
);
|
|
458
|
+
const cookiesFileSecondPath = (0, _path.resolve)(
|
|
459
|
+
defaultFilePath,
|
|
460
|
+
"Cookies"
|
|
461
|
+
);
|
|
354
462
|
await mkdir((0, _path.resolve)(defaultFilePath, "Network"), {
|
|
355
|
-
recursive: true
|
|
463
|
+
recursive: true,
|
|
356
464
|
}).catch(console.log);
|
|
357
|
-
await Promise.all([
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
465
|
+
await Promise.all([
|
|
466
|
+
writeFile(
|
|
467
|
+
preferencesFilePath,
|
|
468
|
+
JSON.stringify(_zeroProfilePreferences.zeroProfilePreferences),
|
|
469
|
+
{
|
|
470
|
+
mode: 0o666,
|
|
471
|
+
}
|
|
472
|
+
),
|
|
473
|
+
writeFile(
|
|
474
|
+
bookmarksFilePath,
|
|
475
|
+
JSON.stringify(_zeroProfileBookmarks.zeroProfileBookmarks),
|
|
476
|
+
{
|
|
477
|
+
mode: 0o666,
|
|
478
|
+
}
|
|
479
|
+
),
|
|
480
|
+
(0, _cookiesManager.createDBFile)({
|
|
481
|
+
cookiesFilePath,
|
|
482
|
+
cookiesFileSecondPath,
|
|
483
|
+
createCookiesTableQuery,
|
|
484
|
+
}),
|
|
485
|
+
]);
|
|
366
486
|
}
|
|
367
487
|
async createStartup(local = false) {
|
|
368
|
-
const profilePath = (0, _path.join)(
|
|
488
|
+
const profilePath = (0, _path.join)(
|
|
489
|
+
this.tmpdir,
|
|
490
|
+
`gologin_profile_${this.profile_id}`
|
|
491
|
+
);
|
|
369
492
|
await (0, _rimraf.default)(profilePath, () => null);
|
|
370
493
|
debug("-", profilePath, "dropped");
|
|
371
494
|
const profile = await this.getProfile();
|
|
372
|
-
const {
|
|
373
|
-
navigator = {},
|
|
374
|
-
fonts,
|
|
375
|
-
os: profileOs
|
|
376
|
-
} = profile;
|
|
495
|
+
const { navigator = {}, fonts, os: profileOs } = profile;
|
|
377
496
|
this.fontsMasking = fonts?.enableMasking;
|
|
378
497
|
this.profileOs = profileOs;
|
|
379
|
-
this.differentOs =
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
498
|
+
this.differentOs =
|
|
499
|
+
profileOs !== "android" &&
|
|
500
|
+
((OS_PLATFORM === "win32" && profileOs !== "win") ||
|
|
501
|
+
(OS_PLATFORM === "darwin" && profileOs !== "mac") ||
|
|
502
|
+
(OS_PLATFORM === "linux" && profileOs !== "lin"));
|
|
503
|
+
const { resolution = "1920x1080", language = "en-US,en;q=0.9" } = navigator;
|
|
384
504
|
this.language = language;
|
|
385
505
|
const [screenWidth, screenHeight] = resolution.split("x");
|
|
386
506
|
this.resolution = {
|
|
387
507
|
width: parseInt(screenWidth, 10),
|
|
388
|
-
height: parseInt(screenHeight, 10)
|
|
508
|
+
height: parseInt(screenHeight, 10),
|
|
389
509
|
};
|
|
390
510
|
if (profile.storageInfo.isNewProfile) {
|
|
391
511
|
this.isFirstSession = true;
|
|
@@ -394,54 +514,102 @@ class GoLogin {
|
|
|
394
514
|
this.isFirstSession = false;
|
|
395
515
|
await this.downloadProfileAndExtract(profile, local);
|
|
396
516
|
}
|
|
397
|
-
const pref_file_name = (0, _path.join)(
|
|
517
|
+
const pref_file_name = (0, _path.join)(
|
|
518
|
+
profilePath,
|
|
519
|
+
"Default",
|
|
520
|
+
"Preferences"
|
|
521
|
+
);
|
|
398
522
|
debug("reading", pref_file_name);
|
|
399
|
-
const prefFileExists = await access(pref_file_name)
|
|
523
|
+
const prefFileExists = await access(pref_file_name)
|
|
524
|
+
.then(() => true)
|
|
525
|
+
.catch(() => false);
|
|
400
526
|
if (!prefFileExists) {
|
|
401
|
-
debug(
|
|
527
|
+
debug(
|
|
528
|
+
"Preferences file not exists waiting",
|
|
529
|
+
pref_file_name,
|
|
530
|
+
". Using empty profile"
|
|
531
|
+
);
|
|
402
532
|
await writeFile(pref_file_name, "{}");
|
|
403
533
|
}
|
|
404
534
|
const preferences_raw = await readFile(pref_file_name);
|
|
405
535
|
const preferences = JSON.parse(preferences_raw.toString());
|
|
406
536
|
let proxy = (0, _utils2.get)(profile, "proxy");
|
|
407
537
|
const name = (0, _utils2.get)(profile, "name");
|
|
408
|
-
const chromeExtensions =
|
|
409
|
-
|
|
538
|
+
const chromeExtensions =
|
|
539
|
+
(0, _utils2.get)(profile, "chromeExtensions") || [];
|
|
540
|
+
const userChromeExtensions =
|
|
541
|
+
(0, _utils2.get)(profile, "userChromeExtensions") || [];
|
|
410
542
|
const allExtensions = [...chromeExtensions, ...userChromeExtensions];
|
|
411
543
|
if (allExtensions.length) {
|
|
412
544
|
const ExtensionsManagerInst = new _extensionsManager.default();
|
|
413
545
|
ExtensionsManagerInst.apiUrl = _common.API_URL;
|
|
414
|
-
await ExtensionsManagerInst.init()
|
|
546
|
+
await ExtensionsManagerInst.init()
|
|
547
|
+
.then(() => ExtensionsManagerInst.updateExtensions())
|
|
548
|
+
.catch(() => {});
|
|
415
549
|
ExtensionsManagerInst.accessToken = this.access_token;
|
|
416
550
|
await ExtensionsManagerInst.getExtensionsPolicies();
|
|
417
551
|
let profileExtensionsCheckRes = [];
|
|
418
552
|
if (ExtensionsManagerInst.useLocalExtStorage) {
|
|
419
|
-
const promises = [
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
553
|
+
const promises = [
|
|
554
|
+
ExtensionsManagerInst.checkChromeExtensions(allExtensions)
|
|
555
|
+
.then((res) => ({
|
|
556
|
+
profileExtensionsCheckRes: res,
|
|
557
|
+
}))
|
|
558
|
+
.catch((e) => {
|
|
559
|
+
console.log("checkChromeExtensions error: ", e);
|
|
560
|
+
return {
|
|
561
|
+
profileExtensionsCheckRes: [],
|
|
562
|
+
};
|
|
563
|
+
}),
|
|
564
|
+
ExtensionsManagerInst.checkLocalUserChromeExtensions(
|
|
565
|
+
userChromeExtensions,
|
|
566
|
+
this.profile_id
|
|
567
|
+
)
|
|
568
|
+
.then((res) => ({
|
|
569
|
+
profileUserExtensionsCheckRes: res,
|
|
570
|
+
}))
|
|
571
|
+
.catch((error) => {
|
|
572
|
+
console.log("checkUserChromeExtensions error: ", error);
|
|
573
|
+
return null;
|
|
574
|
+
}),
|
|
575
|
+
];
|
|
432
576
|
const extensionsResult = await Promise.all(promises);
|
|
433
|
-
const profileExtensionPathRes =
|
|
434
|
-
|
|
435
|
-
|
|
577
|
+
const profileExtensionPathRes =
|
|
578
|
+
extensionsResult.find((el) => "profileExtensionsCheckRes" in el) ||
|
|
579
|
+
{};
|
|
580
|
+
const profileUserExtensionPathRes = extensionsResult.find(
|
|
581
|
+
(el) => "profileUserExtensionsCheckRes" in el
|
|
582
|
+
);
|
|
583
|
+
profileExtensionsCheckRes = (
|
|
584
|
+
profileExtensionPathRes?.profileExtensionsCheckRes || []
|
|
585
|
+
).concat(
|
|
586
|
+
profileUserExtensionPathRes?.profileUserExtensionsCheckRes || []
|
|
587
|
+
);
|
|
436
588
|
}
|
|
437
589
|
let extSettings;
|
|
438
590
|
if (ExtensionsManagerInst.useLocalExtStorage) {
|
|
439
|
-
extSettings = await (0,
|
|
591
|
+
extSettings = await (0,
|
|
592
|
+
_browserUserDataManager.setExtPathsAndRemoveDeleted)(
|
|
593
|
+
preferences,
|
|
594
|
+
profileExtensionsCheckRes,
|
|
595
|
+
this.profile_id
|
|
596
|
+
);
|
|
440
597
|
} else {
|
|
441
|
-
const originalExtensionsFolder = (0, _path.join)(
|
|
442
|
-
|
|
598
|
+
const originalExtensionsFolder = (0, _path.join)(
|
|
599
|
+
profilePath,
|
|
600
|
+
"Default",
|
|
601
|
+
"Extensions"
|
|
602
|
+
);
|
|
603
|
+
extSettings = await (0, _browserUserDataManager.setOriginalExtPaths)(
|
|
604
|
+
preferences,
|
|
605
|
+
originalExtensionsFolder
|
|
606
|
+
);
|
|
443
607
|
}
|
|
444
|
-
this.extensionPathsToInstall =
|
|
608
|
+
this.extensionPathsToInstall =
|
|
609
|
+
ExtensionsManagerInst.getExtensionsToInstall(
|
|
610
|
+
extSettings,
|
|
611
|
+
profileExtensionsCheckRes
|
|
612
|
+
);
|
|
445
613
|
if (extSettings) {
|
|
446
614
|
const currentExtSettings = preferences.extensions || {};
|
|
447
615
|
currentExtSettings.settings = extSettings;
|
|
@@ -458,7 +626,7 @@ class GoLogin {
|
|
|
458
626
|
host: splittedProxyAddress[0],
|
|
459
627
|
port,
|
|
460
628
|
username: (0, _utils2.get)(profile, "autoProxyUsername"),
|
|
461
|
-
password: (0, _utils2.get)(profile, "autoProxyPassword")
|
|
629
|
+
password: (0, _utils2.get)(profile, "autoProxyPassword"),
|
|
462
630
|
};
|
|
463
631
|
profile.proxy.username = (0, _utils2.get)(profile, "autoProxyUsername");
|
|
464
632
|
profile.proxy.password = (0, _utils2.get)(profile, "autoProxyPassword");
|
|
@@ -470,44 +638,47 @@ class GoLogin {
|
|
|
470
638
|
proxy = null;
|
|
471
639
|
}
|
|
472
640
|
this.proxy = proxy;
|
|
473
|
-
await this.getTimeZone(proxy).catch(e => {
|
|
641
|
+
await this.getTimeZone(proxy).catch((e) => {
|
|
474
642
|
console.error("Proxy Error. Check it and try again.");
|
|
475
643
|
throw new Error(`Proxy Error. ${e.message}`);
|
|
476
644
|
});
|
|
477
645
|
const [latitude, longitude] = this._tz.ll;
|
|
478
|
-
const {
|
|
479
|
-
accuracy
|
|
480
|
-
} = this._tz;
|
|
646
|
+
const { accuracy } = this._tz;
|
|
481
647
|
const profileGeolocation = profile.geolocation;
|
|
482
648
|
const tzGeoLocation = {
|
|
483
649
|
latitude,
|
|
484
650
|
longitude,
|
|
485
|
-
accuracy
|
|
651
|
+
accuracy,
|
|
486
652
|
};
|
|
487
|
-
profile.geoLocation = this.getGeolocationParams(
|
|
653
|
+
profile.geoLocation = this.getGeolocationParams(
|
|
654
|
+
profileGeolocation,
|
|
655
|
+
tzGeoLocation
|
|
656
|
+
);
|
|
488
657
|
profile.name = name;
|
|
489
658
|
profile.name_base64 = Buffer.from(name).toString("base64");
|
|
490
659
|
profile.profile_id = this.profile_id;
|
|
491
660
|
profile.webRtc = {
|
|
492
|
-
mode:
|
|
493
|
-
|
|
494
|
-
|
|
661
|
+
mode:
|
|
662
|
+
(0, _utils2.get)(profile, "webRTC.mode") === "alerted"
|
|
663
|
+
? "public"
|
|
664
|
+
: (0, _utils2.get)(profile, "webRTC.mode"),
|
|
665
|
+
publicIP: (0, _utils2.get)(profile, "webRTC.fillBasedOnIp")
|
|
666
|
+
? this._tz.ip
|
|
667
|
+
: (0, _utils2.get)(profile, "webRTC.publicIp"),
|
|
668
|
+
localIps: (0, _utils2.get)(profile, "webRTC.localIps", []),
|
|
495
669
|
};
|
|
496
670
|
debug("profile.webRtc=", profile.webRtc);
|
|
497
671
|
debug("profile.timezone=", profile.timezone);
|
|
498
672
|
debug("profile.mediaDevices=", profile.mediaDevices);
|
|
499
673
|
const audioContext = profile.audioContext || {};
|
|
500
|
-
const {
|
|
501
|
-
mode: audioCtxMode = "off",
|
|
502
|
-
noise: audioCtxNoise
|
|
503
|
-
} = audioContext;
|
|
674
|
+
const { mode: audioCtxMode = "off", noise: audioCtxNoise } = audioContext;
|
|
504
675
|
if (profile.timezone.fillBasedOnIp === false) {
|
|
505
676
|
profile.timezone = {
|
|
506
|
-
id: profile.timezone.timezone
|
|
677
|
+
id: profile.timezone.timezone,
|
|
507
678
|
};
|
|
508
679
|
} else {
|
|
509
680
|
profile.timezone = {
|
|
510
|
-
id: this._tz.timezone
|
|
681
|
+
id: this._tz.timezone,
|
|
511
682
|
};
|
|
512
683
|
}
|
|
513
684
|
profile.webgl_noise_value = profile.webGL.noise;
|
|
@@ -516,24 +687,30 @@ class GoLogin {
|
|
|
516
687
|
profile.canvasNoise = profile.canvas.noise;
|
|
517
688
|
profile.audioContext = {
|
|
518
689
|
enable: audioCtxMode !== "off",
|
|
519
|
-
noiseValue: audioCtxNoise
|
|
690
|
+
noiseValue: audioCtxNoise,
|
|
520
691
|
};
|
|
521
692
|
profile.webgl = {
|
|
522
693
|
metadata: {
|
|
523
694
|
vendor: (0, _utils2.get)(profile, "webGLMetadata.vendor"),
|
|
524
695
|
renderer: (0, _utils2.get)(profile, "webGLMetadata.renderer"),
|
|
525
|
-
mode: (0, _utils2.get)(profile, "webGLMetadata.mode") === "mask"
|
|
526
|
-
}
|
|
696
|
+
mode: (0, _utils2.get)(profile, "webGLMetadata.mode") === "mask",
|
|
697
|
+
},
|
|
527
698
|
};
|
|
528
699
|
profile.custom_fonts = {
|
|
529
|
-
enable: !!fonts?.enableMasking
|
|
700
|
+
enable: !!fonts?.enableMasking,
|
|
530
701
|
};
|
|
531
702
|
const gologin = this.convertPreferences(profile);
|
|
532
|
-
debug(
|
|
703
|
+
debug(
|
|
704
|
+
`Writing profile for screenWidth ${profilePath}`,
|
|
705
|
+
JSON.stringify(gologin)
|
|
706
|
+
);
|
|
533
707
|
gologin.screenWidth = this.resolution.width;
|
|
534
708
|
gologin.screenHeight = this.resolution.height;
|
|
535
709
|
debug("writeCookiesFromServer", this.writeCookiesFromServer);
|
|
536
|
-
this.cookiesFilePath = await (0, _cookiesManager.getCookiesFilePath)(
|
|
710
|
+
this.cookiesFilePath = await (0, _cookiesManager.getCookiesFilePath)(
|
|
711
|
+
this.profile_id,
|
|
712
|
+
this.tmpdir
|
|
713
|
+
);
|
|
537
714
|
if (this.writeCookiesFromServer) {
|
|
538
715
|
await this.writeCookiesToFile(profile.cookies?.cookies);
|
|
539
716
|
}
|
|
@@ -543,7 +720,11 @@ class GoLogin {
|
|
|
543
720
|
this.isEmptyFonts = true;
|
|
544
721
|
}
|
|
545
722
|
try {
|
|
546
|
-
await (0, _browserUserDataManager.composeFonts)(
|
|
723
|
+
await (0, _browserUserDataManager.composeFonts)(
|
|
724
|
+
families,
|
|
725
|
+
profilePath,
|
|
726
|
+
this.differentOs
|
|
727
|
+
);
|
|
547
728
|
} catch (e) {
|
|
548
729
|
console.trace(e);
|
|
549
730
|
}
|
|
@@ -560,14 +741,31 @@ class GoLogin {
|
|
|
560
741
|
const isMAC = OS_PLATFORM === "darwin";
|
|
561
742
|
const checkAutoLangResult = (0, _browser.checkAutoLang)(gologin, this._tz);
|
|
562
743
|
this.browserLang = isMAC ? "en-US" : checkAutoLangResult;
|
|
563
|
-
await writeFile(
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
744
|
+
await writeFile(
|
|
745
|
+
(0, _path.join)(profilePath, "Default", "Preferences"),
|
|
746
|
+
JSON.stringify(
|
|
747
|
+
Object.assign(preferences, {
|
|
748
|
+
gologin,
|
|
749
|
+
})
|
|
750
|
+
)
|
|
751
|
+
);
|
|
752
|
+
const bookmarksParsedData = await (0, _utils.getCurrentProfileBookmarks)(
|
|
753
|
+
this.bookmarksFilePath
|
|
754
|
+
);
|
|
567
755
|
const bookmarksFromDb = profile.bookmarks?.bookmark_bar;
|
|
568
|
-
bookmarksParsedData.roots = bookmarksFromDb
|
|
569
|
-
|
|
570
|
-
|
|
756
|
+
bookmarksParsedData.roots = bookmarksFromDb
|
|
757
|
+
? profile.bookmarks
|
|
758
|
+
: bookmarksParsedData.roots;
|
|
759
|
+
await writeFile(
|
|
760
|
+
this.bookmarksFilePath,
|
|
761
|
+
JSON.stringify(bookmarksParsedData)
|
|
762
|
+
);
|
|
763
|
+
debug(
|
|
764
|
+
"Profile ready. Path: ",
|
|
765
|
+
profilePath,
|
|
766
|
+
"PROXY",
|
|
767
|
+
JSON.stringify((0, _utils2.get)(preferences, "gologin.proxy"))
|
|
768
|
+
);
|
|
571
769
|
return profilePath;
|
|
572
770
|
}
|
|
573
771
|
async commitProfile() {
|
|
@@ -600,7 +798,7 @@ class GoLogin {
|
|
|
600
798
|
debug("CHECKING PORT AVAILABLE", port);
|
|
601
799
|
try {
|
|
602
800
|
const portAvailable = await (0, _utils2.isPortReachable)(port, {
|
|
603
|
-
host: "localhost"
|
|
801
|
+
host: "localhost",
|
|
604
802
|
});
|
|
605
803
|
if (portAvailable) {
|
|
606
804
|
debug(`PORT ${port} IS OPEN`);
|
|
@@ -646,7 +844,7 @@ class GoLogin {
|
|
|
646
844
|
const response = await _requestretry.default.get(TIMEZONE_URL, {
|
|
647
845
|
proxy: proxyUrl,
|
|
648
846
|
timeout: 20 * 1000,
|
|
649
|
-
maxAttempts: 5
|
|
847
|
+
maxAttempts: 5,
|
|
650
848
|
});
|
|
651
849
|
const result = JSON.parse(response.body);
|
|
652
850
|
data = {
|
|
@@ -657,13 +855,13 @@ class GoLogin {
|
|
|
657
855
|
timezone: (0, _timezone.tzlookup)(result.latitude, result.longitude),
|
|
658
856
|
ll: [result.latitude, result.longitude],
|
|
659
857
|
languages: "en",
|
|
660
|
-
accuracy: 100
|
|
661
|
-
}
|
|
858
|
+
accuracy: 100,
|
|
859
|
+
},
|
|
662
860
|
};
|
|
663
861
|
} else {
|
|
664
862
|
const response = await _requestretry.default.get(TIMEZONE_URL, {
|
|
665
863
|
timeout: 20 * 1000,
|
|
666
|
-
maxAttempts: 5
|
|
864
|
+
maxAttempts: 5,
|
|
667
865
|
});
|
|
668
866
|
const result = JSON.parse(response.body);
|
|
669
867
|
data = {
|
|
@@ -674,8 +872,8 @@ class GoLogin {
|
|
|
674
872
|
timezone: (0, _timezone.tzlookup)(result.latitude, result.longitude),
|
|
675
873
|
ll: [result.latitude, result.longitude],
|
|
676
874
|
languages: "en",
|
|
677
|
-
accuracy: 100
|
|
678
|
-
}
|
|
875
|
+
accuracy: 100,
|
|
876
|
+
},
|
|
679
877
|
};
|
|
680
878
|
}
|
|
681
879
|
debug("getTimeZone finish", data.body);
|
|
@@ -683,12 +881,7 @@ class GoLogin {
|
|
|
683
881
|
return this._tz.timezone;
|
|
684
882
|
}
|
|
685
883
|
async getTimezoneWithSocks(params) {
|
|
686
|
-
const {
|
|
687
|
-
host,
|
|
688
|
-
port,
|
|
689
|
-
username = "",
|
|
690
|
-
password = ""
|
|
691
|
-
} = params;
|
|
884
|
+
const { host, port, username = "", password = "" } = params;
|
|
692
885
|
let body;
|
|
693
886
|
let proxy = "socks://";
|
|
694
887
|
if (username) {
|
|
@@ -698,25 +891,29 @@ class GoLogin {
|
|
|
698
891
|
proxy += host + ":" + port;
|
|
699
892
|
const agent = new _socksProxyAgent.SocksProxyAgent(proxy);
|
|
700
893
|
const checkData = await new Promise((resolve, reject) => {
|
|
701
|
-
(0, _https.get)(
|
|
702
|
-
|
|
703
|
-
|
|
704
|
-
|
|
705
|
-
|
|
706
|
-
|
|
707
|
-
res
|
|
708
|
-
let
|
|
709
|
-
|
|
710
|
-
|
|
711
|
-
|
|
712
|
-
|
|
713
|
-
|
|
714
|
-
|
|
715
|
-
|
|
716
|
-
|
|
894
|
+
(0, _https.get)(
|
|
895
|
+
TIMEZONE_URL,
|
|
896
|
+
{
|
|
897
|
+
agent,
|
|
898
|
+
timeout: 10000,
|
|
899
|
+
},
|
|
900
|
+
(res) => {
|
|
901
|
+
let resultResponse = "";
|
|
902
|
+
res.on("data", (data) => (resultResponse += data));
|
|
903
|
+
res.on("end", () => {
|
|
904
|
+
let parsedData;
|
|
905
|
+
try {
|
|
906
|
+
parsedData = JSON.parse(resultResponse);
|
|
907
|
+
} catch (e) {
|
|
908
|
+
reject(e);
|
|
909
|
+
}
|
|
910
|
+
resolve({
|
|
911
|
+
...res,
|
|
912
|
+
body: parsedData,
|
|
913
|
+
});
|
|
717
914
|
});
|
|
718
|
-
}
|
|
719
|
-
|
|
915
|
+
}
|
|
916
|
+
).on("error", (err) => reject(err));
|
|
720
917
|
});
|
|
721
918
|
body = checkData.body || {};
|
|
722
919
|
if (!body.ip && checkData.statusCode.toString().startsWith("4")) {
|
|
@@ -728,20 +925,24 @@ class GoLogin {
|
|
|
728
925
|
}
|
|
729
926
|
async spawnArguments() {
|
|
730
927
|
const profile_path = this.profilePath();
|
|
731
|
-
let {
|
|
732
|
-
proxy
|
|
733
|
-
} = this;
|
|
928
|
+
let { proxy } = this;
|
|
734
929
|
proxy = `${proxy.mode}://${proxy.host}:${proxy.port}`;
|
|
735
930
|
const env = {};
|
|
736
|
-
Object.keys(process.env).forEach(key => {
|
|
931
|
+
Object.keys(process.env).forEach((key) => {
|
|
737
932
|
env[key] = process.env[key];
|
|
738
933
|
});
|
|
739
|
-
const tz = await this.getTimeZone(this.proxy).catch(e => {
|
|
934
|
+
const tz = await this.getTimeZone(this.proxy).catch((e) => {
|
|
740
935
|
console.error("Proxy Error. Check it and try again.");
|
|
741
936
|
throw e;
|
|
742
937
|
});
|
|
743
938
|
env.TZ = tz;
|
|
744
|
-
let params = [
|
|
939
|
+
let params = [
|
|
940
|
+
`--proxy-server=${proxy}`,
|
|
941
|
+
`--user-data-dir=${profile_path}`,
|
|
942
|
+
"--password-store=basic",
|
|
943
|
+
`--tz=${tz}`,
|
|
944
|
+
"--lang=en",
|
|
945
|
+
];
|
|
745
946
|
if (Array.isArray(this.extra_params) && this.extra_params.length) {
|
|
746
947
|
params = params.concat(this.extra_params);
|
|
747
948
|
}
|
|
@@ -751,42 +952,63 @@ class GoLogin {
|
|
|
751
952
|
return params;
|
|
752
953
|
}
|
|
753
954
|
async spawnBrowser() {
|
|
754
|
-
let {
|
|
755
|
-
remote_debugging_port,
|
|
756
|
-
customArgs
|
|
757
|
-
} = this;
|
|
955
|
+
let { remote_debugging_port, customArgs } = this;
|
|
758
956
|
if (!remote_debugging_port) {
|
|
759
957
|
remote_debugging_port = await this.getRandomPort();
|
|
760
958
|
}
|
|
761
959
|
const profile_path = this.profilePath();
|
|
762
|
-
let {
|
|
763
|
-
proxy
|
|
764
|
-
} = this;
|
|
960
|
+
let { proxy } = this;
|
|
765
961
|
let proxy_host = "";
|
|
766
962
|
if (proxy) {
|
|
767
963
|
proxy_host = this.proxy.host;
|
|
768
964
|
proxy = `${proxy.mode}://${proxy.host}:${proxy.port}`;
|
|
769
965
|
}
|
|
770
966
|
this.port = remote_debugging_port;
|
|
771
|
-
const ORBITA_BROWSER =
|
|
967
|
+
const ORBITA_BROWSER =
|
|
968
|
+
this.executablePath || this.browserChecker.getOrbitaPath;
|
|
772
969
|
debug(`ORBITA_BROWSER=${ORBITA_BROWSER}`);
|
|
773
970
|
const env = {};
|
|
774
|
-
Object.keys(process.env).forEach(key => {
|
|
971
|
+
Object.keys(process.env).forEach((key) => {
|
|
775
972
|
env[key] = process.env[key];
|
|
776
973
|
});
|
|
777
|
-
const tz = await this.getTimeZone(this.proxy).catch(e => {
|
|
974
|
+
const tz = await this.getTimeZone(this.proxy).catch((e) => {
|
|
778
975
|
console.error("Proxy Error. Check it and try again.");
|
|
779
976
|
throw e;
|
|
780
977
|
});
|
|
781
978
|
env.TZ = tz;
|
|
782
979
|
if (this.vnc_port) {
|
|
783
980
|
const script_path = (0, _path.resolve)(__dirname, "./run.sh");
|
|
784
|
-
debug(
|
|
785
|
-
|
|
786
|
-
|
|
787
|
-
|
|
981
|
+
debug(
|
|
982
|
+
"RUNNING",
|
|
983
|
+
script_path,
|
|
984
|
+
ORBITA_BROWSER,
|
|
985
|
+
remote_debugging_port,
|
|
986
|
+
proxy,
|
|
987
|
+
profile_path,
|
|
988
|
+
this.vnc_port
|
|
989
|
+
);
|
|
990
|
+
(0, _child_process.execFile)(
|
|
991
|
+
script_path,
|
|
992
|
+
[
|
|
993
|
+
ORBITA_BROWSER,
|
|
994
|
+
remote_debugging_port,
|
|
995
|
+
proxy,
|
|
996
|
+
profile_path,
|
|
997
|
+
this.vnc_port,
|
|
998
|
+
tz,
|
|
999
|
+
],
|
|
1000
|
+
{
|
|
1001
|
+
env,
|
|
1002
|
+
}
|
|
1003
|
+
);
|
|
788
1004
|
} else {
|
|
789
|
-
let params = [
|
|
1005
|
+
let params = [
|
|
1006
|
+
`--remote-debugging-port=${remote_debugging_port}`,
|
|
1007
|
+
`--user-data-dir=${profile_path}`,
|
|
1008
|
+
"--password-store=basic",
|
|
1009
|
+
`--tz=${tz}`,
|
|
1010
|
+
`--lang=${this.browserLang}`,
|
|
1011
|
+
];
|
|
790
1012
|
if (this.extensionPathsToInstall.length) {
|
|
791
1013
|
if (Array.isArray(this.extra_params) && this.extra_params.length) {
|
|
792
1014
|
this.extra_params.forEach((param, index) => {
|
|
@@ -795,11 +1017,16 @@ class GoLogin {
|
|
|
795
1017
|
}
|
|
796
1018
|
const [_, extPathsString] = param.split("=");
|
|
797
1019
|
const extPathsArray = extPathsString.split(",");
|
|
798
|
-
this.extensionPathsToInstall = [
|
|
1020
|
+
this.extensionPathsToInstall = [
|
|
1021
|
+
...this.extensionPathsToInstall,
|
|
1022
|
+
...extPathsArray,
|
|
1023
|
+
];
|
|
799
1024
|
this.extra_params.splice(index, 1);
|
|
800
1025
|
});
|
|
801
1026
|
}
|
|
802
|
-
params.push(
|
|
1027
|
+
params.push(
|
|
1028
|
+
`--load-extension=${this.extensionPathsToInstall.join(",")}`
|
|
1029
|
+
);
|
|
803
1030
|
}
|
|
804
1031
|
if (this.fontsMasking) {
|
|
805
1032
|
let arg = "--font-masking-mode=2";
|
|
@@ -825,18 +1052,21 @@ class GoLogin {
|
|
|
825
1052
|
params.push(...new Set(customArgs));
|
|
826
1053
|
console.log(params);
|
|
827
1054
|
const child = (0, _child_process.execFile)(ORBITA_BROWSER, params, {
|
|
828
|
-
env
|
|
1055
|
+
env,
|
|
829
1056
|
});
|
|
830
1057
|
this.processSpawned = child;
|
|
831
1058
|
// const child = spawn(ORBITA_BROWSER, params, { env, shell: true });
|
|
832
|
-
child.stdout.on("data", data => debug(data.toString()));
|
|
1059
|
+
child.stdout.on("data", (data) => debug(data.toString()));
|
|
833
1060
|
debug("SPAWN CMD", ORBITA_BROWSER, params.join(" "));
|
|
834
1061
|
}
|
|
835
1062
|
if (this.waitWebsocket) {
|
|
836
1063
|
debug("GETTING WS URL FROM BROWSER");
|
|
837
|
-
const data = await _requestretry.default.get(
|
|
838
|
-
json
|
|
839
|
-
|
|
1064
|
+
const data = await _requestretry.default.get(
|
|
1065
|
+
`http://127.0.0.1:${remote_debugging_port}/json/version`,
|
|
1066
|
+
{
|
|
1067
|
+
json: true,
|
|
1068
|
+
}
|
|
1069
|
+
);
|
|
840
1070
|
debug("WS IS", (0, _utils2.get)(data, "body.webSocketDebuggerUrl", ""));
|
|
841
1071
|
this.is_active = true;
|
|
842
1072
|
return (0, _utils2.get)(data, "body.webSocketDebuggerUrl", "");
|
|
@@ -848,16 +1078,24 @@ class GoLogin {
|
|
|
848
1078
|
return this.spawnBrowser();
|
|
849
1079
|
}
|
|
850
1080
|
async clearProfileFiles() {
|
|
851
|
-
await (0, _rimraf.default)(
|
|
852
|
-
|
|
1081
|
+
await (0, _rimraf.default)(
|
|
1082
|
+
(0, _path.join)(this.tmpdir, `gologin_profile_${this.profile_id}`),
|
|
1083
|
+
() => null
|
|
1084
|
+
);
|
|
1085
|
+
await (0, _rimraf.default)(
|
|
1086
|
+
(0, _path.join)(this.tmpdir, `gologin_${this.profile_id}_upload.zip`),
|
|
1087
|
+
() => null
|
|
1088
|
+
);
|
|
853
1089
|
}
|
|
854
1090
|
async stopAndCommit(options, local = false) {
|
|
855
1091
|
if (this.is_stopping) {
|
|
856
1092
|
return true;
|
|
857
1093
|
}
|
|
858
|
-
const is_posting =
|
|
859
|
-
|
|
860
|
-
|
|
1094
|
+
const is_posting =
|
|
1095
|
+
options.posting ||
|
|
1096
|
+
options.postings ||
|
|
1097
|
+
// backward compability
|
|
1098
|
+
false;
|
|
861
1099
|
if (this.uploadCookiesToServer) {
|
|
862
1100
|
const updateResult = await this.uploadProfileDataToServer();
|
|
863
1101
|
this.storageGatewayUrl = updateResult.storageGateway.url;
|
|
@@ -872,42 +1110,58 @@ class GoLogin {
|
|
|
872
1110
|
await delay(3000);
|
|
873
1111
|
await this.clearProfileFiles();
|
|
874
1112
|
if (!local) {
|
|
875
|
-
await (0, _rimraf.default)(
|
|
1113
|
+
await (0, _rimraf.default)(
|
|
1114
|
+
(0, _path.join)(this.tmpdir, `gologin_${this.profile_id}.zip`),
|
|
1115
|
+
() => null
|
|
1116
|
+
);
|
|
876
1117
|
}
|
|
877
1118
|
debug(`PROFILE ${this.profile_id} STOPPED AND CLEAR`);
|
|
878
1119
|
return false;
|
|
879
1120
|
}
|
|
880
1121
|
async uploadProfileDataToServer() {
|
|
881
|
-
const cookies = await (0, _cookiesManager.loadCookiesFromFile)(
|
|
882
|
-
|
|
1122
|
+
const cookies = await (0, _cookiesManager.loadCookiesFromFile)(
|
|
1123
|
+
this.cookiesFilePath
|
|
1124
|
+
);
|
|
1125
|
+
const bookmarks = await (0, _utils.getCurrentProfileBookmarks)(
|
|
1126
|
+
this.bookmarksFilePath
|
|
1127
|
+
);
|
|
883
1128
|
const body = {
|
|
884
1129
|
cookies,
|
|
885
1130
|
bookmarks,
|
|
886
1131
|
isCookiesEncrypted: true,
|
|
887
|
-
isStorageGateway: true
|
|
1132
|
+
isStorageGateway: true,
|
|
888
1133
|
};
|
|
889
|
-
const updateResult = await _requestretry.default
|
|
890
|
-
|
|
891
|
-
|
|
892
|
-
|
|
893
|
-
|
|
894
|
-
|
|
895
|
-
|
|
896
|
-
|
|
897
|
-
|
|
898
|
-
|
|
899
|
-
|
|
900
|
-
|
|
901
|
-
|
|
1134
|
+
const updateResult = await _requestretry.default
|
|
1135
|
+
.post(
|
|
1136
|
+
`${_common.API_URL}/browser/features/profile/${this.profile_id}/update_after_close`,
|
|
1137
|
+
{
|
|
1138
|
+
headers: {
|
|
1139
|
+
Authorization: `Bearer ${this.access_token}`,
|
|
1140
|
+
"User-Agent": "gologin-api",
|
|
1141
|
+
},
|
|
1142
|
+
json: body,
|
|
1143
|
+
maxAttempts: 3,
|
|
1144
|
+
retryDelay: 2000,
|
|
1145
|
+
timeout: 20 * 1000,
|
|
1146
|
+
}
|
|
1147
|
+
)
|
|
1148
|
+
.catch((e) => {
|
|
1149
|
+
console.log(e);
|
|
1150
|
+
return e;
|
|
1151
|
+
});
|
|
902
1152
|
return updateResult.body;
|
|
903
1153
|
}
|
|
904
1154
|
async stopBrowser() {
|
|
905
1155
|
if (!this.port) {
|
|
906
1156
|
throw new Error("Empty GoLogin port");
|
|
907
1157
|
}
|
|
908
|
-
const ls = await (0, _child_process.spawn)(
|
|
909
|
-
|
|
910
|
-
|
|
1158
|
+
const ls = await (0, _child_process.spawn)(
|
|
1159
|
+
"fuser",
|
|
1160
|
+
["-k TERM", `-n tcp ${this.port}`],
|
|
1161
|
+
{
|
|
1162
|
+
shell: true,
|
|
1163
|
+
}
|
|
1164
|
+
);
|
|
911
1165
|
debug("browser killed");
|
|
912
1166
|
}
|
|
913
1167
|
killBrowser() {
|
|
@@ -927,24 +1181,57 @@ class GoLogin {
|
|
|
927
1181
|
await this.stopAndCommit(options, local).catch(console.error);
|
|
928
1182
|
}
|
|
929
1183
|
async sanitizeProfile() {
|
|
930
|
-
const remove_dirs = [
|
|
1184
|
+
const remove_dirs = [
|
|
1185
|
+
`${SEPARATOR}Default${SEPARATOR}Cache`,
|
|
1186
|
+
`${SEPARATOR}Default${SEPARATOR}Service Worker`,
|
|
1187
|
+
`${SEPARATOR}Default${SEPARATOR}Code Cache`,
|
|
1188
|
+
`${SEPARATOR}Default${SEPARATOR}GPUCache`,
|
|
1189
|
+
`${SEPARATOR}Default${SEPARATOR}Extensions`,
|
|
1190
|
+
`${SEPARATOR}Default${SEPARATOR}IndexedDB`,
|
|
1191
|
+
`${SEPARATOR}Default${SEPARATOR}GPUCache`,
|
|
1192
|
+
`${SEPARATOR}Default${SEPARATOR}DawnCache`,
|
|
1193
|
+
`${SEPARATOR}Default${SEPARATOR}fonts_config`,
|
|
1194
|
+
`${SEPARATOR}GrShaderCache`,
|
|
1195
|
+
`${SEPARATOR}ShaderCache`,
|
|
1196
|
+
`${SEPARATOR}biahpgbdmdkfgndcmfiipgcebobojjkp`,
|
|
1197
|
+
`${SEPARATOR}afalakplffnnnlkncjhbmahjfjhmlkal`,
|
|
1198
|
+
`${SEPARATOR}cffkpbalmllkdoenhmdmpbkajipdjfam`,
|
|
1199
|
+
`${SEPARATOR}Dictionaries`,
|
|
1200
|
+
`${SEPARATOR}enkheaiicpeffbfgjiklngbpkilnbkoi`,
|
|
1201
|
+
`${SEPARATOR}oofiananboodjbbmdelgdommihjbkfag`,
|
|
1202
|
+
`${SEPARATOR}SafetyTips`,
|
|
1203
|
+
`${SEPARATOR}fonts`,
|
|
1204
|
+
`${SEPARATOR}BrowserMetrics`,
|
|
1205
|
+
`${SEPARATOR}BrowserMetrics-spare.pma`,
|
|
1206
|
+
];
|
|
931
1207
|
const that = this;
|
|
932
|
-
await Promise.all(
|
|
933
|
-
|
|
934
|
-
|
|
935
|
-
|
|
936
|
-
|
|
937
|
-
|
|
938
|
-
|
|
939
|
-
|
|
940
|
-
|
|
1208
|
+
await Promise.all(
|
|
1209
|
+
remove_dirs.map((d) => {
|
|
1210
|
+
const path_to_remove = `${that.profilePath()}${d}`;
|
|
1211
|
+
return new Promise((resolve) => {
|
|
1212
|
+
debug("DROPPING", path_to_remove);
|
|
1213
|
+
(0, _rimraf.default)(
|
|
1214
|
+
path_to_remove,
|
|
1215
|
+
{
|
|
1216
|
+
maxBusyTries: 100,
|
|
1217
|
+
},
|
|
1218
|
+
(e) => {
|
|
1219
|
+
// debug('DROPPING RESULT', e);
|
|
1220
|
+
resolve();
|
|
1221
|
+
}
|
|
1222
|
+
);
|
|
941
1223
|
});
|
|
942
|
-
})
|
|
943
|
-
|
|
1224
|
+
})
|
|
1225
|
+
);
|
|
944
1226
|
}
|
|
945
1227
|
async getProfileDataToUpdate() {
|
|
946
|
-
const zipPath = (0, _path.join)(
|
|
947
|
-
|
|
1228
|
+
const zipPath = (0, _path.join)(
|
|
1229
|
+
this.tmpdir,
|
|
1230
|
+
`gologin_${this.profile_id}_upload.zip`
|
|
1231
|
+
);
|
|
1232
|
+
const zipExists = await access(zipPath)
|
|
1233
|
+
.then(() => true)
|
|
1234
|
+
.catch(() => false);
|
|
948
1235
|
if (zipExists) {
|
|
949
1236
|
await unlink(zipPath);
|
|
950
1237
|
}
|
|
@@ -956,13 +1243,16 @@ class GoLogin {
|
|
|
956
1243
|
return fileBuff;
|
|
957
1244
|
}
|
|
958
1245
|
async profileExists() {
|
|
959
|
-
const profileResponse = await _requestretry.default.post(
|
|
960
|
-
|
|
961
|
-
|
|
962
|
-
|
|
963
|
-
|
|
964
|
-
|
|
965
|
-
|
|
1246
|
+
const profileResponse = await _requestretry.default.post(
|
|
1247
|
+
`${_common.API_URL}/browser`,
|
|
1248
|
+
{
|
|
1249
|
+
headers: {
|
|
1250
|
+
Authorization: `Bearer ${this.access_token}`,
|
|
1251
|
+
"User-Agent": "gologin-api",
|
|
1252
|
+
},
|
|
1253
|
+
json: {},
|
|
1254
|
+
}
|
|
1255
|
+
);
|
|
966
1256
|
if (profileResponse.statusCode !== 200) {
|
|
967
1257
|
return false;
|
|
968
1258
|
}
|
|
@@ -981,8 +1271,8 @@ class GoLogin {
|
|
|
981
1271
|
const fingerprint = await _requestretry.default.get(url, {
|
|
982
1272
|
headers: {
|
|
983
1273
|
Authorization: `Bearer ${this.access_token}`,
|
|
984
|
-
"User-Agent": "gologin-api"
|
|
985
|
-
}
|
|
1274
|
+
"User-Agent": "gologin-api",
|
|
1275
|
+
},
|
|
986
1276
|
});
|
|
987
1277
|
return JSON.parse(fingerprint.body);
|
|
988
1278
|
}
|
|
@@ -996,12 +1286,7 @@ class GoLogin {
|
|
|
996
1286
|
if (fingerprint.statusCode === 401) {
|
|
997
1287
|
throw new Error("invalid token");
|
|
998
1288
|
}
|
|
999
|
-
const {
|
|
1000
|
-
navigator,
|
|
1001
|
-
fonts,
|
|
1002
|
-
webGLMetadata,
|
|
1003
|
-
webRTC
|
|
1004
|
-
} = fingerprint;
|
|
1289
|
+
const { navigator, fonts, webGLMetadata, webRTC } = fingerprint;
|
|
1005
1290
|
let deviceMemory = navigator.deviceMemory || 2;
|
|
1006
1291
|
if (deviceMemory < 1) {
|
|
1007
1292
|
deviceMemory = 1;
|
|
@@ -1016,20 +1301,20 @@ class GoLogin {
|
|
|
1016
1301
|
name: "default_name",
|
|
1017
1302
|
notes: "auto generated",
|
|
1018
1303
|
fonts: {
|
|
1019
|
-
families: fonts
|
|
1304
|
+
families: fonts,
|
|
1020
1305
|
},
|
|
1021
1306
|
webRTC: {
|
|
1022
1307
|
...webRTC,
|
|
1023
|
-
mode: "alerted"
|
|
1024
|
-
}
|
|
1308
|
+
mode: "alerted",
|
|
1309
|
+
},
|
|
1025
1310
|
};
|
|
1026
1311
|
const user_agent = options.navigator?.userAgent;
|
|
1027
1312
|
const orig_user_agent = json.navigator.userAgent;
|
|
1028
|
-
Object.keys(options).forEach(key => {
|
|
1313
|
+
Object.keys(options).forEach((key) => {
|
|
1029
1314
|
if (typeof json[key] === "object") {
|
|
1030
1315
|
json[key] = {
|
|
1031
1316
|
...json[key],
|
|
1032
|
-
...options[key]
|
|
1317
|
+
...options[key],
|
|
1033
1318
|
};
|
|
1034
1319
|
return;
|
|
1035
1320
|
}
|
|
@@ -1038,87 +1323,112 @@ class GoLogin {
|
|
|
1038
1323
|
if (user_agent === "random") {
|
|
1039
1324
|
json.navigator.userAgent = orig_user_agent;
|
|
1040
1325
|
}
|
|
1041
|
-
const response = await _requestretry.default.post(
|
|
1042
|
-
|
|
1043
|
-
|
|
1044
|
-
|
|
1045
|
-
|
|
1046
|
-
|
|
1047
|
-
|
|
1326
|
+
const response = await _requestretry.default.post(
|
|
1327
|
+
`${_common.API_URL}/browser`,
|
|
1328
|
+
{
|
|
1329
|
+
headers: {
|
|
1330
|
+
Authorization: `Bearer ${this.access_token}`,
|
|
1331
|
+
"User-Agent": "gologin-api",
|
|
1332
|
+
},
|
|
1333
|
+
json,
|
|
1334
|
+
}
|
|
1335
|
+
);
|
|
1048
1336
|
if (response.statusCode === 400) {
|
|
1049
|
-
throw new Error(
|
|
1337
|
+
throw new Error(
|
|
1338
|
+
`gologin failed account creation with status code, ${
|
|
1339
|
+
response.statusCode
|
|
1340
|
+
} DATA ${JSON.stringify(response.body.message)}`
|
|
1341
|
+
);
|
|
1050
1342
|
}
|
|
1051
1343
|
if (response.statusCode === 500) {
|
|
1052
|
-
throw new Error(
|
|
1344
|
+
throw new Error(
|
|
1345
|
+
`gologin failed account creation with status code, ${response.statusCode}`
|
|
1346
|
+
);
|
|
1053
1347
|
}
|
|
1054
1348
|
debug(JSON.stringify(response.body));
|
|
1055
1349
|
return response.body.id;
|
|
1056
1350
|
}
|
|
1057
1351
|
async createCustom(options) {
|
|
1058
1352
|
debug("createCustomProfile", options);
|
|
1059
|
-
const response = await _requestretry.default.post(
|
|
1060
|
-
|
|
1061
|
-
|
|
1062
|
-
|
|
1063
|
-
|
|
1064
|
-
|
|
1065
|
-
|
|
1353
|
+
const response = await _requestretry.default.post(
|
|
1354
|
+
`${_common.API_URL}/browser/custom`,
|
|
1355
|
+
{
|
|
1356
|
+
headers: {
|
|
1357
|
+
Authorization: `Bearer ${this.access_token}`,
|
|
1358
|
+
"User-Agent": "gologin-api",
|
|
1359
|
+
},
|
|
1360
|
+
json: options,
|
|
1361
|
+
}
|
|
1362
|
+
);
|
|
1066
1363
|
if (response.statusCode === 400) {
|
|
1067
|
-
throw new Error(
|
|
1364
|
+
throw new Error(
|
|
1365
|
+
`gologin failed account creation with status code, ${
|
|
1366
|
+
response.statusCode
|
|
1367
|
+
} DATA ${JSON.stringify(response.body.message)}`
|
|
1368
|
+
);
|
|
1068
1369
|
}
|
|
1069
1370
|
if (response.statusCode === 500) {
|
|
1070
|
-
throw new Error(
|
|
1371
|
+
throw new Error(
|
|
1372
|
+
`gologin failed account creation with status code, ${response.statusCode}`
|
|
1373
|
+
);
|
|
1071
1374
|
}
|
|
1072
1375
|
debug(JSON.stringify(response));
|
|
1073
1376
|
return response.body.id;
|
|
1074
1377
|
}
|
|
1075
1378
|
async quickCreateProfile(name = "") {
|
|
1076
1379
|
const osInfo = await (0, _common.getOsAdvanced)();
|
|
1077
|
-
const {
|
|
1078
|
-
os,
|
|
1079
|
-
osSpec
|
|
1080
|
-
} = osInfo;
|
|
1380
|
+
const { os, osSpec } = osInfo;
|
|
1081
1381
|
const resultName = name || "api-generated";
|
|
1082
|
-
return _requestretry.default
|
|
1083
|
-
|
|
1084
|
-
|
|
1085
|
-
|
|
1086
|
-
|
|
1087
|
-
|
|
1088
|
-
|
|
1089
|
-
|
|
1090
|
-
|
|
1091
|
-
|
|
1092
|
-
|
|
1382
|
+
return _requestretry.default
|
|
1383
|
+
.post(`${_common.API_URL}/browser/quick`, {
|
|
1384
|
+
headers: {
|
|
1385
|
+
Authorization: `Bearer ${this.access_token}`,
|
|
1386
|
+
"User-Agent": "gologin-api",
|
|
1387
|
+
},
|
|
1388
|
+
json: {
|
|
1389
|
+
os,
|
|
1390
|
+
osSpec,
|
|
1391
|
+
name: resultName,
|
|
1392
|
+
},
|
|
1393
|
+
})
|
|
1394
|
+
.then((res) => res.body);
|
|
1093
1395
|
}
|
|
1094
1396
|
async delete(pid) {
|
|
1095
1397
|
const profile_id = pid || this.profile_id;
|
|
1096
|
-
await _requestretry.default.delete(
|
|
1097
|
-
|
|
1098
|
-
|
|
1099
|
-
|
|
1398
|
+
await _requestretry.default.delete(
|
|
1399
|
+
`${_common.API_URL}/browser/${profile_id}`,
|
|
1400
|
+
{
|
|
1401
|
+
headers: {
|
|
1402
|
+
Authorization: `Bearer ${this.access_token}`,
|
|
1403
|
+
"User-Agent": "gologin-api",
|
|
1404
|
+
},
|
|
1100
1405
|
}
|
|
1101
|
-
|
|
1406
|
+
);
|
|
1102
1407
|
}
|
|
1103
1408
|
async update(options) {
|
|
1104
1409
|
this.profile_id = options.id;
|
|
1105
1410
|
const profile = await this.getProfile();
|
|
1106
1411
|
if (options.navigator) {
|
|
1107
|
-
Object.keys(options.navigator).map(e => {
|
|
1412
|
+
Object.keys(options.navigator).map((e) => {
|
|
1108
1413
|
profile.navigator[e] = options.navigator[e];
|
|
1109
1414
|
});
|
|
1110
1415
|
}
|
|
1111
|
-
Object.keys(options)
|
|
1112
|
-
|
|
1113
|
-
|
|
1416
|
+
Object.keys(options)
|
|
1417
|
+
.filter((el) => el !== "navigator")
|
|
1418
|
+
.forEach((el) => {
|
|
1419
|
+
profile[el] = options[el];
|
|
1420
|
+
});
|
|
1114
1421
|
debug("update profile", profile);
|
|
1115
|
-
const response = await _requestretry.default.put(
|
|
1116
|
-
|
|
1117
|
-
|
|
1118
|
-
|
|
1119
|
-
|
|
1422
|
+
const response = await _requestretry.default.put(
|
|
1423
|
+
`${_common.API_URL}/browser/${options.id}`,
|
|
1424
|
+
{
|
|
1425
|
+
json: profile,
|
|
1426
|
+
headers: {
|
|
1427
|
+
Authorization: `Bearer ${this.access_token}`,
|
|
1428
|
+
"User-Agent": "gologin-api",
|
|
1429
|
+
},
|
|
1120
1430
|
}
|
|
1121
|
-
|
|
1431
|
+
);
|
|
1122
1432
|
debug("response", JSON.stringify(response.body));
|
|
1123
1433
|
return response.body;
|
|
1124
1434
|
}
|
|
@@ -1131,24 +1441,28 @@ class GoLogin {
|
|
|
1131
1441
|
mode: profileGeolocationParams.mode,
|
|
1132
1442
|
latitude: Number(tzGeolocationParams.latitude),
|
|
1133
1443
|
longitude: Number(tzGeolocationParams.longitude),
|
|
1134
|
-
accuracy: Number(tzGeolocationParams.accuracy)
|
|
1444
|
+
accuracy: Number(tzGeolocationParams.accuracy),
|
|
1135
1445
|
};
|
|
1136
1446
|
}
|
|
1137
1447
|
return {
|
|
1138
1448
|
mode: profileGeolocationParams.mode,
|
|
1139
1449
|
latitude: profileGeolocationParams.latitude,
|
|
1140
1450
|
longitude: profileGeolocationParams.longitude,
|
|
1141
|
-
accuracy: profileGeolocationParams.accuracy
|
|
1451
|
+
accuracy: profileGeolocationParams.accuracy,
|
|
1142
1452
|
};
|
|
1143
1453
|
}
|
|
1144
1454
|
getViewPort() {
|
|
1145
1455
|
return {
|
|
1146
|
-
...this.resolution
|
|
1456
|
+
...this.resolution,
|
|
1147
1457
|
};
|
|
1148
1458
|
}
|
|
1149
1459
|
async postCookies(profileId, cookies) {
|
|
1150
|
-
const formattedCookies = cookies.map(cookie => {
|
|
1151
|
-
if (
|
|
1460
|
+
const formattedCookies = cookies.map((cookie) => {
|
|
1461
|
+
if (
|
|
1462
|
+
!["no_restriction", "lax", "strict", "unspecified"].includes(
|
|
1463
|
+
cookie.sameSite
|
|
1464
|
+
)
|
|
1465
|
+
) {
|
|
1152
1466
|
cookie.sameSite = "unspecified";
|
|
1153
1467
|
}
|
|
1154
1468
|
return cookie;
|
|
@@ -1157,7 +1471,7 @@ class GoLogin {
|
|
|
1157
1471
|
profileId,
|
|
1158
1472
|
cookies: formattedCookies,
|
|
1159
1473
|
API_BASE_URL: _common.API_URL,
|
|
1160
|
-
ACCESS_TOKEN: this.access_token
|
|
1474
|
+
ACCESS_TOKEN: this.access_token,
|
|
1161
1475
|
});
|
|
1162
1476
|
if (response.statusCode === 200) {
|
|
1163
1477
|
return response.body;
|
|
@@ -1165,14 +1479,14 @@ class GoLogin {
|
|
|
1165
1479
|
return {
|
|
1166
1480
|
status: "failure",
|
|
1167
1481
|
status_code: response.statusCode,
|
|
1168
|
-
body: response.body
|
|
1482
|
+
body: response.body,
|
|
1169
1483
|
};
|
|
1170
1484
|
}
|
|
1171
1485
|
async getCookies(profileId) {
|
|
1172
1486
|
const response = await (0, _browserUserDataManager.downloadCookies)({
|
|
1173
1487
|
profileId,
|
|
1174
1488
|
API_BASE_URL: _common.API_URL,
|
|
1175
|
-
ACCESS_TOKEN: this.access_token
|
|
1489
|
+
ACCESS_TOKEN: this.access_token,
|
|
1176
1490
|
});
|
|
1177
1491
|
return response.body;
|
|
1178
1492
|
}
|
|
@@ -1185,7 +1499,7 @@ class GoLogin {
|
|
|
1185
1499
|
}
|
|
1186
1500
|
return {
|
|
1187
1501
|
primary,
|
|
1188
|
-
secondary
|
|
1502
|
+
secondary,
|
|
1189
1503
|
};
|
|
1190
1504
|
}
|
|
1191
1505
|
async writeCookiesToFile(cookies) {
|
|
@@ -1195,19 +1509,27 @@ class GoLogin {
|
|
|
1195
1509
|
if (!cookies?.length) {
|
|
1196
1510
|
return;
|
|
1197
1511
|
}
|
|
1198
|
-
const resultCookies = cookies.map(el => ({
|
|
1512
|
+
const resultCookies = cookies.map((el) => ({
|
|
1199
1513
|
...el,
|
|
1200
|
-
value: Buffer.from(el.value)
|
|
1514
|
+
value: Buffer.from(el.value),
|
|
1201
1515
|
}));
|
|
1202
1516
|
let db;
|
|
1203
|
-
const profilePath = (0, _path.join)(
|
|
1517
|
+
const profilePath = (0, _path.join)(
|
|
1518
|
+
this.tmpdir,
|
|
1519
|
+
`gologin_profile_${this.profile_id}`
|
|
1520
|
+
);
|
|
1204
1521
|
const defaultFilePath = (0, _path.resolve)(profilePath, "Default");
|
|
1205
1522
|
const cookiesPaths = this.getCookiePath(defaultFilePath);
|
|
1206
1523
|
try {
|
|
1207
1524
|
db = await (0, _cookiesManager.getDB)(cookiesPaths.primary, false);
|
|
1208
|
-
const cookiesToInsert = await (0, _cookiesManager.getUniqueCookies)(
|
|
1525
|
+
const cookiesToInsert = await (0, _cookiesManager.getUniqueCookies)(
|
|
1526
|
+
resultCookies,
|
|
1527
|
+
cookiesPaths.primary
|
|
1528
|
+
);
|
|
1209
1529
|
if (cookiesToInsert.length) {
|
|
1210
|
-
const chunckInsertValues = (0, _cookiesManager.getChunckedInsertValues)(
|
|
1530
|
+
const chunckInsertValues = (0, _cookiesManager.getChunckedInsertValues)(
|
|
1531
|
+
cookiesToInsert
|
|
1532
|
+
);
|
|
1211
1533
|
for (const [query, queryParams] of chunckInsertValues) {
|
|
1212
1534
|
const insertStmt = await db.prepare(query);
|
|
1213
1535
|
await insertStmt.run(queryParams);
|
|
@@ -1218,29 +1540,44 @@ class GoLogin {
|
|
|
1218
1540
|
console.log(error.message);
|
|
1219
1541
|
} finally {
|
|
1220
1542
|
db && (await db.close());
|
|
1221
|
-
await copyFile(cookiesPaths.primary, cookiesPaths.secondary).catch(
|
|
1543
|
+
await copyFile(cookiesPaths.primary, cookiesPaths.secondary).catch(
|
|
1544
|
+
console.log
|
|
1545
|
+
);
|
|
1222
1546
|
}
|
|
1223
1547
|
}
|
|
1224
1548
|
async uploadProfileCookiesToServer() {
|
|
1225
|
-
const cookies = await (0, _cookiesManager.loadCookiesFromFile)(
|
|
1549
|
+
const cookies = await (0, _cookiesManager.loadCookiesFromFile)(
|
|
1550
|
+
this.cookiesFilePath
|
|
1551
|
+
);
|
|
1226
1552
|
if (!cookies.length) {
|
|
1227
1553
|
return;
|
|
1228
1554
|
}
|
|
1229
1555
|
return this.postCookies(this.profile_id, cookies);
|
|
1230
1556
|
}
|
|
1231
1557
|
async saveBookmarksToDb() {
|
|
1232
|
-
const bookmarksData = await (0, _utils.getCurrentProfileBookmarks)(
|
|
1558
|
+
const bookmarksData = await (0, _utils.getCurrentProfileBookmarks)(
|
|
1559
|
+
this.bookmarksFilePath
|
|
1560
|
+
);
|
|
1233
1561
|
const bookmarks = bookmarksData.roots || {};
|
|
1234
|
-
await (0, _browserApi.updateProfileBookmarks)(
|
|
1562
|
+
await (0, _browserApi.updateProfileBookmarks)(
|
|
1563
|
+
[this.profile_id],
|
|
1564
|
+
this.access_token,
|
|
1565
|
+
bookmarks
|
|
1566
|
+
);
|
|
1235
1567
|
}
|
|
1236
1568
|
async start() {
|
|
1237
1569
|
if (!this.executablePath) {
|
|
1238
1570
|
await this.checkBrowser();
|
|
1239
1571
|
}
|
|
1240
|
-
const ORBITA_BROWSER =
|
|
1241
|
-
|
|
1572
|
+
const ORBITA_BROWSER =
|
|
1573
|
+
this.executablePath || this.browserChecker.getOrbitaPath;
|
|
1574
|
+
const orbitaBrowserExists = await access(ORBITA_BROWSER)
|
|
1575
|
+
.then(() => true)
|
|
1576
|
+
.catch(() => false);
|
|
1242
1577
|
if (!orbitaBrowserExists) {
|
|
1243
|
-
throw new Error(
|
|
1578
|
+
throw new Error(
|
|
1579
|
+
`Orbita browser is not exists on path ${ORBITA_BROWSER}, check executablePath param`
|
|
1580
|
+
);
|
|
1244
1581
|
}
|
|
1245
1582
|
await this.createStartup();
|
|
1246
1583
|
// await this.createBrowserExtension();
|
|
@@ -1248,7 +1585,7 @@ class GoLogin {
|
|
|
1248
1585
|
this.setActive(true);
|
|
1249
1586
|
return {
|
|
1250
1587
|
status: "success",
|
|
1251
|
-
wsUrl
|
|
1588
|
+
wsUrl,
|
|
1252
1589
|
};
|
|
1253
1590
|
}
|
|
1254
1591
|
async startLocal() {
|
|
@@ -1258,18 +1595,21 @@ class GoLogin {
|
|
|
1258
1595
|
this.setActive(true);
|
|
1259
1596
|
return {
|
|
1260
1597
|
status: "success",
|
|
1261
|
-
wsUrl
|
|
1598
|
+
wsUrl,
|
|
1262
1599
|
};
|
|
1263
1600
|
}
|
|
1264
1601
|
async stop() {
|
|
1265
|
-
await new Promise(resolve => setTimeout(resolve, 500));
|
|
1266
|
-
await this.stopAndCommit(
|
|
1267
|
-
|
|
1268
|
-
|
|
1602
|
+
await new Promise((resolve) => setTimeout(resolve, 500));
|
|
1603
|
+
await this.stopAndCommit(
|
|
1604
|
+
{
|
|
1605
|
+
posting: true,
|
|
1606
|
+
},
|
|
1607
|
+
false
|
|
1608
|
+
);
|
|
1269
1609
|
}
|
|
1270
1610
|
async stopLocal(options) {
|
|
1271
1611
|
const opts = options || {
|
|
1272
|
-
posting: false
|
|
1612
|
+
posting: false,
|
|
1273
1613
|
};
|
|
1274
1614
|
await this.stopAndCommit(opts, true);
|
|
1275
1615
|
}
|
|
@@ -1294,38 +1634,60 @@ class GoLogin {
|
|
|
1294
1634
|
status: "failure",
|
|
1295
1635
|
wsUrl,
|
|
1296
1636
|
message: "Check proxy settings",
|
|
1297
|
-
profile_id: this.profile_id
|
|
1637
|
+
profile_id: this.profile_id,
|
|
1298
1638
|
};
|
|
1299
1639
|
}
|
|
1300
|
-
const remoteOrbitaUrlWithoutProtocol = remoteOrbitaUrl.replace(
|
|
1301
|
-
|
|
1640
|
+
const remoteOrbitaUrlWithoutProtocol = remoteOrbitaUrl.replace(
|
|
1641
|
+
"https://",
|
|
1642
|
+
""
|
|
1643
|
+
);
|
|
1644
|
+
wsUrl = wsUrl
|
|
1645
|
+
.replace("ws://", "wss://")
|
|
1646
|
+
.replace("127.0.0.1", remoteOrbitaUrlWithoutProtocol);
|
|
1302
1647
|
return wsUrl;
|
|
1303
1648
|
}
|
|
1304
1649
|
async stopRemote() {
|
|
1305
1650
|
debug(`stopRemote ${this.profile_id}`);
|
|
1306
|
-
const profileResponse = await _requestretry.default.delete(
|
|
1307
|
-
|
|
1308
|
-
|
|
1309
|
-
|
|
1651
|
+
const profileResponse = await _requestretry.default.delete(
|
|
1652
|
+
`${_common.API_URL}/browser/${this.profile_id}/web`,
|
|
1653
|
+
{
|
|
1654
|
+
headers: {
|
|
1655
|
+
Authorization: `Bearer ${this.access_token}`,
|
|
1656
|
+
"User-Agent": "gologin-api",
|
|
1657
|
+
},
|
|
1310
1658
|
}
|
|
1311
|
-
|
|
1659
|
+
);
|
|
1312
1660
|
console.log(`stopRemote ${profileResponse.body}`);
|
|
1313
1661
|
if (profileResponse.body) {
|
|
1314
1662
|
return JSON.parse(profileResponse.body);
|
|
1315
1663
|
}
|
|
1316
1664
|
}
|
|
1317
1665
|
getAvailableFonts() {
|
|
1318
|
-
return _fonts.fontsCollection
|
|
1666
|
+
return _fonts.fontsCollection
|
|
1667
|
+
.filter((elem) => elem.fileNames)
|
|
1668
|
+
.map((elem) => elem.name);
|
|
1319
1669
|
}
|
|
1320
1670
|
async changeProfileResolution(resolution) {
|
|
1321
|
-
return (0, _browserApi.updateProfileResolution)(
|
|
1671
|
+
return (0, _browserApi.updateProfileResolution)(
|
|
1672
|
+
this.profile_id,
|
|
1673
|
+
this.access_token,
|
|
1674
|
+
resolution
|
|
1675
|
+
);
|
|
1322
1676
|
}
|
|
1323
1677
|
async changeProfileUserAgent(userAgent) {
|
|
1324
|
-
return (0, _browserApi.updateProfileUserAgent)(
|
|
1678
|
+
return (0, _browserApi.updateProfileUserAgent)(
|
|
1679
|
+
this.profile_id,
|
|
1680
|
+
this.access_token,
|
|
1681
|
+
userAgent
|
|
1682
|
+
);
|
|
1325
1683
|
}
|
|
1326
1684
|
async changeProfileProxy(proxyData) {
|
|
1327
|
-
return (0, _browserApi.updateProfileProxy)(
|
|
1685
|
+
return (0, _browserApi.updateProfileProxy)(
|
|
1686
|
+
this.profile_id,
|
|
1687
|
+
this.access_token,
|
|
1688
|
+
proxyData
|
|
1689
|
+
);
|
|
1328
1690
|
}
|
|
1329
1691
|
}
|
|
1330
1692
|
exports.GoLogin = GoLogin;
|
|
1331
|
-
var _default = exports.default = GoLogin;
|
|
1693
|
+
var _default = (exports.default = GoLogin);
|