gologin 1.0.37 → 1.0.40

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
@@ -65,15 +65,16 @@ const GoLogin = require('gologin');
65
65
 
66
66
  - `options` <[Object]> Options for profile
67
67
  - `autoUpdateBrowser` <[boolean]> do not ask whether download new browser version (default false)
68
- - `token` <[string]> your API <a href="https://gologin.com/#/personalArea/TokenApi" target="_blank">token</a>
69
- - `profile_id` <[string]> profile ID
70
- - `executablePath` <[string]> path to executable Orbita file. Orbita will be downloaded automatically if not specified.
68
+ - `token` <[string]> your API <a href="https://gologin.com/#/personalArea/TokenApi" target="_blank">token</a>
69
+ - `profile_id` <[string]> profile ID
70
+ - `executablePath` <[string]> path to executable Orbita file. Orbita will be downloaded automatically if not specified.
71
71
  - `remote_debugging_port` <[int]> port for remote debugging
72
- - `vncPort` <[integer]> port of VNC server if you using it
72
+ - `vncPort` <[integer]> port of VNC server if you using it
73
73
  - `tmpdir` <[string]> path to temporary directore for saving profiles
74
74
  - `extra_params` arrayof <[string]> extra params for browser orbita (ex. extentions etc.)
75
75
  - `uploadCookiesToServer` <[boolean]> upload cookies to server after profile stopping (default false)
76
76
  - `writeCookesFromServer` <[boolean]> download cookies from server and write to profile cookies file (default true)
77
+ - `skipOrbitaHashChecking` <[boolean]> skip hash checking for Orbita after downloading process (default false)
77
78
 
