gologin 1.0.24 → 1.0.28

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.
@@ -32,9 +32,9 @@ class CookiesManager {
32
32
  const queryPlaceholders = cookies.map(() => '(?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)').join(', ');
33
33
  const query = `insert or replace into cookies (creation_utc, top_frame_site_key, host_key, name, value, path, expires_utc, is_secure, is_httponly, last_access_utc, is_persistent, encrypted_value, samesite, has_expires) values ${queryPlaceholders}`;
34
34
  const queryParams = cookies.flatMap((cookie) => {
35
- const creationDate = cookie.creationDate ? cookie.creationDate : unixToLDAP(todayUnix);
36
- let expirationDate = cookie.session ? 0 : unixToLDAP(cookie.expirationDate);
37
- const encryptedValue = Buffer.concat([Buffer.from('v11'), Buffer.from(encrypt(cookie.value), 'binary')]);
35
+ const creationDate = cookie.creationDate ? cookie.creationDate : this.unixToLDAP(todayUnix);
36
+ let expirationDate = cookie.session ? 0 : this.unixToLDAP(cookie.expirationDate);
37
+ const encryptedValue = cookie.value;
38
38
  const samesite = Object.keys(SAME_SITE).find((key) => SAME_SITE[key] === (cookie.sameSite || '-1'));
39
39
  const isSecure =
40
40
  cookie.name.startsWith('__Host-') || cookie.name.startsWith('__Secure-') ? 1 : Number(cookie.secure);
@@ -5,7 +5,7 @@ const GoLogin = require('../gologin');
5
5
  const GL = new GoLogin({
6
6
  token: 'yU0token',
7
7
  profile_id: 'yU0Pr0f1leiD',
8
- extra_params: ['--headless'],
8
+ extra_params: ['--headless', '--no-sandbox'],
9
9
  });
10
10
  const {status, wsUrl} = await GL.start();
11
11
  const browser = await puppeteer.connect({
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){
@@ -520,35 +522,31 @@ class GoLogin {
520
522
  return this._tz.timezone;
521
523
  }
522
524
 
523
- async getTimezoneWithSocks(proxy) {
524
- const { host, port, username, password } = proxy;
525
+ async getTimezoneWithSocks(params) {
526
+ const { mode = 'http', host, port, username = '', password = '' } = params;
525
527
  let body;
526
528
 
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');
529
+ let proxy = mode + '://';
530
+ if (username) {
531
+ const resultPassword = password ? ':' + password + '@' : '@';
532
+ proxy += username + resultPassword;
533
+ }
534
+ proxy += host + ':' + port;
542
535
 
536
+ const agent = new ProxyAgent(proxy, { tunnel: true, timeout: 10000 });
537
+
538
+ const checkData = await new Promise((resolve, reject) => {
539
+ https.get('https://time.gologin.com/timezone', { agent }, (res) => {
543
540
  let resultResponse = '';
544
541
  res.on('data', (data) => resultResponse += data);
545
542
 
546
543
  res.on('end', () => {
547
- clearTimeout(timer);
548
544
  let parsedData;
549
545
  try {
550
546
  parsedData = JSON.parse(resultResponse);
551
- } catch (e) {}
547
+ } catch (e) {
548
+ reject(e);
549
+ }
552
550
 
553
551
  resolve({
554
552
  ...res,
@@ -558,7 +556,7 @@ class GoLogin {
558
556
  }).on('error', (err) => reject(err));
559
557
  });
560
558
 
561
- console.log('checkData:', checkData);
559
+ // console.log('checkData:', checkData);
562
560
  body = checkData.body || {};
563
561
  if (!body.ip && checkData.statusCode.toString().startsWith('4')) {
564
562
  throw checkData;
@@ -697,7 +695,7 @@ class GoLogin {
697
695
  await rimraf(path.join(this.tmpdir, `gologin_${this.profile_id}_upload.zip`));
698
696
  }
699
697
 
700
- async stopAndCommit(options, local= false) {
698
+ async stopAndCommit(options, local = false) {
701
699
  if (this.is_stopping) {
702
700
  return true;
703
701
  }
@@ -1060,12 +1058,12 @@ class GoLogin {
1060
1058
  return this.stopRemote();
1061
1059
  }
1062
1060
 
1063
- await this.stopAndCommit(false, {});
1061
+ await this.stopAndCommit({ posting: false }, false);
1064
1062
  }
1065
1063
 
1066
1064
  async stopLocal(options) {
1067
- const opts = options || {posting: false};
1068
- await this.stopAndCommit(true, opts.posting);
1065
+ const opts = options || { posting: false };
1066
+ await this.stopAndCommit(options, true);
1069
1067
  }
1070
1068
 
1071
1069
  async waitDebuggingUrl(delay_ms, try_count=0) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "gologin",
3
- "version": "1.0.24",
3
+ "version": "1.0.28",
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
  },