gologin 2.2.8 → 3.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/src/gologin.js CHANGED
@@ -1,39 +1,32 @@
1
- import * as Sentry from '@sentry/node';
2
1
  import { execFile, spawn } from 'child_process';
3
2
  import debugDefault from 'debug';
4
- import decompress from 'decompress';
5
- import decompressUnzip from 'decompress-unzip';
6
3
  import { existsSync, mkdirSync, promises as _promises } from 'fs';
7
4
  import { tmpdir } from 'os';
8
5
  import { join, resolve as _resolve, sep } from 'path';
9
- import rimraf from 'rimraf';
10
- import { SocksProxyAgent } from 'socks-proxy-agent';
11
6
 
12
- import { fontsCollection } from '../fonts.js';
13
7
  import { getCurrentProfileBookmarks } from './bookmarks/utils.js';
14
8
  import { updateProfileBookmarks, updateProfileProxy, updateProfileResolution, updateProfileUserAgent } from './browser/browser-api.js';
15
- import BrowserChecker from './browser/browser-checker.js';
16
9
  import {
17
- composeFonts, downloadCookies, setExtPathsAndRemoveDeleted, setOriginalExtPaths, uploadCookies,
10
+ downloadCookies, setExtPathsAndRemoveDeleted, setOriginalExtPaths, uploadCookies,
18
11
  } from './browser/browser-user-data-manager.js';
19
- import {
20
- createDBFile,
21
- getChunckedInsertValues,
22
- getCookiesFilePath,
23
- getDB,
24
- getUniqueCookies,
25
- loadCookiesFromFile,
26
- } from './cookies/cookies-manager.js';
27
- import ExtensionsManager from './extensions/extensions-manager.js';
28
- import { archiveProfile } from './profile/profile-archiver.js';
12
+ import { getProfileChromeExtensions } from './extensions/get-extensions.js';
29
13
  import { checkAutoLang, getIntlProfileConfig, securedOrbitaOpts } from './utils/browser.js';
30
14
  import { API_URL, ensureDirectoryExists, FALLBACK_API_URL, getOsAdvanced } from './utils/common.js';
31
15
  import { STORAGE_GATEWAY_BASE_URL } from './utils/constants.js';
32
- import { get, isPortReachable } from './utils/utils.js';
33
- export { exitAll, GologinApi } from './gologin-api.js';
34
- import { getProfileChromeExtensions } from './extensions/get-extensions.js';
35
16
  import { checkSocksProxy, makeRequest } from './utils/http.js';
36
- import { captureGroupedSentryError } from './utils/sentry.js';
17
+ import {
18
+ // ensureSentryInitialized,
19
+ loadBrowserChecker,
20
+ loadCookiesManager,
21
+ loadDecompress,
22
+ loadExtensionsManager,
23
+ loadProfileArchiver,
24
+ loadSocksProxyAgent,
25
+ preloadStartupDeps,
26
+ removePath,
27
+ } from './utils/lazy-deps.js';
28
+ import { get, isPortReachable } from './utils/utils.js';
29
+ // import { captureGroupedSentryError } from './utils/sentry.js';
37
30
  import { zeroProfileBookmarks } from './utils/zero-profile-bookmarks.js';
38
31
  import { zeroProfilePreferences } from './utils/zero-profile-preferences.js';
39
32
 