78
79
  ```js
79
80
  const GoLogin = require('gologin');
@@ -39,8 +39,10 @@ class BrowserChecker {
39
39
  #homedir;
40
40
  #browserPath;
41
41
  #executableFilePath;
42
+ #skipOrbitaHashChecking = false;
42
43
 
43
- constructor() {
44
+ constructor(skipOrbitaHashChecking) {
45
+ this.#skipOrbitaHashChecking = skipOrbitaHashChecking;
44
46
  this.#homedir = os.homedir();
45
47
  this.#browserPath = path.join(this.#homedir, '.gologin', 'browser');
46
48
 
@@ -221,6 +223,10 @@ class BrowserChecker {
221
223
  }
222
224
 
223
225
  async checkBrowserSum() {
226
+ if (this.#skipOrbitaHashChecking) {
227
+ return Promise.resolve();
228
+ }
229
+
224
230
  console.log('Orbita hash checking');
225
231
  if (PLATFORM === 'win32') {
226
232
  return Promise.resolve();
@@ -58,9 +58,9 @@ class BrowserUserDataManager {
58
58
  const fontsToDownload = fontsList.filter(font => !files.includes(font));
59
59
 
60
60
  let promises = fontsToDownload.map(font => request.get(FONTS_URL + font, {
61
- maxAttempts: 3,
61
+ maxAttempts: 5,
62
62
  retryDelay: 2000,
63
- timeout: 10 * 1000,
63
+ timeout: 30 * 1000,
64
64
  })
65
65
  .pipe(createWriteStream(path.join(browserFontsPath, font)))
66
66
  );
package/gologin.js CHANGED
@@ -8,7 +8,6 @@ const rimraf = util.promisify(require('rimraf'));
8
8
  const { access, unlink, writeFile, readFile } = require('fs').promises;
9
9
  const exec = util.promisify(require('child_process').exec);
10
10
  const { spawn, execFile } = require('child_process');
11
- const FormData = require('form-data');
12
11
  const ProxyAgent = require('simple-proxy-agent');
13
12
  const decompress = require('decompress');
14
13
  const decompressUnzip = require('decompress-unzip');
@@ -30,7 +29,7 @@ const OS_PLATFORM = process.platform;
30
29
  const delay = (time) => new Promise((resolve) => setTimeout(resolve, time));
31
30
 
32
31
  class GoLogin {
33
- constructor(options) {
32
+ constructor(options = {}) {
34
33
  this.is_remote = options.remote || false;
35
34
  this.access_token = options.token;
36
35
  this.profile_id = options.profile_id;
@@ -45,7 +44,7 @@ class GoLogin {
45
44
  this.profileOs = 'lin';
46
45
  this.tmpdir = os.tmpdir();
47
46
  this.autoUpdateBrowser = !!options.autoUpdateBrowser;
48
- this.browserChecker = new BrowserChecker();
47
+ this.browserChecker = new BrowserChecker(options.skipOrbitaHashChecking);
49
48
  this.uploadCookiesToServer = options.uploadCookiesToServer || false;
50
49
  this.writeCookesFromServer = options.writeCookesFromServer || true;
51
50
  this.remote_debugging_port = options.remote_debugging_port || 0;
@@ -123,12 +122,17 @@ class GoLogin {
123
122
  'Authorization': `Bearer ${this.access_token}`
124
123
  }
125
124
  })
126
- debug(profileResponse.body);
125
+ debug("profileResponse", profileResponse.statusCode, profileResponse.body);
126
+
127
127
 
128
128
  if (profileResponse.statusCode === 404) {
129
129
  throw new Error(JSON.parse(profileResponse.body).message);
130
130
  }
131
131
 
132
+ if (profileResponse.statusCode === 403) {
133
+ throw new Error(JSON.parse(profileResponse.body).message);
134
+ }
135
+
132
136
  if (profileResponse.statusCode !== 200) {
133
137
  throw new Error(`Gologin /browser/${id} response error ${profileResponse.statusCode} INVALID TOKEN OR PROFILE NOT FOUND`);
134
138
  }
@@ -221,7 +225,7 @@ class GoLogin {
221
225
 
222
226
  async emptyProfileFolder() {
223
227
  debug('get emptyProfileFolder');
224
- const profile = await readFile(path.resolve(__dirname, 'gologin_zeroprofile.zip'));
228
+ const profile = await readFile(path.resolve(__dirname, 'zero_profile.zip'));
225
229
  debug('emptyProfileFolder LENGTH ::', profile.length);
226
230
  return profile;
227
231
  }
@@ -282,10 +286,6 @@ class GoLogin {
282
286
  );
283
287
  }
284
288
 
285
- async checkLocalProfile() {
286
-
287
- }
288
-
289
289
  async createStartup(local=false) {
290
290
  const profilePath = path.join(this.tmpdir, `gologin_profile_${this.profile_id}`);
291
291
  let profile;
@@ -337,8 +337,15 @@ class GoLogin {
337
337
 
338
338
  debug('Cleaning up..', profilePath);
339
339
 
340
- await this.extractProfile(profilePath, this.profile_zip_path);
341
- debug('extraction done');
340
+ try {
341
+ await this.extractProfile(profilePath, this.profile_zip_path);
342
+ debug('extraction done');
343
+ } catch(e) {
344
+ console.trace(e);
345
+ profile_folder = await this.emptyProfileFolder();
346
+ await writeFile(this.profile_zip_path, profile_folder);
347
+ await this.extractProfile(profilePath, this.profile_zip_path);
348
+ }
342
349
 
343
350
  const singletonLockPath = path.join(profilePath, 'SingletonLock');
344
351
  const singletonLockExists = await access(singletonLockPath).then(() => true).catch(() => false);
@@ -357,7 +364,7 @@ class GoLogin {
357
364
  }
358
365
 
359
366
  const preferences_raw = await readFile(pref_file_name);
360
- let preferences = JSON.parse(preferences_raw.toString());
367
+ let preferences = JSON.parse(preferences_raw.toString());
361
368
  let proxy = _.get(profile, 'proxy');
362
369
  let name = _.get(profile, 'name');
363
370
 
@@ -453,10 +460,19 @@ class GoLogin {
453
460
  throw new Error('No fonts list provided');
454
461
  }
455
462
 
456
- await BrowserUserDataManager.composeFonts(families, profilePath, this.differentOs);
463
+ try{
464
+ await BrowserUserDataManager.composeFonts(families, profilePath, this.differentOs);
465
+ } catch (e) {
466
+ console.trace(e);
467
+ }
457
468
  }
458
469
 
459
470
  const [languages] = this.language.split(';');
471
+
472
+ if(preferences.gologin==null){
473
+ preferences.gologin = {};
474
+ }
475
+
460
476
  preferences.gologin.langHeader = gologin.language;
461
477
  preferences.gologin.languages = languages;
462
478
 
@@ -1142,25 +1158,28 @@ class GoLogin {
1142
1158
 
1143
1159
  async startRemote(delay_ms = 10000) {
1144
1160
  debug(`startRemote ${this.profile_id}`);
1161
+
1162
+ /*
1163
+ if (profileResponse.statusCode !== 202) {
1164
+ return {'status': 'failure', 'code': profileResponse.statusCode};
1165
+ }
1166
+ */
1167
+
1168
+ // if (profileResponse.body === 'ok') {
1169
+ const profile = await this.getProfile();
1170
+
1145
1171
  const profileResponse = await requests.post(`https://api.gologin.com/browser/${this.profile_id}/web`, {
1146
1172
  headers: {
1147
1173
  'Authorization': `Bearer ${this.access_token}`
1148
1174
  }
1149
1175
  });
1176
+
1177
+ debug('profileResponse', profileResponse.statusCode, profileResponse.body);
1150
1178
 
1151
1179
  if (profileResponse.statusCode === 401){
1152
1180
  throw new Error("invalid token");
1153
1181
  }
1154
1182
 
1155
- debug('profileResponse', profileResponse.statusCode, profileResponse.body);
1156
- /*
1157
- if (profileResponse.statusCode !== 202) {
1158
- return {'status': 'failure', 'code': profileResponse.statusCode};
1159
- }
1160
- */
1161
-
1162
- // if (profileResponse.body === 'ok') {
1163
- const profile = await this.getProfile();
1164
1183
  const { navigator = {}, fonts, os: profileOs } = profile;
1165
1184
  this.fontsMasking = fonts?.enableMasking;
1166
1185
  this.profileOs = profileOs;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "gologin",
3
- "version": "1.0.37",
3
+ "version": "1.0.40",
4
4
  "description": "A high-level API to control Orbita browser over GoLogin API",
5
5
  "main": "./gologin.js",
6
6
  "repository": {
Binary file
Binary file