gologin 1.0.18 → 1.0.22

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
@@ -32,7 +32,15 @@ const GoLogin = require('gologin');
32
32
  profile_id: 'yU0Pr0f1leiD',
33
33
  });
34
34
 
35
- const { status, wsUrl } = await GL.start();
35
+ const { status, wsUrl } = await GL.start().catch((e) => {
36
+ console.trace(e);
37
+ return { status: 'failure' };
38
+ });
39
+
40
+ if (status !== 'success') {
41
+ console.log('Invalid status');
42
+ return;
43
+ }
36
44
 
37
45
  const browser = await puppeteer.connect({
38
46
  browserWSEndpoint: wsUrl.toString(),
package/example.js CHANGED
@@ -1,5 +1,5 @@
1
1
  const puppeteer = require('puppeteer-core');
2
- const GoLogin = require('gologin');
2
+ const GoLogin = require('./gologin');
3
3
 
4
4
  (async () => {
5
5
  const GL = new GoLogin({
@@ -7,7 +7,16 @@ const GoLogin = require('gologin');
7
7
  profile_id: 'yU0Pr0f1leiD',
8
8
  });
9
9
 
10
- const { status, wsUrl } = await GL.start();
10
+ const { status, wsUrl } = await GL.start().catch((e) => {
11
+ console.trace(e);
12
+ return { status: 'failure' };
13
+ });
14
+
15
+ if (status !== 'success') {
16
+ console.log('Invalid status');
17
+ return;
18
+ }
19
+
11
20
  const browser = await puppeteer.connect({
12
21
  browserWSEndpoint: wsUrl.toString(),
13
22
  ignoreHTTPSErrors: true,
@@ -13,6 +13,13 @@ const GoLogin = require('../gologin');
13
13
  });
14
14
 
15
15
  const page = await browser.newPage();
16
+ const viewPort = GL.getViewPort();
17
+ await page.setViewport({ width: Math.round(viewPort.width * 0.994), height: Math.round(viewPort.height * 0.92) });
18
+ const session = await page.target().createCDPSession();
19
+ const { windowId } = await session.send('Browser.getWindowForTarget');
20
+ await session.send('Browser.setWindowBounds', { windowId, bounds: viewPort });
21
+ await session.detach();
22
+
16
23
  await page.goto('https://www.amazon.com/-/dp/B0771V1JZX');
17
24
  const content = await page.content();
18
25
  const matchData = content.match(/'initial': (.*)}/);
@@ -0,0 +1,64 @@
1
+ const puppeteer = require('puppeteer-core');
2
+ const GoLogin = require('../gologin');
3
+
4
+ const delay = ms => new Promise(res => setTimeout(res, ms));
5
+
6
+ (async () =>{
7
+ const GL = new GoLogin({
8
+ token: 'yU0token',
9
+ });
10
+
11
+ const profile_id = await GL.create({
12
+ name: 'profile_gmail',
13
+ os: 'lin',
14
+ navigator: {
15
+ userAgent: 'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/90.0.4430.85 Safari/537.36',
16
+ resolution: '1280x720',
17
+ language: 'en-GB,en-US;q=0.9,en;q=0.8',
18
+ platform: 'Linux x86_64',
19
+ hardwareConcurrency: 8,
20
+ deviceMemory: 8,
21
+ maxTouchPoints: 5,
22
+ },
23
+ proxy: {
24
+ mode: 'http',
25
+ host: 'proxy_host',
26
+ port: 'proxy_port',
27
+ username: 'proxy_username',
28
+ password: 'proxy_password',
29
+ }
30
+ });
31
+
32
+ console.log('profile id=', profile_id);
33
+ GL.setProfileId(profile_id);
34
+
35
+ const {status, wsUrl} = await GL.start();
36
+ const browser = await puppeteer.connect({
37
+ browserWSEndpoint: wsUrl.toString(),
38
+ ignoreHTTPSErrors: true,
39
+ });
40
+
41
+ const page = await browser.newPage();
42
+
43
+ const viewPort = GL.getViewPort();
44
+ await page.setViewport({ width: Math.round(viewPort.width * 0.994), height: Math.round(viewPort.height * 0.92) });
45
+ const session = await page.target().createCDPSession();
46
+ const { windowId } = await session.send('Browser.getWindowForTarget');
47
+ await session.send('Browser.setWindowBounds', { windowId, bounds: viewPort });
48
+ await session.detach();
49
+
50
+ await page.goto('https://gmail.com');
51
+ await delay(1000);
52
+ await page.goto('https://accounts.google.com/signup/v2?service=mail&continue=https%3A%2F%2Fmail.google.com%2Fmail%2F&flowName=GlifWebSignIn&flowEntry=SignUp');
53
+ await delay(3000);
54
+ await page.type('#firstName', 'first_name', { delay: 100 });
55
+ await page.type('#lastName', 'last_name', { delay: 100 });
56
+ await page.type('#username', 'username', { delay: 100 });
57
+ await page.type('[name=Passwd]', 'pa$$w0rd', { delay: 100 });
58
+ await page.type('[name=ConfirmPasswd]', 'pa$$w0rd', { delay: 100 });
59
+ await page.click('#accountDetailsNext > div > button');
60
+
61
+ await delay(60000)
62
+ await browser.close();
63
+ await GL.stop();
64
+ })();
@@ -0,0 +1,41 @@
1
+ const puppeteer = require('puppeteer-core');
2
+ const GoLogin = require('../gologin');
3
+
4
+ const delay = ms => new Promise(res => setTimeout(res, ms));
5
+
6
+ (async () =>{
7
+ const GL = new GoLogin({
8
+ token: 'yU0token',
9
+ profile_id: 'yU0Pr0f1leiD',
10
+ timezone: {
11
+ ip:'1.1.1.1',
12
+ timezone:'Europe/Amsterdam',
13
+ accuracy:100,
14
+ ll: ['52.3759','4.8975'],
15
+ country: 'NL',
16
+ city: 'Amsterdam',
17
+ stateProv:'',
18
+ }
19
+ });
20
+
21
+ const {status, wsUrl} = await GL.start();
22
+ const browser = await puppeteer.connect({
23
+ browserWSEndpoint: wsUrl.toString(),
24
+ ignoreHTTPSErrors: true,
25
+ });
26
+
27
+ const page = await browser.newPage();
28
+
29
+ const viewPort = GL.getViewPort();
30
+ await page.setViewport({ width: Math.round(viewPort.width * 0.994), height: Math.round(viewPort.height * 0.92) });
31
+ const session = await page.target().createCDPSession();
32
+ const { windowId } = await session.send('Browser.getWindowForTarget');
33
+ await session.send('Browser.setWindowBounds', { windowId, bounds: viewPort });
34
+ await session.detach();
35
+
36
+ await page.goto('https://myip.link');
37
+
38
+ await delay(60000)
39
+ await browser.close();
40
+ await GL.stop();
41
+ })();
package/gologin.js CHANGED
@@ -48,7 +48,8 @@ class GoLogin {
48
48
  this.writeCookesFromServer = options.writeCookesFromServer || true;
49
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
53
  if (options.tmpdir) {
53
54
  this.tmpdir = options.tmpdir;
54
55
  if (!fs.existsSync(this.tmpdir)) {
@@ -81,10 +82,10 @@ class GoLogin {
81
82
  }
82
83
  }
83
84
 
84
- async getNewFingerPrint() {
85
+ async getNewFingerPrint(os) {
85
86
  debug('GETTING FINGERPRINT');
86
87
 
87
- const fpResponse = await requests.get(`${API_URL}/browser/fingerprint?os=lin`, {
88
+ const fpResponse = await requests.get(`${API_URL}/browser/fingerprint?os=${os}`, {
88
89
  json: true,
89
90
  headers: {
90
91
  'Authorization': `Bearer ${this.access_token}`,
@@ -123,6 +124,11 @@ class GoLogin {
123
124
  if (profileResponse.statusCode !== 200) {
124
125
  throw new Error(`Gologin /browser/${id} response error ${profileResponse.statusCode}`);
125
126
  }
127
+
128
+ if(profileResponse.statusCode == 401){
129
+ throw new Error("invalid token");
130
+ }
131
+
126
132
  return JSON.parse(profileResponse.body);
127
133
  }
128
134
 
@@ -355,9 +361,11 @@ class GoLogin {
355
361
  proxy = null;
356
362
  }
357
363
  this.proxy = proxy;
358
- this.profile_name = name;
359
364
 
360
- await this.getTimeZone(proxy);
365
+ await this.getTimeZone(proxy).catch((e) => {
366
+ console.error('Proxy Error. Check it and try again.');
367
+ throw e;
368
+ });
361
369
 
362
370
  const [latitude, longitude] = this._tz.ll;
363
371
  const accuracy = this._tz.accuracy;
@@ -369,6 +377,7 @@ class GoLogin {
369
377
  accuracy
370
378
  };
371
379
  profile.geoLocation = this.getGeolocationParams(profileGeolocation, tzGeoLocation);
380
+ profile.name = name;
372
381
 
373
382
  profile.webRtc = {
374
383
  mode: _.get(profile, 'webRTC.mode') === 'alerted' ? 'public' : _.get(profile, 'webRTC.mode'),
@@ -488,6 +497,12 @@ class GoLogin {
488
497
  }
489
498
 
490
499
  async getTimeZone(proxy) {
500
+ if(this.timezone){
501
+ debug('getTimeZone from options', this.timezone);
502
+ this._tz = this.timezone;
503
+ return this._tz.timezone;
504
+ }
505
+
491
506
  let data = null;
492
507
  if (proxy) {
493
508
  if (proxy.mode.includes('socks')) {
@@ -496,9 +511,9 @@ class GoLogin {
496
511
 
497
512
  const proxyUrl = `${proxy.mode}://${proxy.username}:${proxy.password}@${proxy.host}:${proxy.port}`;
498
513
  debug('getTimeZone start https://time.gologin.com', proxyUrl);
499
- data = await requests.get('https://time.gologin.com', { proxy: proxyUrl });
514
+ data = await requests.get('https://time.gologin.com', { proxy: proxyUrl, timeout: 10 * 1000, maxAttempts: 2 });
500
515
  } else {
501
- data = await requests.get('https://time.gologin.com');
516
+ data = await requests.get('https://time.gologin.com', { timeout: 10 * 1000, maxAttempts: 2 });
502
517
  }
503
518
  debug('getTimeZone finish', data.body);
504
519
  this._tz = JSON.parse(data.body);
@@ -543,6 +558,7 @@ class GoLogin {
543
558
  }).on('error', (err) => reject(err));
544
559
  });
545
560
 
561
+ console.log('checkData:', checkData);
546
562
  body = checkData.body || {};
547
563
  if (!body.ip && checkData.statusCode.toString().startsWith('4')) {
548
564
  throw checkData;
@@ -557,17 +573,19 @@ class GoLogin {
557
573
  const profile_path = this.profilePath();
558
574
 
559
575
  let proxy = this.proxy;
560
- let profile_name = this.profile_name;
561
576
  proxy = `${proxy.mode}://${proxy.host}:${proxy.port}`;
562
577
 
563
578
  const env = {};
564
579
  Object.keys(process.env).forEach((key) => {
565
580
  env[key] = process.env[key];
566
581
  });
567
- const tz = await this.getTimeZone(this.proxy);
582
+ const tz = await this.getTimeZone(this.proxy).catch((e) => {
583
+ console.error('Proxy Error. Check it and try again.');
584
+ throw e;
585
+ });
568
586
  env['TZ'] = tz;
569
587
 
570
- let params = [`--proxy-server=${proxy}`, `--user-data-dir=${profile_path}`, `--password-store=basic`, `--tz=${tz}`, `--gologin-profile=${profile_name}`, `--lang=en`]
588
+ let params = [`--proxy-server=${proxy}`, `--user-data-dir=${profile_path}`, `--password-store=basic`, `--tz=${tz}`, `--lang=en`]
571
589
  if (Array.isArray(this.extra_params) && this.extra_params.length) {
572
590
  params = params.concat(this.extra_params);
573
591
  }
@@ -580,16 +598,14 @@ class GoLogin {
580
598
  }
581
599
 
582
600
  async spawnBrowser() {
583
-
584
601
  let remote_debugging_port = this.remote_debugging_port;
585
- if(remote_debugging_port == 0){
602
+ if(!remote_debugging_port){
586
603
  remote_debugging_port = await this.getRandomPort();
587
604
  }
588
605
 
589
606
  const profile_path = this.profilePath();
590
607
 
591
608
  let proxy = this.proxy;
592
- let profile_name = this.profile_name;
593
609
  let proxy_host = '';
594
610
  if (proxy) {
595
611
  proxy_host = this.proxy.host;
@@ -604,7 +620,10 @@ class GoLogin {
604
620
  Object.keys(process.env).forEach((key) => {
605
621
  env[key] = process.env[key];
606
622
  });
607
- const tz = await this.getTimeZone(this.proxy);
623
+ const tz = await this.getTimeZone(this.proxy).catch((e) => {
624
+ console.error('Proxy Error. Check it and try again.');
625
+ throw e;
626
+ });
608
627
  env['TZ'] = tz;
609
628
 
610
629
  if (this.vnc_port) {
@@ -612,20 +631,22 @@ class GoLogin {
612
631
  debug('RUNNING', script_path, ORBITA_BROWSER, remote_debugging_port, proxy, profile_path, this.vnc_port);
613
632
  execFile(
614
633
  script_path,
615
- [ORBITA_BROWSER, remote_debugging_port, proxy, profile_path, this.vnc_port, tz, profile_name],
634
+ [ORBITA_BROWSER, remote_debugging_port, proxy, profile_path, this.vnc_port, tz],
616
635
  { env }
617
636
  );
618
637
  } else {
619
638
  const [splittedLangs] = this.language.split(';');
620
- const browserLangs = splittedLangs.split(',');
621
- const browserLang = browserLangs[browserLangs.length - 1];
639
+ let [browserLang] = splittedLangs.split(',');
640
+ if (process.platform === 'darwin') {
641
+ browserLang = 'en-US';
642
+ }
643
+
622
644
  let params = [
623
645
  `--remote-debugging-port=${remote_debugging_port}`,
624
646
  `--user-data-dir=${profile_path}`,
625
647
  `--password-store=basic`,
626
- `--tz=${tz}`,
627
- `--gologin-profile='${profile_name}'`,
628
- `--lang=${browserLang || 'en'}`,
648
+ `--tz=${tz}`,
649
+ `--lang=${browserLang}`,
629
650
  ];
630
651
 
631
652
  if (this.fontsMasking) {
@@ -825,6 +846,15 @@ class GoLogin {
825
846
  debug('createProfile', options);
826
847
 
827
848
  const fingerprint = await this.getRandomFingerprint(options);
849
+ debug("fingerprint=", fingerprint)
850
+
851
+ if(fingerprint.statusCode == 500){
852
+ throw new Error("no valid random fingerprint check os param");
853
+ }
854
+
855
+ if(fingerprint.statusCode == 401){
856
+ throw new Error("invalid token");
857
+ }
828
858
 
829
859
  const { navigator, fonts, webGLMetadata, webRTC } = fingerprint;
830
860
  let deviceMemory = navigator.deviceMemory || 2;
@@ -922,9 +952,17 @@ class GoLogin {
922
952
  };
923
953
 
924
954
  async postCookies(profileId, cookies) {
955
+ const formattedCookies = cookies.map(cookie => {
956
+ if (!['no_restriction', 'lax', 'strict', 'unspecified'].includes(cookie.sameSite)) {
957
+ cookie.sameSite = 'unspecified';
958
+ }
959
+
960
+ return cookie;
961
+ });
962
+
925
963
  const response = await BrowserUserDataManager.uploadCookies({
926
964
  profileId,
927
- cookies,
965
+ cookies: formattedCookies,
928
966
  API_BASE_URL: API_URL,
929
967
  ACCESS_TOKEN: this.access_token,
930
968
  });
@@ -1052,6 +1090,11 @@ class GoLogin {
1052
1090
  'Authorization': `Bearer ${this.access_token}`
1053
1091
  }
1054
1092
  });
1093
+
1094
+ if(profileResponse.statusCode == 401){
1095
+ throw new Error("invalid token");
1096
+ }
1097
+
1055
1098
  debug('profileResponse', profileResponse.statusCode, profileResponse.body);
1056
1099
  if (profileResponse.statusCode !== 202) {
1057
1100
  return {'status': 'failure', 'code': profileResponse.statusCode};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "gologin",
3
- "version": "1.0.18",
3
+ "version": "1.0.22",
4
4
  "description": "A high-level API to control Orbita browser over GoLogin API",
5
5
  "main": "./gologin.js",
6
6
  "repository": {
package/run.sh CHANGED
@@ -1 +1 @@
1
- DISPLAY=:$5 $1 --remote-debugging-port=$2 --proxy-server=$3 --user-data-dir=$4 --tz=$6 --gologin-profile=$7 --load-extension=$8 --password-store=basic --lang=en --new-window
1
+ DISPLAY=:$5 $1 --remote-debugging-port=$2 --proxy-server=$3 --user-data-dir=$4 --tz=$6 --load-extension=$7 --password-store=basic --lang=en --new-window
@@ -0,0 +1,30 @@
1
+ import time
2
+ from sys import platform
3
+ from selenium import webdriver
4
+ from selenium.webdriver.chrome.options import Options
5
+ from gologin import GoLogin
6
+
7
+
8
+ gl = GoLogin({
9
+ "token": "yU0token",
10
+ "profile_id": "yU0Pr0f1leiD",
11
+ "local": True,
12
+ "credentials_enable_service": False,
13
+ })
14
+
15
+ if platform == "linux" or platform == "linux2":
16
+ chrome_driver_path = "./chromedriver"
17
+ elif platform == "darwin":
18
+ chrome_driver_path = "./mac/chromedriver"
19
+ elif platform == "win32":
20
+ chrome_driver_path = "chromedriver.exe"
21
+
22
+ debugger_address = gl.start()
23
+ chrome_options = Options()
24
+ chrome_options.add_experimental_option("debuggerAddress", debugger_address)
25
+ driver = webdriver.Chrome(executable_path=chrome_driver_path, options=chrome_options)
26
+ driver.get("http://www.python.org")
27
+ assert "Python" in driver.title
28
+ driver.close()
29
+ time.sleep(3)
30
+ gl.stop()
@@ -6,16 +6,16 @@ from gologin import GoLogin
6
6
 
7
7
 
8
8
  gl = GoLogin({
9
- 'token': 'yU0token',
10
- 'profile_id': 'yU0Pr0f1leiD',
9
+ "token": "yU0token",
10
+ "profile_id": "yU0Pr0f1leiD",
11
11
  })
12
12
 
13
13
  if platform == "linux" or platform == "linux2":
14
- chrome_driver_path = './chromedriver'
14
+ chrome_driver_path = "./chromedriver"
15
15
  elif platform == "darwin":
16
- chrome_driver_path = './mac/chromedriver'
16
+ chrome_driver_path = "./mac/chromedriver"
17
17
  elif platform == "win32":
18
- chrome_driver_path = 'chromedriver.exe'
18
+ chrome_driver_path = "chromedriver.exe"
19
19
 
20
20
  debugger_address = gl.start()
21
21
  chrome_options = Options()
@@ -19,8 +19,10 @@ class GoLogin(object):
19
19
  self.tmpdir = options.get('tmpdir', tempfile.gettempdir())
20
20
  self.address = options.get('address', '127.0.0.1')
21
21
  self.extra_params = options.get('extra_params', [])
22
- self.port = options.get('port', 3500)
22
+ self.port = options.get('port', 3500)
23
+ self.local = options.get('local', False)
23
24
  self.spawn_browser = options.get('spawn_browser', True)
25
+ self.credentials_enable_service = options.get('credentials_enable_service')
24
26
 
25
27
  home = str(pathlib.Path.home())
26
28
  self.executablePath = options.get('executablePath', os.path.join(home, '.gologin/browser/orbita-browser/chrome'))
@@ -98,13 +100,17 @@ class GoLogin(object):
98
100
  continue
99
101
  if stat.S_ISSOCK(os.stat(path).st_mode):
100
102
  continue
101
- ziph.write(path, path.replace(self.profile_path, ''))
103
+ try:
104
+ ziph.write(path, path.replace(self.profile_path, ''))
105
+ except:
106
+ continue
102
107
 
103
108
  def stop(self):
104
109
  self.sanitizeProfile()
105
- self.commitProfile()
106
- os.remove(self.profile_zip_path_upload)
107
- shutil.rmtree(self.profile_path)
110
+ if self.local==False:
111
+ self.commitProfile()
112
+ os.remove(self.profile_zip_path_upload)
113
+ shutil.rmtree(self.profile_path)
108
114
 
109
115
  def commitProfile(self):
110
116
  zipf = zipfile.ZipFile(self.profile_zip_path_upload, 'w', zipfile.ZIP_DEFLATED)
@@ -338,15 +344,18 @@ class GoLogin(object):
338
344
  exit()
339
345
 
340
346
  gologin = self.convertPreferences(profile)
347
+ if self.credentials_enable_service!=None:
348
+ preferences['credentials_enable_service'] = self.credentials_enable_service
341
349
  preferences['gologin'] = gologin
342
350
  pfile = open(pref_file, 'w')
343
351
  json.dump(preferences, pfile)
344
352
 
345
353
  def createStartup(self):
346
- if os.path.exists(self.profile_path):
354
+ if self.local==False and os.path.exists(self.profile_path):
347
355
  shutil.rmtree(self.profile_path)
348
356
  self.profile = self.getProfile()
349
- self.downloadProfileZip()
357
+ if self.local==False:
358
+ self.downloadProfileZip()
350
359
  self.updatePreferences()
351
360
  return self.profile_path
352
361