gologin 1.0.23 → 1.0.27

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.
@@ -29,10 +29,11 @@ class CookiesManager {
29
29
  const chunckedCookiesArr = this.chunk(cookiesArr, MAX_SQLITE_VARIABLES);
30
30
 
31
31
  return chunckedCookiesArr.map((cookies) => {
32
- const queryPlaceholders = cookies.map(() => '(?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)').join(', ');
33
- const query = `insert or replace into cookies (creation_utc, host_key, name, value, path, expires_utc, is_secure, is_httponly, last_access_utc, is_persistent, encrypted_value, samesite, has_expires) values ${queryPlaceholders}`;
32
+ const queryPlaceholders = cookies.map(() => '(?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)').join(', ');
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
35
  const creationDate = cookie.creationDate ? cookie.creationDate : this.unixToLDAP(todayUnix);
36
+ let expirationDate = cookie.session ? 0 : this.unixToLDAP(cookie.expirationDate);
36
37
  const encryptedValue = cookie.value;
37
38
  const samesite = Object.keys(SAME_SITE).find((key) => SAME_SITE[key] === (cookie.sameSite || '-1'));
38
39
  const isSecure =
@@ -40,7 +41,6 @@ class CookiesManager {
40
41
  let isPersistent = [undefined, null].includes(cookie.session)
41
42
  ? Number(expirationDate !== 0)
42
43
  : Number(!cookie.session);
43
- let expirationDate = cookie.session ? 0 : this.unixToLDAP(cookie.expirationDate);
44
44
 
45
45
  if (/^(\.)?mail.google.com$/.test(cookie.domain) && cookie.name === 'COMPASS') {
46
46
  expirationDate = 0;
@@ -49,6 +49,7 @@ class CookiesManager {
49
49
 
50
50
  return [
51
51
  creationDate,
52
+ '', // top_frame_site_key
52
53
  cookie.domain,
53
54
  cookie.name,
54
55
  '', // value
@@ -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({
@@ -15,7 +15,7 @@ const delay = ms => new Promise(res => setTimeout(res, ms));
15
15
  os: 'mac',
16
16
  navigator: {
17
17
  language: 'enUS',
18
- userAgent: 'MyUserAgent',
18
+ userAgent: 'random', // get random user agent for selected os
19
19
  resolution: '1024x768',
20
20
  platform: 'mac',
21
21
  }
@@ -31,6 +31,6 @@ const delay = ms => new Promise(res => setTimeout(res, ms));
31
31
  const profile = await GL.getProfile(profile_id);
32
32
 
33
33
  console.log('new profile name=', profile.name);
34
-
34
+
35
35
  //await GL.delete(profile_id);
36
36
  })();
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';
@@ -122,7 +123,7 @@ class GoLogin {
122
123
  })
123
124
  debug(profileResponse.body);
124
125
  if (profileResponse.statusCode !== 200) {
125
- throw new Error(`Gologin /browser/${id} response error ${profileResponse.statusCode}`);
126
+ throw new Error(`Gologin /browser/${id} response error ${profileResponse.statusCode} INVALID TOKEN OR PROFILE NOT FOUND`);
126
127
  }
127
128
 
128
129
  if(profileResponse.statusCode == 401){
@@ -520,35 +521,31 @@ class GoLogin {
520
521
  return this._tz.timezone;
521
522
  }
522
523
 
523
- async getTimezoneWithSocks(proxy) {
524
- const { host, port, username, password } = proxy;
524
+ async getTimezoneWithSocks(params) {
525
+ const { mode = 'http', host, port, username = '', password = '' } = params;
525
526
  let body;
526
527
 
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');
528
+ let proxy = mode + '://';
529
+ if (username) {
530
+ const resultPassword = password ? ':' + password + '@' : '@';
531
+ proxy += username + resultPassword;
532
+ }
533
+ proxy += host + ':' + port;
534
+
535
+ const agent = new ProxyAgent(proxy, { tunnel: true, timeout: 10000 });
542
536
 
537
+ const checkData = await new Promise((resolve, reject) => {
538
+ https.get('https://time.gologin.com/timezone', { agent }, (res) => {
543
539
  let resultResponse = '';
544
540
  res.on('data', (data) => resultResponse += data);
545
541
 
546
542
  res.on('end', () => {
547
- clearTimeout(timer);
548
543
  let parsedData;
549
544
  try {
550
545
  parsedData = JSON.parse(resultResponse);
551
- } catch (e) {}
546
+ } catch (e) {
547
+ reject(e);
548
+ }
552
549
 
553
550
  resolve({
554
551
  ...res,
@@ -558,7 +555,7 @@ class GoLogin {
558
555
  }).on('error', (err) => reject(err));
559
556
  });
560
557
 
561
- console.log('checkData:', checkData);
558
+ // console.log('checkData:', checkData);
562
559
  body = checkData.body || {};
563
560
  if (!body.ip && checkData.statusCode.toString().startsWith('4')) {
564
561
  throw checkData;
@@ -879,9 +876,12 @@ class GoLogin {
879
876
  mode: 'alerted',
880
877
  },
881
878
  };
882
-
879
+ let user_agent = options.navigator?.userAgent;
880
+ let orig_user_agent = json.navigator.userAgent;
883
881
  Object.keys(options).map((e)=>{ json[e] = options[e] });
884
-
882
+ if(user_agent=='random'){
883
+ json.navigator.userAgent = orig_user_agent;
884
+ }
885
885
  // console.log('profileOptions', json);
886
886
 
887
887
  const response = await requests.post(`${API_URL}/browser`, {
@@ -891,7 +891,15 @@ class GoLogin {
891
891
  },
892
892
  json,
893
893
  });
894
- // console.log(JSON.stringify(response.body));
894
+
895
+ if(response.body.statusCode==400){
896
+ throw new Error(`gologin failed account creation with status code, ${data.statusCode} DATA ${JSON.stringify(response.body.message)}`);
897
+ }
898
+
899
+ if(response.body.statusCode==500){
900
+ throw new Error(`gologin failed account creation with status code, ${data.statusCode}`);
901
+ }
902
+ debug(JSON.stringify(response.body));
895
903
  return response.body.id;
896
904
  }
897
905
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "gologin",
3
- "version": "1.0.23",
3
+ "version": "1.0.27",
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
  },
@@ -0,0 +1,30 @@
1
+ from gologin import GoLogin
2
+
3
+
4
+ gl = GoLogin({
5
+ "token": "yU0token",
6
+ })
7
+
8
+ profile_id = gl.create({
9
+ "name": 'profile_mac',
10
+ "os": 'mac',
11
+ "navigator": {
12
+ "language": 'enUS',
13
+ "userAgent": 'MyUserAgent',
14
+ "resolution": '1024x768',
15
+ "platform": 'mac',
16
+ }
17
+ });
18
+
19
+ print('profile id=', profile_id);
20
+
21
+ gl.update({
22
+ "id": profile_id,
23
+ "name": 'profile_mac2',
24
+ });
25
+
26
+ profile = gl.getProfile(profile_id);
27
+
28
+ print('new profile name=', profile.get("name"));
29
+
30
+ gl.delete(profile_id)
@@ -422,9 +422,12 @@ class GoLogin(object):
422
422
  def update(self, options):
423
423
  self.profile_id = options.get('id')
424
424
  profile = self.getProfile()
425
+ #print("profile", profile)
425
426
  for k,v in options.items():
426
427
  profile[k] = v
427
- return json.loads(requests.put(API_URL + '/browser/' + self.profile_id, headers=self.headers(), json=profile).content.decode('utf-8'))
428
+ resp = requests.put(API_URL + '/browser/' + self.profile_id, headers=self.headers(), json=profile).content.decode('utf-8')
429
+ #print("update", resp)
430
+ #return json.loads(resp)
428
431
 
429
432
  def waitDebuggingUrl(self, delay_s, try_count=3):
430
433
  url = 'https://' + self.profile_id + '.orbita.gologin.com/json/version'