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