gologin 1.0.19 → 1.0.23

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
+ })();
@@ -15,7 +15,7 @@ const GoLogin = require('../gologin');
15
15
  });
16
16
 
17
17
  const page = await browser.newPage();
18
- await page.goto('https://myip.gologin.app/mini');
18
+ await page.goto('https://myip.link');
19
19
  console.log(await page.content());
20
20
  await browser.close();
21
21
  await GL.stopLocal({posting: false});
@@ -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
 
@@ -356,7 +362,10 @@ class GoLogin {
356
362
  }
357
363
  this.proxy = proxy;
358
364
 
359
- 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
+ });
360
369
 
361
370
  const [latitude, longitude] = this._tz.ll;
362
371
  const accuracy = this._tz.accuracy;
@@ -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;
@@ -563,7 +579,10 @@ class GoLogin {
563
579
  Object.keys(process.env).forEach((key) => {
564
580
  env[key] = process.env[key];
565
581
  });
566
- 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
+ });
567
586
  env['TZ'] = tz;
568
587
 
569
588
  let params = [`--proxy-server=${proxy}`, `--user-data-dir=${profile_path}`, `--password-store=basic`, `--tz=${tz}`, `--lang=en`]
@@ -579,7 +598,6 @@ class GoLogin {
579
598
  }
580
599
 
