gologin 1.0.27 → 1.0.31

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
 
@@ -260,7 +260,8 @@ class BrowserChecker {
260
260
  async replaceBrowser() {
261
261
  console.log('Copy Orbita to target path');
262
262
  if (PLATFORM === 'darwin') {
263
- await rmdir(path.join(this.#browserPath, 'Orbita-Browser.app'), { recursive: true });
263
+ await this.deleteDir(path.join(this.#browserPath, 'Orbita-Browser.app'));
264
+
264
265
  const files = await readdir(path.join(this.#browserPath, EXTRACTED_FOLDER));
265
266
  const promises = [];
266
267
  files.forEach((filename) => {
@@ -268,22 +269,25 @@ class BrowserChecker {
268
269
  promises.push(copyFile(path.join(this.#browserPath, EXTRACTED_FOLDER, filename), path.join(this.#browserPath, filename)));
269
270
  }
270
271
  });
272
+
271
273
  return Promise.all(promises);
272
- } else {
273
- await rmdir(path.join(this.#browserPath, 'orbita-browser'), { recursive: true });
274
- await this.copyDir(
275
- path.join(this.#browserPath, EXTRACTED_FOLDER, 'orbita-browser'),
276
- path.join(this.#browserPath, 'orbita-browser')
277
- );
278
274
  }
275
+
276
+ const targetBrowserPath = path.join(this.#browserPath, 'orbita-browser');
277
+ await this.deleteDir(targetBrowserPath);
278
+
279
+ await this.copyDir(
280
+ path.join(this.#browserPath, EXTRACTED_FOLDER, 'orbita-browser'),
281
+ targetBrowserPath
282
+ );
279
283
  }
280
284
 
281
285
  async deleteOldArchives(deleteCurrentBrowser = false) {
282
286
  if (deleteCurrentBrowser) {
283
- return await rmdir(path.join(this.#browserPath), { recursive: true });
287
+ return this.deleteDir(path.join(this.#browserPath));
284
288
  }
285
289
 
286
- await rmdir(path.join(this.#browserPath, EXTRACTED_FOLDER), { recursive: true });
290
+ await this.deleteDir(path.join(this.#browserPath, EXTRACTED_FOLDER));
287
291
  return readdir(this.#browserPath)
288
292
  .then((files) => {
289
293
  const promises = [];
@@ -355,6 +359,19 @@ class BrowserChecker {
355
359
  get getOrbitaPath() {
356
360
  return this.#executableFilePath;
357
361
  }
362
+
363
+ async deleteDir(path = '') {
364
+ if (!path) {
365
+ return;
366
+ }
367
+
368
+ const directoryExists = await access(path).then(() => true).catch(() => false);
369
+ if (!directoryExists) {
370
+ return;
371
+ }
372
+
373
+ return rmdir(path, { recursive: true });
374
+ }
358
375
  }
359
376
 
360
377
  module.exports = BrowserChecker;
@@ -1,7 +1,9 @@
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',
@@ -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
@@ -47,7 +47,6 @@ class GoLogin {
47
47
  this.browserChecker = new BrowserChecker();
48
48
  this.uploadCookiesToServer = options.uploadCookiesToServer || false;
49
49
  this.writeCookesFromServer = options.writeCookesFromServer || true;
50
- this.cookiesFilePath = path.join(os.tmpdir(), `gologin_profile_${this.profile_id}`, 'Default', 'Cookies');
51
50
  this.remote_debugging_port = options.remote_debugging_port || 0;
52
51
  this.timezone = options.timezone;
53
52
 
@@ -59,6 +58,7 @@ class GoLogin {
59
58
  }
60
59
  }
61
60
 
61
+ this.cookiesFilePath = path.join(this.tmpdir, `gologin_profile_${this.profile_id}`, 'Default', 'Cookies');
62
62
  this.profile_zip_path = path.join(this.tmpdir, `gologin_${this.profile_id}.zip`);
63
63
  debug('INIT GOLOGIN', this.profile_id);
64
64
  }
@@ -67,6 +67,7 @@ class GoLogin {
67
67
 
68
68
  async setProfileId(profile_id) {
69
69
  this.profile_id = profile_id;
70
+ this.cookiesFilePath = path.join(this.tmpdir, `gologin_profile_${this.profile_id}`, 'Default', 'Cookies');
70
71
  this.profile_zip_path = path.join(this.tmpdir, `gologin_${this.profile_id}.zip`);
71
72
  }
72
73
 
@@ -358,6 +359,11 @@ class GoLogin {
358
359
  profile.proxy.password = _.get(profile, 'autoProxyPassword');
359
360
  }
360
361
  // console.log('proxy=', proxy);
362
+
363
+ if (proxy.mode === 'geolocation') {
364
+ proxy.mode = 'http';
365
+ }
366
+
361
367
  if (proxy.mode === 'none') {
362
368
  proxy = null;
363
369
  }
@@ -385,6 +391,8 @@ class GoLogin {
385
391
  publicIP: _.get(profile, 'webRTC.fillBasedOnIp') ? this._tz.ip : _.get(profile, 'webRTC.publicIp'),
386
392
  localIps: _.get(profile, 'webRTC.localIps', []),
387
393
  };
394
+
395
+ debug('profile.webRtc=', profile.webRtc);
388
396
 
389
397
  const audioContext = profile.audioContext || {};
390
398
  const { mode: audioCtxMode = 'off', noise: audioCtxNoise } = audioContext;
@@ -498,6 +506,7 @@ class GoLogin {
498
506
  }
499
507
 
500
508
  async getTimeZone(proxy) {
509
+ debug('getting timeZone proxy=', proxy);
501
510
  if(this.timezone){
502
511
  debug('getTimeZone from options', this.timezone);
503
512
  this._tz = this.timezone;
@@ -505,16 +514,16 @@ class GoLogin {
505
514
  }
506
515
 
507
516
  let data = null;
508
- if (proxy) {
517
+ if (proxy!==null && proxy.mode !== "none") {
509
518
  if (proxy.mode.includes('socks')) {
510
519
  return this.getTimezoneWithSocks(proxy);
511
520
  }
512
521
 
513
522
  const proxyUrl = `${proxy.mode}://${proxy.username}:${proxy.password}@${proxy.host}:${proxy.port}`;
514
523
  debug('getTimeZone start https://time.gologin.com', proxyUrl);
515
- 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 });
516
525
  } else {
517
- 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 });
518
527
  }
519
528
  debug('getTimeZone finish', data.body);
520
529
  this._tz = JSON.parse(data.body);
@@ -562,7 +571,6 @@ class GoLogin {
562
571
  }
563
572
  debug('getTimeZone finish', body.body);
564
573
  this._tz = body;
565
-
566
574
  return this._tz.timezone;
567
575
  }
568
576
 
@@ -694,7 +702,7 @@ class GoLogin {
694
702
  await rimraf(path.join(this.tmpdir, `gologin_${this.profile_id}_upload.zip`));
695
703
  }
696
704
 
697
- async stopAndCommit(options, local= false) {
705
+ async stopAndCommit(options, local = false) {
698
706
  if (this.is_stopping) {
699
707
  return true;
700
708
  }
@@ -1034,6 +1042,12 @@ class GoLogin {
1034
1042
  if (!this.executablePath) {
1035
1043
  await this.checkBrowser();
1036
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
+ }
1037
1051
 
1038
1052
  await this.createStartup();
1039
1053
  // await this.createBrowserExtension();
@@ -1057,12 +1071,12 @@ class GoLogin {
1057
1071
  return this.stopRemote();
1058
1072
  }
1059
1073
 
1060
- await this.stopAndCommit(false, {});
1074
+ await this.stopAndCommit({ posting: false }, false);
1061
1075
  }
1062
1076
 
1063
1077
  async stopLocal(options) {
1064
- const opts = options || {posting: false};
1065
- await this.stopAndCommit(true, opts.posting);
1078
+ const opts = options || { posting: false };
1079
+ await this.stopAndCommit(options, true);
1066
1080
  }
1067
1081
 
1068
1082
  async waitDebuggingUrl(delay_ms, try_count=0) {
@@ -1084,7 +1098,7 @@ class GoLogin {
1084
1098
  if (try_count < 3) {
1085
1099
  return this.waitDebuggingUrl(delay_ms, try_count+1);
1086
1100
  }
1087
- return { 'status': 'failure', wsUrl }
1101
+ return { 'status': 'failure', wsUrl, 'message': 'Check proxy settings', 'profile_id': this.profile_id }
1088
1102
  }
1089
1103
 
1090
1104
  wsUrl = wsUrl.replace('ws://', `wss://`).replace('127.0.0.1', `${this.profile_id}.orbita.gologin.com`)
@@ -1109,6 +1123,28 @@ class GoLogin {
1109
1123
  }
1110
1124
 
1111
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
+
1112
1148
  let wsUrl = await this.waitDebuggingUrl(delay_ms);
1113
1149
  return { 'status': 'success', wsUrl }
1114
1150
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "gologin",
3
- "version": "1.0.27",
3
+ "version": "1.0.31",
4
4
  "description": "A high-level API to control Orbita browser over GoLogin API",
5
5
  "main": "./gologin.js",
6
6
  "repository": {
@@ -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)