@@ -70,7 +63,8 @@ export class GoLogin {
70
63
  this.tmpdir = tmpdir();
71
64
  this.autoUpdateBrowser = !!options.autoUpdateBrowser;
72
65
  this.checkBrowserUpdate = options.checkBrowserUpdate ?? true;
73
- this.browserChecker = new BrowserChecker(options.skipOrbitaHashChecking);
66
+ this._skipOrbitaHashChecking = options.skipOrbitaHashChecking;
67
+ this._browserChecker = null;
74
68
  this.uploadCookiesToServer = options.uploadCookiesToServer || false;
75
69
  this.writeCookiesFromServer = options.writeCookiesFromServer ?? true;
76
70
  this.remote_debugging_port = options.remote_debugging_port || 0;
@@ -85,15 +79,6 @@ export class GoLogin {
85
79
  this.proxyCheckTimeout = options.proxyCheckTimeout || 13 * 1000;
86
80
  this.proxyCheckAttempts = options.proxyCheckAttempts || 3;
87
81
 
88
- if (process.env.DISABLE_TELEMETRY !== 'true') {
89
- Sentry.init({
90
- dsn: 'https://a13d5939a60ae4f6583e228597f1f2a0@sentry-new.amzn.pro/24',
91
- tracesSampleRate: 1.0,
92
- defaultIntegrations: false,
93
- release: process.env.npm_package_version || '2.1.34',
94
- });
95
- }
96
-
97
82
  if (options.tmpdir) {
98
83
  this.tmpdir = options.tmpdir;
99
84
  if (!existsSync(this.tmpdir)) {
@@ -107,8 +92,18 @@ export class GoLogin {
107
92
  debug('INIT GOLOGIN', this.profile_id);
108
93
  }
109
94
 
95
+ async getBrowserChecker() {
96
+ if (!this._browserChecker) {
97
+ const BrowserChecker = await loadBrowserChecker();
98
+ this._browserChecker = new BrowserChecker(this._skipOrbitaHashChecking);
99
+ }
100
+
101
+ return this._browserChecker;
102
+ }
103
+
110
104
  async checkBrowser(majorVersion) {
111
- this.executablePath = await this.browserChecker.checkBrowser({
105
+ const browserChecker = await this.getBrowserChecker();
106
+ this.executablePath = await browserChecker.checkBrowser({
112
107
  autoUpdateBrowser: this.autoUpdateBrowser,
113
108
  checkBrowserUpdate: this.checkBrowserUpdate,
114
109
  majorVersion,
@@ -130,7 +125,8 @@ export class GoLogin {
130
125
  }
131
126
 
132
127
  for (const majorVersion of versionsToDownload) {
133
- await this.browserChecker.checkBrowser({
128
+ const browserChecker = await this.getBrowserChecker();
129
+ await browserChecker.checkBrowser({
134
130
  autoUpdateBrowser: true,
135
131
  checkBrowserUpdate: true,
136
132
  majorVersion,
@@ -141,7 +137,8 @@ export class GoLogin {
141
137
  }
142
138
 
143
139
  async getLatestBrowserVersion() {
144
- const { latestVersion: browserLatestVersion } = await this.browserChecker.getLatestBrowserVersion();
140
+ const browserChecker = await this.getBrowserChecker();
141
+ const { latestVersion: browserLatestVersion } = await browserChecker.getLatestBrowserVersion();
145
142
  const [latestBrowserMajorVersion] = browserLatestVersion.split('.');
146
143
 
147
144
  return Number(latestBrowserMajorVersion);
@@ -149,6 +146,7 @@ export class GoLogin {
149
146
 
150
147
  async setProfileId(profile_id) {
151
148
  this.profile_id = profile_id;
149
+ const { getCookiesFilePath } = await loadCookiesManager();
152
150
  this.cookiesFilePath = await getCookiesFilePath(profile_id, this.tmpdir);
153
151
  this.profile_zip_path = join(this.tmpdir, `gologin_${this.profile_id}.zip`);
154
152
  this.bookmarksFilePath = join(this.tmpdir, `gologin_profile_${this.profile_id}`, 'Default', 'Bookmarks');
@@ -359,10 +357,11 @@ export class GoLogin {
359
357
  async createBrowserExtension() {
360
358
  const that = this;
361
359
  debug('start createBrowserExtension');
362
- await rimraf(this.orbitaExtensionPath(), () => null);
360
+ await removePath(this.orbitaExtensionPath());
363
361
  const extPath = this.orbitaExtensionPath();
364
362
  debug('extension folder sanitized');
365
363
  const extension_source = _resolve(__dirname, 'gologin-browser-ext.zip');
364
+ const { decompress, decompressUnzip } = await loadDecompress();
366
365
  await decompress(extension_source, extPath,
367
366
  {
368
367
  plugins: [decompressUnzip()],
@@ -383,8 +382,9 @@ export class GoLogin {
383
382
  debug('createBrowserExtension done');
384
383
  }
385
384
 
386
- extractProfile(path, zipfile) {
385
+ async extractProfile(path, zipfile) {
387
386
  debug(`extactProfile ${zipfile}, ${path}`);
387
+ const { decompress, decompressUnzip } = await loadDecompress();
388
388
 
389
389
  return decompress(zipfile, path,
390
390
  {
@@ -397,19 +397,24 @@ export class GoLogin {
397
397
  async downloadProfileAndExtract(profile, local) {
398
398
  let profile_folder;
399
399
  const profilePath = join(this.tmpdir, `gologin_profile_${this.profile_id}`);
400
+
400
401
  const profileZipExists = await access(this.profile_zip_path).then(() => true).catch(() => false);
401
402
 
402
403
  if (!(local && profileZipExists)) {
403
404
  try {
404
- profile_folder = await this.getProfileS3();
405
+ const [, profileData] = await Promise.all([
406
+ loadDecompress(),
407
+ this.getProfileS3(),
408
+ ]);
409
+
410
+ profile_folder = profileData;
405
411
  } catch (e) {
406
412
  debug('Cannot get profile - using empty', e);
413
+ await loadDecompress();
407
414
  }
408
415
 
409
416
  debug('FILE READY', this.profile_zip_path);
410
-
411
417
  await writeFile(this.profile_zip_path, profile_folder);
412
-
413
418
  debug('PROFILE LENGTH', profile_folder.length);
414
419
  } else {
415
420
  debug('PROFILE LOCAL HAVING', this.profile_zip_path);
@@ -435,6 +440,7 @@ export class GoLogin {
435
440
  }
436
441
 
437
442
  async createZeroProfile(createCookiesTableQuery) {
443
+ const { createDBFile } = await loadCookiesManager();
438
444
  const profilePath = join(this.tmpdir, `gologin_profile_${this.profile_id}`);
439
445
  const defaultFilePath = _resolve(profilePath, 'Default');
440
446
  const preferencesFilePath = _resolve(defaultFilePath, 'Preferences');
@@ -457,47 +463,16 @@ export class GoLogin {
457
463
 
458
464
  async createStartup(local = false) {
459
465
  const profilePath = join(this.tmpdir, `gologin_profile_${this.profile_id}`);
460
- await rimraf(profilePath, () => null);
461
- debug('-', profilePath, 'dropped');
462
- const profile = await this.getProfile();
463
- if (!profile) {
464
- throw new Error('Error fetching profile data');
465
- }
466
+ const startupDepsPromise = preloadStartupDeps();
466
467
 
467
- if (!this.executablePath) {
468
- const { userAgent } = profile.navigator;
469
- try {
470
- const [browserMajorVersion] = userAgent.split('Chrome/')[1].split('.');
471
- this.browserMajorVersion = Number(browserMajorVersion);
472
- await this.checkBrowser(browserMajorVersion);
473
- } catch (e) {
474
- const latestVersionNumber = await this.getLatestBrowserVersion();
475
- this.browserMajorVersion = latestVersionNumber;
476
- await this.checkBrowser(latestVersionNumber);
477
- }
478
- } else if (!this.browserMajorVersion) {
479
- const { userAgent } = profile.navigator;
480
- const [browserMajorVersion] = userAgent.split('Chrome/')[1].split('.');
481
- this.browserMajorVersion = Number(browserMajorVersion);
482
-
483
- let executableDir = join(this.executablePath, '..');
484
- if (OS_PLATFORM === 'darwin') {
485
- executableDir = join(this.executablePath, '..', '..', '..');
486
- }
468
+ const [profile] = await Promise.all([
469
+ this.getProfile(),
470
+ startupDepsPromise.then(() => removePath(profilePath)
471
+ .then(() => debug('-', profilePath, 'dropped'))),
472
+ ]);
487
473
 
488
- const versionFilePath = join(executableDir, 'version');
489
- try {
490
- await access(versionFilePath);
491
- const versionContent = await readFile(versionFilePath, 'utf8');
492
- const versionFromFile = versionContent.trim();
493
- const isValidVersion = /^\d+\.\d+\.\d+/.test(versionFromFile);
494
- if (isValidVersion) {
495
- const [browserMajorVersion] = isValidVersion.split('.');
496
- this.browserMajorVersion = Number(browserMajorVersion);
497
- }
498
- } catch (error) {
499
- console.warn('Error reading version file:', error);
500
- }
474
+ if (!profile) {
475
+ throw new Error('Error fetching profile data');
501
476
  }
502
477
 
503
478
  const { navigator = {}, fonts, os: profileOs } = profile;
@@ -510,10 +485,7 @@ export class GoLogin {
510
485
  OS_PLATFORM === 'linux' && profileOs !== 'lin'
511
486
  );
512
487
 
513
- const {
514
- resolution = '1920x1080',
515
- } = navigator;
516
-
488
+ const { resolution = '1920x1080' } = navigator;
517
489
  const [screenWidth, screenHeight] = resolution.split('x');
518
490
  this.resolution = {
519
491
  width: parseInt(screenWidth, 10),
@@ -521,87 +493,8 @@ export class GoLogin {
521
493
  };
522
494
 
523
495
  this.createCookiesTableQuery = profile.createCookiesTableQuery;
524
- if (profile.storageInfo.isNewProfile) {
525
- this.isFirstSession = true;
526
- await this.createZeroProfile(profile.createCookiesTableQuery);
527
- } else {
528
- this.isFirstSession = false;
529
- await this.downloadProfileAndExtract(profile, local);
530
- }
531
-
532
- await _promises.rm(join(profilePath, 'Default', 'Sync Data'), { recursive: true }).catch(() => null);
533
- const pref_file_name = join(profilePath, 'Default', 'Preferences');
534
- debug('reading', pref_file_name);
535
-
536
- const prefFileExists = await access(pref_file_name).then(() => true).catch(() => false);
537
- if (!prefFileExists) {
538
- debug('Preferences file not exists waiting', pref_file_name, '. Using empty profile');
539
- await mkdir(join(profilePath, 'Default'), { recursive: true });
540
- await writeFile(pref_file_name, '{}');
541
- }
542
496
 
543
- const preferences_raw = await readFile(pref_file_name);
544
- const preferences = JSON.parse(preferences_raw.toString());
545
497
  let proxy = get(profile, 'proxy');
546
- const chromeExtensions = get(profile, 'chromeExtensions') || [];
547
- const userChromeExtensions = get(profile, 'userChromeExtensions') || [];
548
- const allExtensions = [...chromeExtensions, ...userChromeExtensions];
549
-
550
- if (allExtensions.length) {
551
- const ExtensionsManagerInst = new ExtensionsManager();
552
- ExtensionsManagerInst.apiUrl = API_URL;
553
- await ExtensionsManagerInst.init()
554
- .then(() => ExtensionsManagerInst.updateExtensions())
555
- .catch(() => {});
556
- ExtensionsManagerInst.accessToken = this.access_token;
557
-
558
- await ExtensionsManagerInst.getExtensionsPolicies();
559
- let profileExtensionsCheckRes = [];
560
-
561
- if (ExtensionsManagerInst.useLocalExtStorage) {
562
- const promises = [
563
- ExtensionsManagerInst.checkChromeExtensions(allExtensions)
564
- .then(res => ({ profileExtensionsCheckRes: res }))
565
- .catch((e) => {
566
- console.log('checkChromeExtensions error: ', e);
567
-
568
- return { profileExtensionsCheckRes: [] };
569
- }),
570
- ExtensionsManagerInst.checkLocalUserChromeExtensions(userChromeExtensions, this.profile_id)
571
- .then(res => ({ profileUserExtensionsCheckRes: res }))
572
- .catch((error) => {
573
- console.log('checkUserChromeExtensions error: ', error);
574
-
575
- return null;
576
- }),
577
- ];
578
-
579
- const extensionsResult = await Promise.all(promises);
580
-
581
- const profileExtensionPathRes = extensionsResult.find(el => 'profileExtensionsCheckRes' in el) || {};
582
- const profileUserExtensionPathRes = extensionsResult.find(el => 'profileUserExtensionsCheckRes' in el);
583
- profileExtensionsCheckRes =
584
- (profileExtensionPathRes?.profileExtensionsCheckRes || []).concat(profileUserExtensionPathRes?.profileUserExtensionsCheckRes || []);
585
- }
586
-
587
- let extSettings;
588
- if (ExtensionsManagerInst.useLocalExtStorage) {
589
- extSettings = await setExtPathsAndRemoveDeleted(preferences, profileExtensionsCheckRes, this.profile_id);
590
- } else {
591
- const originalExtensionsFolder = join(profilePath, 'Default', 'Extensions');
592
- extSettings = await setOriginalExtPaths(preferences, originalExtensionsFolder);
593
- }
594
-
595
- this.extensionPathsToInstall =
596
- ExtensionsManagerInst.getExtensionsToInstall(extSettings, profileExtensionsCheckRes);
597
-
598
- if (extSettings) {
599
- const currentExtSettings = preferences.extensions || {};
600
- currentExtSettings.settings = extSettings;
601
- preferences.extensions = currentExtSettings;
602
- }
603
- }
604
-
605
498
  if (proxy.mode === 'gologin' || proxy.mode === 'tor') {
606
499
  const autoProxyServer = get(profile, 'autoProxyServer');
607
500
  const splittedAutoProxyServer = autoProxyServer.split('://');
@@ -630,51 +523,62 @@ export class GoLogin {
630
523
 
631
524
  this.proxy = proxy;
632
525
 
633
- await this.getTimeZone(proxy).catch((e) => {
634
- console.error('Proxy Error. Check it and try again.');
635
- throw new Error(`Proxy Error. ${e.message}`);
636
- });
637
-
638
- const gologin = this.getGologinPreferences(profile);
526
+ await Promise.all([
527
+ this.resolveProfileBrowserVersion(profile),
528
+ this.initProfileStorage({ profile, local }),
529
+ this.getTimeZone(proxy).catch((e) => {
530
+ console.error('Proxy Error. Check it and try again.');
531
+ throw new Error(`Proxy Error. ${e.message}`);
532
+ }),
533
+ this.initCookiesFile(profile),
534
+ ]);
639
535
 
640
- debug(`Writing profile for screenWidth ${profilePath}`, JSON.stringify(gologin));
641
- gologin.screenWidth = this.resolution.width;
642
- gologin.screenHeight = this.resolution.height;
643
- debug('writeCookiesFromServer', this.writeCookiesFromServer);
644
- this.cookiesFilePath = await getCookiesFilePath(this.profile_id, this.tmpdir);
536
+ await _promises.rm(join(profilePath, 'Default', 'Sync Data'), { recursive: true }).catch(() => null);
537
+ const pref_file_name = join(profilePath, 'Default', 'Preferences');
538
+ debug('reading', pref_file_name);
645
539
 
646
- if (this.writeCookiesFromServer) {
647
- await this.writeCookiesToFile(profile.cookies?.cookies);
540
+ const prefFileExists = await access(pref_file_name).then(() => true).catch(() => false);
541
+ if (!prefFileExists) {
542
+ debug('Preferences file not exists waiting', pref_file_name, '. Using empty profile');
543
+ await mkdir(join(profilePath, 'Default'), { recursive: true });
544
+ await writeFile(pref_file_name, '{}');
648
545
  }
649
546
 
547
+ const preferences_raw = await readFile(pref_file_name);
548
+ const preferences = JSON.parse(preferences_raw.toString());
549
+ const chromeExtensions = get(profile, 'chromeExtensions') || [];
550
+ const userChromeExtensions = get(profile, 'userChromeExtensions') || [];
551
+ const allExtensions = [...chromeExtensions, ...userChromeExtensions];
552
+
553
+ const [, orbitaParamsToken] = await Promise.all([
554
+ this.setupProfileExtensions({
555
+ preferences, allExtensions, userChromeExtensions, profilePath,
556
+ }),
557
+ this.fetchOrbitaParamsToken(profile),
558
+ ]);
559
+
650
560
  if (this.fontsMasking) {
651
561
  const families = fonts?.families || [];
652
562
  if (!families.length) {
653
563
  this.isEmptyFonts = true;
654
564
  }
655
-
656
- try {
657
- await composeFonts(families, profilePath, this.differentOs);
658
- } catch (e) {
659
- console.trace(e);
660
- }
661
565
  }
662
566
 
663
567
  if (preferences.gologin === null) {
664
568
  preferences.gologin = {};
665
569
  }
666
570
 
571
+ const gologin = this.getGologinPreferences(profile);
572
+
573
+ debug(`Writing profile for screenWidth ${profilePath}`, JSON.stringify(gologin));
574
+ gologin.screenWidth = this.resolution.width;
575
+ gologin.screenHeight = this.resolution.height;
576
+ debug('writeCookiesFromServer', this.writeCookiesFromServer);
577
+
667
578
  const isMAC = OS_PLATFORM === 'darwin';
668
579
  const checkAutoLangResult = checkAutoLang(gologin, this._tz, profile.autoLang);
669
580
  const intlConfig = getIntlProfileConfig(profile, this._tz, profile.autoLang);
670
581
 
671
- let orbitaParamsToken = '';
672
- if (profile.securedOrbitaVersion && (this.browserMajorVersion >= profile.securedOrbitaVersion)) {
673
- const tokenRes = await this.requestOrbitaProfileParamsToken(this.profile_id);
674
-
675
- orbitaParamsToken = tokenRes.token;
676
- }
677
-
678
582
  this.browserLang = isMAC ? 'en-US' : checkAutoLangResult;
679
583
  const prefsToWrite = Object.assign(preferences, { gologin });
680
584
  if (this.browserMajorVersion >= this.newProxyOrbitaMajorVersion && this.proxy?.mode !== 'none') {
@@ -701,12 +605,143 @@ export class GoLogin {
701
605
  const bookmarksFromDb = profile.bookmarks?.bookmark_bar;
702
606
  bookmarksParsedData.roots = bookmarksFromDb ? profile.bookmarks : bookmarksParsedData.roots;
703
607
  await writeFile(this.bookmarksFilePath, JSON.stringify(bookmarksParsedData));
704
-
705
608
  debug('Profile ready. Path: ', profilePath, 'PROXY', JSON.stringify(get(preferences, 'gologin.proxy')));
706
609
 
707
610
  return profilePath;
708
611
  }
709
612
 
613
+ async resolveProfileBrowserVersion(profile) {
614
+ if (!this.executablePath) {
615
+ const { userAgent } = profile.navigator;
616
+ try {
617
+ const [browserMajorVersion] = userAgent.split('Chrome/')[1].split('.');
618
+ this.browserMajorVersion = Number(browserMajorVersion);
619
+ await this.checkBrowser(browserMajorVersion);
620
+ } catch (e) {
621
+ const latestVersionNumber = await this.getLatestBrowserVersion();
622
+ this.browserMajorVersion = latestVersionNumber;
623
+ await this.checkBrowser(latestVersionNumber);
624
+ }
625
+
626
+ return;
627
+ }
628
+
629
+ if (!this.browserMajorVersion) {
630
+ const { userAgent } = profile.navigator;
631
+ const [browserMajorVersion] = userAgent.split('Chrome/')[1].split('.');
632
+ this.browserMajorVersion = Number(browserMajorVersion);
633
+
634
+ let executableDir = join(this.executablePath, '..');
635
+ if (OS_PLATFORM === 'darwin') {
636
+ executableDir = join(this.executablePath, '..', '..', '..');
637
+ }
638
+
639
+ const versionFilePath = join(executableDir, 'version');
640
+ try {
641
+ await access(versionFilePath);
642
+ const versionContent = await readFile(versionFilePath, 'utf8');
643
+ const versionFromFile = versionContent.trim();
644
+ const isValidVersion = /^\d+\.\d+\.\d+/.test(versionFromFile);
645
+ if (isValidVersion) {
646
+ const [browserMajorVersion] = isValidVersion.split('.');
647
+ this.browserMajorVersion = Number(browserMajorVersion);
648
+ }
649
+ } catch (error) {
650
+ console.warn('Error reading version file:', error);
651
+ }
652
+ }
653
+ }
654
+
655
+ async initProfileStorage({ profile, local }) {
656
+ if (profile.storageInfo.isNewProfile) {
657
+ this.isFirstSession = true;
658
+ await this.createZeroProfile(profile.createCookiesTableQuery);
659
+
660
+ return;
661
+ }
662
+
663
+ this.isFirstSession = false;
664
+ await this.downloadProfileAndExtract(profile, local);
665
+ }
666
+
667
+ async initCookiesFile(profile) {
668
+ const { getCookiesFilePath } = await loadCookiesManager();
669
+ this.cookiesFilePath = await getCookiesFilePath(this.profile_id, this.tmpdir);
670
+ if (this.writeCookiesFromServer) {
671
+ await this.writeCookiesToFile(profile.cookies?.cookies);
672
+ }
673
+ }
674
+
675
+ async setupProfileExtensions({ preferences, allExtensions, userChromeExtensions, profilePath }) {
676
+ if (!allExtensions.length) {
677
+ return;
678
+ }
679
+
680
+ const ExtensionsManager = await loadExtensionsManager();
681
+ const ExtensionsManagerInst = new ExtensionsManager();
682
+ ExtensionsManagerInst.apiUrl = API_URL;
683
+ await ExtensionsManagerInst.init()
684
+ .then(() => ExtensionsManagerInst.updateExtensions())
685
+ .catch(() => {});
686
+ ExtensionsManagerInst.accessToken = this.access_token;
687
+
688
+ await ExtensionsManagerInst.getExtensionsPolicies();
689
+ let profileExtensionsCheckRes = [];
690
+
691
+ if (ExtensionsManagerInst.useLocalExtStorage) {
692
+ const promises = [
693
+ ExtensionsManagerInst.checkChromeExtensions(allExtensions)
694
+ .then(res => ({ profileExtensionsCheckRes: res }))
695
+ .catch((e) => {
696
+ console.log('checkChromeExtensions error: ', e);
697
+
698
+ return { profileExtensionsCheckRes: [] };
699
+ }),
700
+ ExtensionsManagerInst.checkLocalUserChromeExtensions(userChromeExtensions, this.profile_id)
701
+ .then(res => ({ profileUserExtensionsCheckRes: res }))
702
+ .catch((error) => {
703
+ console.log('checkUserChromeExtensions error: ', error);
704
+
705
+ return null;
706
+ }),
707
+ ];
708
+
709
+ const extensionsResult = await Promise.all(promises);
710
+
711
+ const profileExtensionPathRes = extensionsResult.find(el => 'profileExtensionsCheckRes' in el) || {};
712
+ const profileUserExtensionPathRes = extensionsResult.find(el => 'profileUserExtensionsCheckRes' in el);
713
+ profileExtensionsCheckRes =
714
+ (profileExtensionPathRes?.profileExtensionsCheckRes || []).concat(profileUserExtensionPathRes?.profileUserExtensionsCheckRes || []);
715
+ }
716
+
717
+ let extSettings;
718
+ if (ExtensionsManagerInst.useLocalExtStorage) {
719
+ extSettings = await setExtPathsAndRemoveDeleted(preferences, profileExtensionsCheckRes, this.profile_id);
720
+ } else {
721
+ const originalExtensionsFolder = join(profilePath, 'Default', 'Extensions');
722
+ extSettings = await setOriginalExtPaths(preferences, originalExtensionsFolder);
723
+ }
724
+
725
+ this.extensionPathsToInstall =
726
+ ExtensionsManagerInst.getExtensionsToInstall(extSettings, profileExtensionsCheckRes);
727
+
728
+ if (extSettings) {
729
+ const currentExtSettings = preferences.extensions || {};
730
+ currentExtSettings.settings = extSettings;
731
+ preferences.extensions = currentExtSettings;
732
+ }
733
+ }
734
+
735
+ async fetchOrbitaParamsToken(profile) {
736
+ if (!profile.securedOrbitaVersion || this.browserMajorVersion < profile.securedOrbitaVersion) {
737
+ return '';
738
+ }
739
+
740
+ const tokenRes = await this.requestOrbitaProfileParamsToken(this.profile_id);
741
+
742
+ return tokenRes.token;
743
+ }
744
+
710
745
  async commitProfile() {
711
746
  // wait for orbita to finish working with files
712
747
  await new Promise((resolve) => setTimeout(resolve, 2000));
@@ -783,6 +818,14 @@ export class GoLogin {
783
818
  return this._tz.timezone;
784
819
  }
785
820
 
821
+ if (this._tz) {
822
+ debug('getTimeZone from cache', this._tz.timezone);
823
+
824
+ return this._tz.timezone;
825
+ }
826
+
827
+ const isGologinProxy = proxy?.host?.includes('floppydata.com');
828
+
786
829
  let data = null;
787
830
  if (proxy && proxy.mode !== PROXY_NONE) {
788
831
  if (proxy.mode.includes('socks')) {
@@ -795,7 +838,7 @@ export class GoLogin {
795
838
  console.log(e.message);
796
839
  }
797
840
  }
798
- throw new Error('Socks proxy connection timed out');
841
+ throw new Error(`Proxy Error${isGologinProxy ? ' (Gologin)' : ''}`);
799
842
  }
800
843
 
801
844
  const proxyUrl = `${proxy.mode}://${proxy.username}:${proxy.password}@${proxy.host}:${proxy.port}`;
@@ -806,6 +849,8 @@ export class GoLogin {
806
849
  timeout: this.proxyCheckTimeout,
807
850
  maxAttempts: this.proxyCheckAttempts,
808
851
  method: 'GET',
852
+ }).catch((e) => {
853
+ throw new Error(`${e.message}${isGologinProxy ? ' (Gologin)' : ''}`);
809
854
  });
810
855
  } else {
811
856
  data = await makeRequest(TIMEZONE_URL, { timeout: this.proxyCheckTimeout, maxAttempts: this.proxyCheckAttempts, method: 'GET' });
@@ -849,9 +894,12 @@ export class GoLogin {
849
894
  }
850
895
 
851
896
  proxy += host + ':' + port;
897
+ const SocksProxyAgent = await loadSocksProxyAgent();
852
898
  const agent = new SocksProxyAgent(proxy);
853
899
 
854
- const checkData = await checkSocksProxy(agent);
900
+ const checkData = await checkSocksProxy(agent).catch((e) => {
901
+ throw new Error(`Proxy Error. ${e.message}`);
902
+ });
855
903
 
856
904
  const body = checkData.body || {};
857
905
  if (!body.ip && checkData.statusCode.toString().startsWith('4')) {
@@ -933,8 +981,14 @@ export class GoLogin {
933
981
 
934
982
  this.port = remote_debugging_port;
935
983
 
936
- const ORBITA_BROWSER = this.executablePath || this.browserChecker.getOrbitaPath;
984
+ let ORBITA_BROWSER = this.executablePath;
985
+ if (!ORBITA_BROWSER) {
986
+ const browserChecker = await this.getBrowserChecker();
987
+ ORBITA_BROWSER = browserChecker.getOrbitaPath;
988
+ }
989
+
937
990
  debug(`ORBITA_BROWSER=${ORBITA_BROWSER}`);
991
+
938
992
  const env = {};
939
993
  Object.keys(process.env).forEach((key) => {
940
994
  env[key] = process.env[key];
@@ -1025,7 +1079,7 @@ export class GoLogin {
1025
1079
  debug('GETTING WS URL FROM BROWSER');
1026
1080
  const data = await makeRequest(
1027
1081
  `http://127.0.0.1:${remote_debugging_port}/json/version`,
1028
- { json: true, maxAttempts: 30, retryDelay: 1000, method: 'GET' },
1082
+ { json: true, maxAttempts: 60, retryDelay: 100, method: 'GET' },
1029
1083
  );
1030
1084
 
1031
1085
  debug('WS IS', get(data, 'webSocketDebuggerUrl', ''));
@@ -1038,8 +1092,8 @@ export class GoLogin {
1038
1092
  }
1039
1093
 
1040
1094
  async clearProfileFiles() {
1041
- await rimraf(join(this.tmpdir, `gologin_profile_${this.profile_id}`), () => null);
1042
- await rimraf(join(this.tmpdir, `gologin_${this.profile_id}_upload.zip`), () => null);
1095
+ await removePath(join(this.tmpdir, `gologin_profile_${this.profile_id}`));
1096
+ await removePath(join(this.tmpdir, `gologin_${this.profile_id}_upload.zip`));
1043
1097
  }
1044
1098
 
1045
1099
  async stopAndCommit(options, local = false) {
@@ -1069,7 +1123,7 @@ export class GoLogin {
1069
1123
  await this.clearProfileFiles();
1070
1124
 
1071
1125
  if (!local) {
1072
- await rimraf(join(this.tmpdir, `gologin_${this.profile_id}.zip`), () => null);
1126
+ await removePath(join(this.tmpdir, `gologin_${this.profile_id}.zip`));
1073
1127
  }
1074
1128
 
1075
1129
  debug(`PROFILE ${this.profile_id} STOPPED AND CLEAR`);
@@ -1078,6 +1132,7 @@ export class GoLogin {
1078
1132
  }
1079
1133
 
1080
1134
  async uploadProfileDataToServer() {
1135
+ const { loadCookiesFromFile } = await loadCookiesManager();
1081
1136
  const cookies = await loadCookiesFromFile(this.cookiesFilePath, false, this.profile_id, this.tmpdir);
1082
1137
  const bookmarks = await getCurrentProfileBookmarks(this.bookmarksFilePath);
1083
1138
  const profilePreferencesPath = join(this.profilePath(), 'Default', 'Preferences');
@@ -1136,7 +1191,7 @@ export class GoLogin {
1136
1191
  debug('browser killed');
1137
1192
  } catch (error) {
1138
1193
  console.error(error);
1139
- captureGroupedSentryError(error, { method: 'killBrowser', profileId: this.profile_id });
1194
+ // captureGroupedSentryError(error, { method: 'killBrowser', profileId: this.profile_id });
1140
1195
  }
1141
1196
  }
1142
1197
 
@@ -1177,13 +1232,7 @@ export class GoLogin {
1177
1232
  await Promise.all(remove_dirs.map(d => {
1178
1233
  const path_to_remove = `${that.profilePath()}${d}`;
1179
1234
 
1180
- return new Promise(resolve => {
1181
- debug('DROPPING', path_to_remove);
1182
- rimraf(path_to_remove, { maxBusyTries: 100 }, (e) => {
1183
- // debug('DROPPING RESULT', e);
1184
- resolve();
1185
- });
1186
- });
1235
+ return removePath(path_to_remove, { maxBusyTries: 100 });
1187
1236
  }));
1188
1237
  }
1189
1238
 
@@ -1198,6 +1247,7 @@ export class GoLogin {
1198
1247
  debug('profile sanitized');
1199
1248
 
1200
1249
  const profilePath = this.profilePath();
1250
+ const { archiveProfile } = await loadProfileArchiver();
1201
1251
  const fileBuff = await archiveProfile(profilePath);
1202
1252
 
1203
1253
  debug('PROFILE ZIP CREATED', profilePath, zipPath);
@@ -1387,6 +1437,13 @@ export class GoLogin {
1387
1437
  return;
1388
1438
  }
1389
1439
 
1440
+ const {
1441
+ createDBFile,
1442
+ getChunckedInsertValues,
1443
+ getDB,
1444
+ getUniqueCookies,
1445
+ } = await loadCookiesManager();
1446
+
1390
1447
  const resultCookies = cookies.map((el) => ({ ...el, value: Buffer.from(el.value) }));
1391
1448
  let db;
1392
1449
  const profilePath = join(this.tmpdir, `gologin_profile_${this.profile_id}`);
@@ -1419,7 +1476,7 @@ export class GoLogin {
1419
1476
  }
1420
1477
 
1421
1478
  console.error(error.message);
1422
- captureGroupedSentryError(error, { method: 'writeCookiesToFile', profileId: this.profile_id });
1479
+ // captureGroupedSentryError(error, { method: 'writeCookiesToFile', profileId: this.profile_id });
1423
1480
  } finally {
1424
1481
  db && await db.close();
1425
1482
  await ensureDirectoryExists(cookiesPaths.primary);
@@ -1437,20 +1494,22 @@ export class GoLogin {
1437
1494
  }
1438
1495
 
1439
1496
  async start() {
1440
- try {
1441
- await this.createStartup();
1442
- const startResponse = await this.spawnBrowser();
1443
- this.setActive(true);
1497
+ // ensureSentryInitialized({ release: process.env.npm_package_version || '2.1.34' });
1444
1498
 
1445
- return { status: 'success', wsUrl: startResponse.wsUrl, resolution: startResponse.resolution };
1446
- } catch (error) {
1447
- captureGroupedSentryError(error, { method: 'start', profileId: this.profile_id });
1448
- throw error;
1449
- }
1499
+ await this.createStartup();
1500
+ const startResponse = await this.spawnBrowser();
1501
+ this.setActive(true);
1502
+
1503
+ return {
1504
+ status: 'success',
1505
+ wsUrl: startResponse.wsUrl,
1506
+ resolution: startResponse.resolution,
1507
+ };
1450
1508
  }
1451
1509
 
1452
1510
  async startLocal() {
1453
1511
  await this.createStartup(true);
1512
+
1454
1513
  // await this.createBrowserExtension();
1455
1514
  const startResponse = await this.spawnBrowser();
1456
1515
  this.setActive(true);
@@ -1525,12 +1584,6 @@ export class GoLogin {
1525
1584
  return updateProfileResolution(this.profile_id, this.access_token, resolution);
1526
1585
  }
1527
1586
 
1528
- getAvailableFonts() {
1529
- return fontsCollection
1530
- .filter(elem => elem.fileNames)
1531
- .map(elem => elem.name);
1532
- }
1533
-
1534
1587
  async quickCreateProfile(name = '') {
1535
1588
  const osInfo = await getOsAdvanced();
1536
1589
  const { os, osSpec } = osInfo;