581
600
  async spawnBrowser() {
582
-
583
601
  let remote_debugging_port = this.remote_debugging_port;
584
602
  if(!remote_debugging_port){
585
603
  remote_debugging_port = await this.getRandomPort();
@@ -602,7 +620,10 @@ class GoLogin {
602
620
  Object.keys(process.env).forEach((key) => {
603
621
  env[key] = process.env[key];
604
622
  });
605
- 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
+ });
606
627
  env['TZ'] = tz;
607
628
 
608
629
  if (this.vnc_port) {
@@ -615,14 +636,17 @@ class GoLogin {
615
636
  );
616
637
  } else {
617
638
  const [splittedLangs] = this.language.split(';');
618
- const browserLangs = splittedLangs.split(',');
619
- const browserLang = browserLangs[browserLangs.length - 1];
639
+ let [browserLang] = splittedLangs.split(',');
640
+ if (process.platform === 'darwin') {
641
+ browserLang = 'en-US';
642
+ }
643
+
620
644
  let params = [
621
645
  `--remote-debugging-port=${remote_debugging_port}`,
622
646
  `--user-data-dir=${profile_path}`,
623
647
  `--password-store=basic`,
624
648
  `--tz=${tz}`,
625
- `--lang=${browserLang || 'en'}`,
649
+ `--lang=${browserLang}`,
626
650
  ];
627
651
 
628
652
  if (this.fontsMasking) {
@@ -822,6 +846,15 @@ class GoLogin {
822
846
  debug('createProfile', options);
823
847
 
824
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
+ }
825
858
 
826
859
  const { navigator, fonts, webGLMetadata, webRTC } = fingerprint;
827
860
  let deviceMemory = navigator.deviceMemory || 2;
@@ -919,9 +952,17 @@ class GoLogin {
919
952
  };
920
953
 
921
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
+
922
963
  const response = await BrowserUserDataManager.uploadCookies({
923
964
  profileId,
924
- cookies,
965
+ cookies: formattedCookies,
925
966
  API_BASE_URL: API_URL,
926
967
  ACCESS_TOKEN: this.access_token,
927
968
  });
@@ -1049,6 +1090,11 @@ class GoLogin {
1049
1090
  'Authorization': `Bearer ${this.access_token}`
1050
1091
  }
1051
1092
  });
1093
+
1094
+ if(profileResponse.statusCode == 401){
1095
+ throw new Error("invalid token");
1096
+ }
1097
+
1052
1098
  debug('profileResponse', profileResponse.statusCode, profileResponse.body);
1053
1099
  if (profileResponse.statusCode !== 202) {
1054
1100
  return {'status': 'failure', 'code': profileResponse.statusCode};
@@ -1056,8 +1102,6 @@ class GoLogin {
1056
1102
 
1057
1103
  if (profileResponse.body === 'ok') {
1058
1104
  let wsUrl = await this.waitDebuggingUrl(delay_ms);
1059
- // const wsUrl = `wss://${this.profile_id}.orbita.gologin.app`
1060
- // const wsUrl = `wss://${this.profile_id}.orbita.gologin.com`
1061
1105
  return { 'status': 'success', wsUrl }
1062
1106
  }
1063
1107
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "gologin",
3
- "version": "1.0.19",
3
+ "version": "1.0.23",
4
4
  "description": "A high-level API to control Orbita browser over GoLogin API",
5
5
  "main": "./gologin.js",
6
6
  "repository": {
@@ -28,5 +28,5 @@ chrome.setDefaultService(new chrome.ServiceBuilder('./chromedriver').build());
28
28
  .setChromeOptions(chromeOptions)
29
29
  .build();
30
30
 
31
- await driver.get('https://myip.gologin.app/mini')
31
+ await driver.get('https://myip.link')
32
32
  })();
@@ -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)
@@ -164,9 +170,9 @@ class GoLogin(object):
164
170
  proxy = self.proxy
165
171
  if proxy:
166
172
  proxies = {proxy.get('mode'): self.formatProxyUrlPassword(proxy)}
167
- data = requests.get('https://time.gologin.app', proxies=proxies)
173
+ data = requests.get('https://time.gologin.com', proxies=proxies)
168
174
  else:
169
- data = requests.get('https://time.gologin.app')
175
+ data = requests.get('https://time.gologin.com')
170
176
  return json.loads(data.content.decode('utf-8'))
171
177
 
172
178
 
@@ -299,9 +305,8 @@ class GoLogin(object):
299
305
 
300
306
  def updatePreferences(self):
301
307
  pref_file = os.path.join(self.profile_path, 'Default/Preferences')
302
- pfile = open(pref_file, 'r')
303
- preferences = json.load(pfile)
304
- pfile.close()
308
+ with open(pref_file, 'r', encoding="utf-8") as pfile:
309
+ preferences = json.load(pfile)
305
310
  profile = self.profile
306
311
  proxy = self.profile.get('proxy')
307
312
  # print('proxy=', proxy)
@@ -338,15 +343,18 @@ class GoLogin(object):
338
343
  exit()
339
344
 
340
345
  gologin = self.convertPreferences(profile)
346
+ if self.credentials_enable_service!=None:
347
+ preferences['credentials_enable_service'] = self.credentials_enable_service
341
348
  preferences['gologin'] = gologin
342
349
  pfile = open(pref_file, 'w')
343
350
  json.dump(preferences, pfile)
344
351
 
345
352
  def createStartup(self):
346
- if os.path.exists(self.profile_path):
353
+ if self.local==False and os.path.exists(self.profile_path):
347
354
  shutil.rmtree(self.profile_path)
348
355
  self.profile = self.getProfile()
349
- self.downloadProfileZip()
356
+ if self.local==False:
357
+ self.downloadProfileZip()
350
358
  self.updatePreferences()
351
359
  return self.profile_path
352
360
 
@@ -416,7 +424,7 @@ class GoLogin(object):
416
424
  profile = self.getProfile()
417
425
  for k,v in options.items():
418
426
  profile[k] = v
419
- return json.loads(requests.put(API_URL + '/browser/' + profile_id, headers=self.headers(), json=profile).content.decode('utf-8'))
427
+ return json.loads(requests.put(API_URL + '/browser/' + self.profile_id, headers=self.headers(), json=profile).content.decode('utf-8'))
420
428
 
421
429
  def waitDebuggingUrl(self, delay_s, try_count=3):
422
430
  url = 'https://' + self.profile_id + '.orbita.gologin.com/json/version'