gologin 2.0.6 → 2.0.7

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.
@@ -18,6 +18,10 @@ const delay = ms => new Promise(res => setTimeout(res, ms));
18
18
  resolution: '1024x768',
19
19
  platform: 'mac',
20
20
  },
21
+ proxyEnabled: false,
22
+ proxy: {
23
+ mode: 'none',
24
+ }
21
25
  });
22
26
 
23
27
  console.log('profile id=', profile_id);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "gologin",
3
- "version": "2.0.6",
3
+ "version": "2.0.7",
4
4
  "description": "A high-level API to control Orbita browser over GoLogin API",
5
5
  "main": "./src/gologin.js",
6
6
  "repository": {
package/src/gologin.js CHANGED
@@ -1,4 +1,4 @@
1
- import { exec as execNonPromise, execFile, spawn } from 'child_process';
1
+ import { execFile, spawn } from 'child_process';
2
2
  import debug from 'debug';
3
3
  import decompress from 'decompress';
4
4
  import decompressUnzip from 'decompress-unzip';
@@ -9,7 +9,6 @@ import { join, resolve as _resolve,sep } from 'path';
9
9
  import requests from 'requestretry';
10
10
  import rimraf from 'rimraf';
11
11
  import ProxyAgent from 'simple-proxy-agent';
12
- import util from 'util';
13
12
 
14
13
  import { fontsCollection } from '../fonts.js';
15
14
  import { updateProfileProxy, updateProfileResolution, updateProfileUserAgent } from './browser/browser-api.js';
@@ -19,8 +18,8 @@ import { composeFonts, downloadCookies, setExtPathsAndRemoveDeleted,
19
18
  import { getChunckedInsertValues, getDB, loadCookiesFromFile } from './cookies/cookies-manager.js';
20
19
  import ExtensionsManager from './extensions/extensions-manager.js';
21
20
  import { archiveProfile } from './profile/profile-archiver.js';
21
+ import { get, isPortReachable } from './utils/utils.js';
22
22
  import { API_URL } from './utils/common.js';
23
- import { get } from './utils/utils.js';
24
23
 
25
24
  const exec = util.promisify(execNonPromise);
26
25
 
@@ -644,27 +643,27 @@ export class GoLogin {
644
643
  debug('CHECKING PORT AVAILABLE', port);
645
644
 
646
645
  try {
647
- const { stdout, stderr } = await exec(`lsof -i:${port}`);
648
- if (stdout && stdout.match(/LISTEN/gmi)) {
649
- debug(`PORT ${port} IS BUSY`);
646
+ const portAvailable = await isPortReachable(port, { host: 'localhost' });
647
+ if (portAvailable) {
648
+ debug(`PORT ${port} IS OPEN`);
650
649
 
651
- return false;
650
+ return true;
652
651
  }
653
652
  } catch (e) {
654
653
  console.log(e);
655
654
  }
656
655
 
657
- debug(`PORT ${port} IS OPEN`);
656
+ debug(`PORT ${port} IS BUSY`);
658
657
 
659
- return true;
658
+ return false;
660
659
  }
661
660
 
662
661
  async getRandomPort() {
663
662
  let port = this.getRandomInt(20000, 40000);
664
- let port_available = this.checkPortAvailable(port);
665
- while (!port_available) {
663
+ let portAvailable = await this.checkPortAvailable(port);
664
+ while (!portAvailable) {
666
665
  port = this.getRandomInt(20000, 40000);
667
- port_available = await this.checkPortAvailable(port);
666
+ portAvailable = await this.checkPortAvailable(port);
668
667
  }
669
668
 
670
669
  return port;
@@ -14,7 +14,12 @@ export const archiveProfile = async (profileFolder = '', tryAgain = true) => {
14
14
 
15
15
  const archive = new AdmZip();
16
16
  archive.addLocalFolder(path.join(profileFolder, 'Default'), 'Default');
17
- archive.addLocalFile(path.join(profileFolder, 'First Run'));
17
+ try {
18
+ archive.addLocalFile(path.join(profileFolder, 'First Run'));
19
+ } catch(e) {
20
+ archive.addFile('First Run', Buffer.from(''));
21
+ }
22
+
18
23
  const dirsToRemove = getDirectoriesForArchiver();
19
24
  dirsToRemove.forEach(entry => archive.deleteFile(entry));
20
25
 
@@ -1,3 +1,5 @@
1
+ import net from 'node:net';
2
+
1
3
  export const get = (value, path, defaultValue) =>
2
4
  String(path).split('.').reduce((acc, v) => {
3
5
  try {
@@ -9,3 +11,12 @@ export const get = (value, path, defaultValue) =>
9
11
  return acc;
10
12
  }, value);
11
13
 
14
+ export const isPortReachable = (port) => new Promise(resolve => {
15
+ const checker = net.createServer()
16
+ .once('error', () => {
17
+ resolve(false);
18
+ })
19
+ .once('listening', () => checker.once('close', () => resolve(true)).close())
20
+ .listen(port);
21
+ });
22
+