gologin 1.0.26 → 1.0.30

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -18,7 +18,7 @@ for running example.js install puppeteer-core
18
18
  Where is token? API token is <a href="https://app.gologin.com/#/personalArea/TokenApi" target="_blank">here</a>.
19
19
  To have an access to the page below you need <a href="https://app.gologin.com/#/createUser" target="_blank">register</a> GoLogin account.
20
20
 
21
- ![Token API in Settings](https://user-images.githubusercontent.com/62306291/78453427-53220100-769a-11ea-9465-0aae3ae602b7.jpg)
21
+ ![Token API in Settings](https://user-images.githubusercontent.com/12957968/146891933-c3b60b4d-c850-47a5-8adf-bc8c37372664.gif)
22
22
 
23
23
  ### Example
24
24
 
@@ -1,11 +1,13 @@
1
1
  const puppeteer = require('puppeteer-core');
2
2
  const GoLogin = require('../gologin');
3
3
 
4
- (async () =>{
4
+ const delay = (time) => new Promise((resolve) => setTimeout(resolve, time));
5
+
6
+ (async () =>{
5
7
  const GL = new GoLogin({
6
8
  token: 'yU0token',
7
9
  profile_id: 'yU0Pr0f1leiD',
8
- extra_params: ['--headless'],
10
+ extra_params: ['--headless', '--no-sandbox'],
9
11
  });
10
12
  const {status, wsUrl} = await GL.start();
11
13
  const browser = await puppeteer.connect({
@@ -14,6 +16,7 @@ const GoLogin = require('../gologin');
14
16
  });
15
17
 
16
18
  const page = await browser.newPage();
19
+ await delay(300);
17
20
 
18
21
  const viewPort = GL.getViewPort();
19
22
  await page.setViewport({ width: Math.round(viewPort.width * 0.994), height: Math.round(viewPort.height * 0.92) });
package/gologin.js CHANGED
@@ -8,7 +8,7 @@ const rimraf = util.promisify(require('rimraf'));
8
8
  const exec = util.promisify(require('child_process').exec);
9
9
  const { spawn, execFile } = require('child_process');
10
10
  const FormData = require('form-data');
11
- const socks5Http = require('socks5-https-client');
11
+ const ProxyAgent = require('simple-proxy-agent');
12
12
  const decompress = require('decompress');
13
13
  const decompressUnzip = require('decompress-unzip');
14
14
  const path = require('path');
@@ -18,6 +18,7 @@ const BrowserChecker = require('./browser-checker');
18
18
  const { BrowserUserDataManager } = require('./browser-user-data-manager');
19
19
  const { CookiesManager } = require('./cookies-manager');
20
20
  const fontsCollection = require('./fonts');
21
+ const https = require('https');
21
22
 
22
23
  const SEPARATOR = path.sep;
23
24
  const API_URL = 'https://api.gologin.com';
@@ -46,7 +47,6 @@ class GoLogin {
46
47
  this.browserChecker = new BrowserChecker();
47
48
  this.uploadCookiesToServer = options.uploadCookiesToServer || false;
48
49
  this.writeCookesFromServer = options.writeCookesFromServer || true;
49
- this.cookiesFilePath = path.join(os.tmpdir(), `gologin_profile_${this.profile_id}`, 'Default', 'Cookies');
50
50
  this.remote_debugging_port = options.remote_debugging_port || 0;
51
51
  this.timezone = options.timezone;
52
52
 
@@ -58,6 +58,7 @@ class GoLogin {
58
58
  }
59
59
  }
60
60
 
61
+ this.cookiesFilePath = path.join(this.tmpdir, `gologin_profile_${this.profile_id}`, 'Default', 'Cookies');
61
62
  this.profile_zip_path = path.join(this.tmpdir, `gologin_${this.profile_id}.zip`);
62
63
  debug('INIT GOLOGIN', this.profile_id);
63
64
  }
@@ -66,6 +67,7 @@ class GoLogin {
66
67
 
67
68
  async setProfileId(profile_id) {
68
69
  this.profile_id = profile_id;
70
+ this.cookiesFilePath = path.join(this.tmpdir, `gologin_profile_${this.profile_id}`, 'Default', 'Cookies');
69
71
  this.profile_zip_path = path.join(this.tmpdir, `gologin_${this.profile_id}.zip`);
70
72
  }
71
73
 
@@ -122,7 +124,7 @@ class GoLogin {
122
124
  })
123
125
  debug(profileResponse.body);
124
126
  if (profileResponse.statusCode !== 200) {
125
- throw new Error(`Gologin /browser/${id} response error ${profileResponse.statusCode}`);
127
+ throw new Error(`Gologin /browser/${id} response error ${profileResponse.statusCode} INVALID TOKEN OR PROFILE NOT FOUND`);
126
128
  }
127
129
 
128
130
  if(profileResponse.statusCode == 401){
@@ -357,6 +359,11 @@ class GoLogin {
357
359
  profile.proxy.password = _.get(profile, 'autoProxyPassword');
358
360
  }
359
361
  // console.log('proxy=', proxy);
362
+
363
+ if (proxy.mode === 'geolocation') {
364
+ proxy.mode = 'http';
365
+ }
366
+
360
367
  if (proxy.mode === 'none') {
361
368
  proxy = null;
362
369
  }
@@ -384,6 +391,8 @@ class GoLogin {
384
391
  publicIP: _.get(profile, 'webRTC.fillBasedOnIp') ? this._tz.ip : _.get(profile, 'webRTC.publicIp'),
385
392
  localIps: _.get(profile, 'webRTC.localIps', []),
386
393
  };
394
+
395
+ debug('profile.webRtc=', profile.webRtc);
387
396
 
388
397
  const audioContext = profile.audioContext || {};
389
398
  const { mode: audioCtxMode = 'off', noise: audioCtxNoise } = audioContext;
@@ -497,6 +506,7 @@ class GoLogin {
497
506
  }
498
507
 
499
508
  async getTimeZone(proxy) {
509
+ debug('getting timeZone proxy=', proxy);
500
510
  if(this.timezone){
501
511
  debug('getTimeZone from options', this.timezone);
502
512
  this._tz = this.timezone;
@@ -504,51 +514,47 @@ class GoLogin {
504
514
  }
505
515
 
506
516
  let data = null;
507
- if (proxy) {
517
+ if (proxy!==null && proxy.mode !== "none") {
508
518
  if (proxy.mode.includes('socks')) {
509
519
  return this.getTimezoneWithSocks(proxy);
510
520
  }
511
521
 
512
522
  const proxyUrl = `${proxy.mode}://${proxy.username}:${proxy.password}@${proxy.host}:${proxy.port}`;
513
523
  debug('getTimeZone start https://time.gologin.com', proxyUrl);
514
- data = await requests.get('https://time.gologin.com', { proxy: proxyUrl, timeout: 10 * 1000, maxAttempts: 2 });
524
+ data = await requests.get('https://time.gologin.com', { proxy: proxyUrl, timeout: 20 * 1000, maxAttempts: 5 });
515
525
  } else {
516
- data = await requests.get('https://time.gologin.com', { timeout: 10 * 1000, maxAttempts: 2 });
526
+ data = await requests.get('https://time.gologin.com', { timeout: 20 * 1000, maxAttempts: 5 });
517
527
  }
518
528
  debug('getTimeZone finish', data.body);
519
529
  this._tz = JSON.parse(data.body);
520
530
  return this._tz.timezone;
521
531
  }
522
532
 
523
- async getTimezoneWithSocks(proxy) {
524
- const { host, port, username, password } = proxy;
533
+ async getTimezoneWithSocks(params) {
534
+ const { mode = 'http', host, port, username = '', password = '' } = params;
525
535
  let body;
526
536
 
527
- const checkData = await new Promise((resolve, reject) => {
528
- const timer = setTimeout(() => {
529
- req.abort();
530
- reject(new Error('Timeout exceeded'));
531
- }, 10000);
532
-
533
- const req = socks5Http.get({
534
- hostname: 'time.gologin.com',
535
- path: '/timezone',
536
- socksHost: host,
537
- socksPort: port,
538
- socksUsername: username || '',
539
- socksPassword: password || '',
540
- }, (res) => {
541
- res.setEncoding('utf8');
537
+ let proxy = mode + '://';
538
+ if (username) {
539
+ const resultPassword = password ? ':' + password + '@' : '@';
540
+ proxy += username + resultPassword;
541
+ }
542
+ proxy += host + ':' + port;
543
+
544
+ const agent = new ProxyAgent(proxy, { tunnel: true, timeout: 10000 });
542
545
 
546
+ const checkData = await new Promise((resolve, reject) => {
547
+ https.get('https://time.gologin.com/timezone', { agent }, (res) => {
543
548
  let resultResponse = '';
544
549
  res.on('data', (data) => resultResponse += data);
545
550
 
546
551
  res.on('end', () => {
547
- clearTimeout(timer);
548
552
  let parsedData;
549
553
  try {
550
554
  parsedData = JSON.parse(resultResponse);
551
- } catch (e) {}
555
+ } catch (e) {
556
+ reject(e);
557
+ }
552
558
 
553
559
  resolve({
554
560
  ...res,
@@ -558,14 +564,13 @@ class GoLogin {
558
564
  }).on('error', (err) => reject(err));
559
565
  });
560
566
 
561
- console.log('checkData:', checkData);
567
+ // console.log('checkData:', checkData);
562
568
  body = checkData.body || {};
563
569
  if (!body.ip && checkData.statusCode.toString().startsWith('4')) {
564
570
  throw checkData;
565
571
  }
566
572
  debug('getTimeZone finish', body.body);
567
573
  this._tz = body;
568
-
569
574
  return this._tz.timezone;
570
575
  }
571
576
 
@@ -697,7 +702,7 @@ class GoLogin {
697
702
  await rimraf(path.join(this.tmpdir, `gologin_${this.profile_id}_upload.zip`));
698
703
  }
699
704
 
700
- async stopAndCommit(options, local= false) {
705
+ async stopAndCommit(options, local = false) {
701
706
  if (this.is_stopping) {
702
707
  return true;
703
708
  }
@@ -1037,6 +1042,12 @@ class GoLogin {
1037
1042
  if (!this.executablePath) {
1038
1043
  await this.checkBrowser();
1039
1044
  }
1045
+
1046
+ const ORBITA_BROWSER = this.executablePath || this.browserChecker.getOrbitaPath;
1047
+
1048
+ if(!fs.existsSync(ORBITA_BROWSER)){
1049
+ throw new Error(`Orbita browser is not exists on path ${ORBITA_BROWSER}, check executablePath param`);
1050
+ }
1040
1051
 
1041
1052
  await this.createStartup();
1042
1053
  // await this.createBrowserExtension();
@@ -1060,12 +1071,12 @@ class GoLogin {
1060
1071
  return this.stopRemote();
1061
1072
  }
1062
1073
 
1063
- await this.stopAndCommit(false, {});
1074
+ await this.stopAndCommit({ posting: false }, false);
1064
1075
  }
1065
1076
 
1066
1077
  async stopLocal(options) {
1067
- const opts = options || {posting: false};
1068
- await this.stopAndCommit(true, opts.posting);
1078
+ const opts = options || { posting: false };
1079
+ await this.stopAndCommit(options, true);
1069
1080
  }
1070
1081
 
1071
1082
  async waitDebuggingUrl(delay_ms, try_count=0) {
@@ -1112,6 +1123,28 @@ class GoLogin {
1112
1123
  }
1113
1124
 
1114
1125
  if (profileResponse.body === 'ok') {
1126
+ const profile = await this.getProfile();
1127
+ const { navigator = {}, fonts, os: profileOs } = profile;
1128
+ this.fontsMasking = fonts?.enableMasking;
1129
+ this.profileOs = profileOs;
1130
+ this.differentOs =
1131
+ profileOs !== 'android' && (
1132
+ OS_PLATFORM === 'win32' && profileOs !== 'win' ||
1133
+ OS_PLATFORM === 'darwin' && profileOs !== 'mac' ||
1134
+ OS_PLATFORM === 'linux' && profileOs !== 'lin'
1135
+ );
1136
+
1137
+ const {
1138
+ resolution = '1920x1080',
1139
+ language = 'en-US,en;q=0.9',
1140
+ } = navigator;
1141
+ this.language = language;
1142
+ const [screenWidth, screenHeight] = resolution.split('x');
1143
+ this.resolution = {
1144
+ width: parseInt(screenWidth, 10),
1145
+ height: parseInt(screenHeight, 10),
1146
+ };
1147
+
1115
1148
  let wsUrl = await this.waitDebuggingUrl(delay_ms);
1116
1149
  return { 'status': 'success', wsUrl }
1117
1150
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "gologin",
3
- "version": "1.0.26",
3
+ "version": "1.0.30",
4
4
  "description": "A high-level API to control Orbita browser over GoLogin API",
5
5
  "main": "./gologin.js",
6
6
  "repository": {
@@ -27,7 +27,7 @@
27
27
  "rimraf": "^3.0.2",
28
28
  "selenium-webdriver": "^4.0.0-alpha.7",
29
29
  "shelljs": "^0.8.4",
30
- "socks5-https-client": "^1.2.1",
30
+ "simple-proxy-agent": "^1.1.0",
31
31
  "sqlite": "^4.0.23",
32
32
  "sqlite3": "^5.0.2"
33
33
  },
@@ -45,7 +45,7 @@ class GoLogin(object):
45
45
  proxy = self.proxy
46
46
  proxy_host = ''
47
47
  if proxy:
48
- if proxy.get('mode')==None:
48
+ if proxy.get('mode')==None or proxy.get('mode')=='geolocation':
49
49
  proxy['mode'] = 'http'
50
50
  proxy_host = proxy.get('host')
51
51
  proxy = self.formatProxyUrl(proxy)