gologin 2.1.16 → 2.1.18
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/package.json +1 -1
- package/src/browser/browser-checker.js +47 -70
- package/src/cookies/cookies-manager.js +7 -1
- package/src/gologin.js +32 -18
- package/src/utils/common.js +12 -0
- package/src/utils/constants.js +1 -1
package/package.json
CHANGED
|
@@ -6,10 +6,8 @@ import { get } from 'https';
|
|
|
6
6
|
import { homedir } from 'os';
|
|
7
7
|
import { join } from 'path';
|
|
8
8
|
import ProgressBar from 'progress';
|
|
9
|
-
import { createInterface } from 'readline';
|
|
10
9
|
import util from 'util';
|
|
11
10
|
|
|
12
|
-
import { findLatestBrowserVersionDirectory } from '../utils/utils.js';
|
|
13
11
|
import { API_URL, getOS } from '../utils/common.js';
|
|
14
12
|
|
|
15
13
|
const exec = util.promisify(execNonPromise);
|
|
@@ -37,87 +35,65 @@ const FAIL_SUM_MATCH_MESSAGE = 'hash_sum_not_matched';
|
|
|
37
35
|
const EXTRACTED_FOLDER = 'extracted-browser';
|
|
38
36
|
|
|
39
37
|
export class BrowserChecker {
|
|
40
|
-
#homedir;
|
|
41
|
-
#browserPath;
|
|
38
|
+
#homedir = homedir();
|
|
39
|
+
#browserPath = join(this.#homedir, '.gologin', 'browser');
|
|
42
40
|
#executableFilePath;
|
|
43
41
|
#skipOrbitaHashChecking = false;
|
|
44
42
|
|
|
45
|
-
constructor(
|
|
46
|
-
this.#skipOrbitaHashChecking = skipOrbitaHashChecking;
|
|
47
|
-
this.#homedir = homedir();
|
|
48
|
-
this.#browserPath = join(this.#homedir, '.gologin', 'browser');
|
|
43
|
+
constructor() {
|
|
49
44
|
|
|
50
|
-
let executableFilePath = join(this.#browserPath, 'orbita-browser', 'chrome');
|
|
51
|
-
if (PLATFORM === 'darwin') {
|
|
52
|
-
const orbitaFolderName = findLatestBrowserVersionDirectory(this.#browserPath);
|
|
53
|
-
if (orbitaFolderName === 'error') {
|
|
54
|
-
throw Error('Orbita folder not found in this directory: ' + this.#browserPath);
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
executableFilePath = join(this.#browserPath, orbitaFolderName, 'Orbita-Browser.app', 'Contents', 'MacOS', 'Orbita');
|
|
58
|
-
} else if (PLATFORM === 'win32') {
|
|
59
|
-
executableFilePath = join(this.#browserPath, 'orbita-browser', 'chrome.exe');
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
this.#executableFilePath = executableFilePath;
|
|
63
|
-
// console.log('executableFilePath:', executableFilePath);
|
|
64
45
|
}
|
|
65
46
|
|
|
66
|
-
async checkBrowser(
|
|
67
|
-
const
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
if (!browserFolderExists) {
|
|
72
|
-
return this.downloadBrowser(browserLatestVersion, browserDownloadUrl);
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
const currentVersionReq = await this.getCurrentVersion();
|
|
76
|
-
const currentVersion = (currentVersionReq?.stdout || '').replace(/(\r\n|\n|\r)/gm, '');
|
|
77
|
-
|
|
78
|
-
if (browserLatestVersion === currentVersion || !checkBrowserUpdate) {
|
|
79
|
-
return;
|
|
47
|
+
async checkBrowser(majorVersion) {
|
|
48
|
+
const isBrowserFolderExists = await access(join(this.#browserPath, `orbita-browser-${majorVersion}`)).then(() => true).catch(() => false);
|
|
49
|
+
if (isBrowserFolderExists) {
|
|
50
|
+
return this.getBrowserExecutablePath(majorVersion);
|
|
80
51
|
}
|
|
81
52
|
|
|
82
|
-
|
|
83
|
-
return this.downloadBrowser(browserLatestVersion, browserDownloadUrl);
|
|
84
|
-
}
|
|
53
|
+
await this.downloadBrowser(majorVersion);
|
|
85
54
|
|
|
86
|
-
return
|
|
87
|
-
const rl = createInterface(process.stdin, process.stdout);
|
|
88
|
-
const timeout = setTimeout(() => {
|
|
89
|
-
console.log(`\nContinue with current ${currentVersion} version.`);
|
|
90
|
-
resolve();
|
|
91
|
-
}, 10000);
|
|
92
|
-
|
|
93
|
-
rl.question(`New Orbita ${browserLatestVersion} is available. Update? [y/n] `, (answer) => {
|
|
94
|
-
clearTimeout(timeout);
|
|
95
|
-
rl.close();
|
|
96
|
-
if (answer && answer[0].toString().toLowerCase() === 'y') {
|
|
97
|
-
return this.downloadBrowser(browserLatestVersion, browserDownloadUrl).then(() => resolve());
|
|
98
|
-
}
|
|
99
|
-
|
|
100
|
-
console.log(`Continue with current ${currentVersion} version.`);
|
|
101
|
-
resolve();
|
|
102
|
-
});
|
|
103
|
-
});
|
|
55
|
+
return this.getBrowserExecutablePath(majorVersion);
|
|
104
56
|
}
|
|
105
57
|
|
|
106
|
-
async downloadBrowser(
|
|
107
|
-
await this.deleteOldArchives(true);
|
|
58
|
+
async downloadBrowser(majorVersion) {
|
|
108
59
|
await mkdir(this.#browserPath, { recursive: true });
|
|
109
60
|
|
|
110
|
-
const
|
|
61
|
+
const browserPath = join(this.#browserPath, BROWSER_ARCHIVE_NAME);
|
|
111
62
|
|
|
112
|
-
|
|
113
|
-
|
|
63
|
+
const browserDownloadUrl = this.getBrowserDownloadUrl(majorVersion);
|
|
64
|
+
|
|
65
|
+
await this.downloadBrowserArchive(browserDownloadUrl, browserPath);
|
|
114
66
|
await this.extractBrowser();
|
|
115
|
-
await this.
|
|
116
|
-
console.log('Orbita hash checked successfully');
|
|
117
|
-
await this.replaceBrowser();
|
|
118
|
-
await this.addLatestVersion(latestVersion).catch(() => null);
|
|
67
|
+
await this.replaceBrowser(majorVersion);
|
|
119
68
|
await this.deleteOldArchives();
|
|
120
|
-
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
getBrowserExecutablePath(majorVersion) {
|
|
72
|
+
const os = getOS();
|
|
73
|
+
switch (os) {
|
|
74
|
+
case 'mac':
|
|
75
|
+
return join(this.#browserPath, `orbita-browser-${majorVersion}`, 'Orbita-Browser.app', 'Contents', 'MacOS', 'Orbita');
|
|
76
|
+
case 'win':
|
|
77
|
+
return join(this.#browserPath, `orbita-browser-${majorVersion}`, 'chrome.exe');
|
|
78
|
+
case 'macM1':
|
|
79
|
+
return join(this.#browserPath, `orbita-browser-${majorVersion}`, 'Orbita-Browser.app', 'Contents', 'MacOS', 'Orbita');
|
|
80
|
+
default:
|
|
81
|
+
return join(this.#browserPath, `orbita-browser-${majorVersion}`, 'chrome');
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
getBrowserDownloadUrl(majorVersion) {
|
|
86
|
+
const os = getOS();
|
|
87
|
+
switch (os) {
|
|
88
|
+
case 'mac':
|
|
89
|
+
return `https://orbita-browser-mac.gologin.com/orbita-browser-latest-${majorVersion}.tar.gz`;
|
|
90
|
+
case 'win':
|
|
91
|
+
return `https://orbita-browser-windows.gologin.com/orbita-browser-latest-${majorVersion}.zip`;
|
|
92
|
+
case 'macM1':
|
|
93
|
+
return `https://orbita-browser-mac-arm.gologin.com/orbita-browser-latest-${majorVersion}.tar.gz`;
|
|
94
|
+
default:
|
|
95
|
+
return `https://orbita-browser-linux.gologin.com/orbita-browser-latest-${majorVersion}.tar.gz`;
|
|
96
|
+
}
|
|
121
97
|
}
|
|
122
98
|
|
|
123
99
|
addLatestVersion(latestVersion) {
|
|
@@ -208,6 +184,7 @@ export class BrowserChecker {
|
|
|
208
184
|
if (ARCH === 'arm64') {
|
|
209
185
|
hashLink = MAC_ARM_HASHFILE_LINK;
|
|
210
186
|
}
|
|
187
|
+
|
|
211
188
|
resultPath = join(this.#browserPath, MAC_HASH_FILE);
|
|
212
189
|
}
|
|
213
190
|
|
|
@@ -282,13 +259,13 @@ export class BrowserChecker {
|
|
|
282
259
|
}
|
|
283
260
|
}
|
|
284
261
|
|
|
285
|
-
async replaceBrowser() {
|
|
262
|
+
async replaceBrowser(majorVersion) {
|
|
286
263
|
console.log('Copy Orbita to target path');
|
|
287
264
|
if (PLATFORM === 'darwin') {
|
|
288
|
-
return rename(join(this.#browserPath, EXTRACTED_FOLDER), join(this.#browserPath,
|
|
265
|
+
return rename(join(this.#browserPath, EXTRACTED_FOLDER), join(this.#browserPath, `orbita-browser-${majorVersion}`));
|
|
289
266
|
}
|
|
290
267
|
|
|
291
|
-
const targetBrowserPath = join(this.#browserPath,
|
|
268
|
+
const targetBrowserPath = join(this.#browserPath, `orbita-browser-${majorVersion}`);
|
|
292
269
|
await this.deleteDir(targetBrowserPath);
|
|
293
270
|
|
|
294
271
|
await this.copyDir(
|
|
@@ -3,6 +3,8 @@ import { join } from 'path';
|
|
|
3
3
|
import { open } from 'sqlite';
|
|
4
4
|
import sqlite3 from 'sqlite3';
|
|
5
5
|
|
|
6
|
+
import { ensureDirectoryExists } from '../utils/common.js';
|
|
7
|
+
|
|
6
8
|
const { access } = fsPromises;
|
|
7
9
|
const { Database, OPEN_READONLY } = sqlite3;
|
|
8
10
|
|
|
@@ -44,7 +46,11 @@ export const createDBFile = async ({
|
|
|
44
46
|
await db.run(createCookiesTableQuery);
|
|
45
47
|
await db.close();
|
|
46
48
|
|
|
47
|
-
|
|
49
|
+
await ensureDirectoryExists(cookiesFilePath);
|
|
50
|
+
await ensureDirectoryExists(cookiesFileSecondPath);
|
|
51
|
+
cookiesFileSecondPath && await fsPromises.copyFile(cookiesFilePath, cookiesFileSecondPath).catch((error) => {
|
|
52
|
+
console.error('error in copyFile createDBFile', error.message);
|
|
53
|
+
});
|
|
48
54
|
};
|
|
49
55
|
|
|
50
56
|
export const getUniqueCookies = async (cookiesArr, cookiesFilePath) => {
|
package/src/gologin.js
CHANGED
|
@@ -2,7 +2,7 @@ import { execFile, spawn } from 'child_process';
|
|
|
2
2
|
import debugDefault from 'debug';
|
|
3
3
|
import decompress from 'decompress';
|
|
4
4
|
import decompressUnzip from 'decompress-unzip';
|
|
5
|
-
import { existsSync, mkdirSync,promises as _promises } from 'fs';
|
|
5
|
+
import { existsSync, mkdirSync, promises as _promises } from 'fs';
|
|
6
6
|
import { get as _get } from 'https';
|
|
7
7
|
import { tmpdir } from 'os';
|
|
8
8
|
import { dirname, join, resolve as _resolve, sep } from 'path';
|
|
@@ -29,7 +29,7 @@ import {
|
|
|
29
29
|
import ExtensionsManager from './extensions/extensions-manager.js';
|
|
30
30
|
import { archiveProfile } from './profile/profile-archiver.js';
|
|
31
31
|
import { checkAutoLang } from './utils/browser.js';
|
|
32
|
-
import { API_URL, getOsAdvanced } from './utils/common.js';
|
|
32
|
+
import { API_URL, ensureDirectoryExists, getOsAdvanced } from './utils/common.js';
|
|
33
33
|
import { STORAGE_GATEWAY_BASE_URL } from './utils/constants.js';
|
|
34
34
|
import { get, isPortReachable } from './utils/utils.js';
|
|
35
35
|
export { exitAll, GologinApi } from './gologin-api.js';
|
|
@@ -92,8 +92,8 @@ export class GoLogin {
|
|
|
92
92
|
debug('INIT GOLOGIN', this.profile_id);
|
|
93
93
|
}
|
|
94
94
|
|
|
95
|
-
async checkBrowser() {
|
|
96
|
-
|
|
95
|
+
async checkBrowser(majorVersion) {
|
|
96
|
+
this.executablePath = await this.browserChecker.checkBrowser(majorVersion);
|
|
97
97
|
}
|
|
98
98
|
|
|
99
99
|
async setProfileId(profile_id) {
|
|
@@ -466,6 +466,12 @@ export class GoLogin {
|
|
|
466
466
|
throw new Error('Error fetching profile data');
|
|
467
467
|
}
|
|
468
468
|
|
|
469
|
+
if (!this.executablePath) {
|
|
470
|
+
const { userAgent } = profile.navigator;
|
|
471
|
+
const [browserMajorVersion] = userAgent.split('Chrome/')[1].split('.');
|
|
472
|
+
await this.checkBrowser(browserMajorVersion);
|
|
473
|
+
}
|
|
474
|
+
|
|
469
475
|
const { navigator = {}, fonts, os: profileOs } = profile;
|
|
470
476
|
this.fontsMasking = fonts?.enableMasking;
|
|
471
477
|
this.profileOs = profileOs;
|
|
@@ -487,6 +493,8 @@ export class GoLogin {
|
|
|
487
493
|
width: parseInt(screenWidth, 10),
|
|
488
494
|
height: parseInt(screenHeight, 10),
|
|
489
495
|
};
|
|
496
|
+
|
|
497
|
+
this.createCookiesTableQuery = profile.createCookiesTableQuery;
|
|
490
498
|
if (profile.storageInfo.isNewProfile) {
|
|
491
499
|
this.isFirstSession = true;
|
|
492
500
|
await this.createZeroProfile(profile.createCookiesTableQuery);
|
|
@@ -927,7 +935,7 @@ export class GoLogin {
|
|
|
927
935
|
|
|
928
936
|
if (this.waitWebsocket) {
|
|
929
937
|
debug('GETTING WS URL FROM BROWSER');
|
|
930
|
-
const data = await requests.get(`http://127.0.0.1:${remote_debugging_port}/json/version`, { json: true });
|
|
938
|
+
const data = await requests.get(`http://127.0.0.1:${remote_debugging_port}/json/version`, { json: true, maxAttempts: 10, retryDelay: 1000 });
|
|
931
939
|
|
|
932
940
|
debug('WS IS', get(data, 'body.webSocketDebuggerUrl', ''));
|
|
933
941
|
this.is_active = true;
|
|
@@ -1377,7 +1385,7 @@ export class GoLogin {
|
|
|
1377
1385
|
return { primary, secondary };
|
|
1378
1386
|
}
|
|
1379
1387
|
|
|
1380
|
-
async writeCookiesToFile(cookies) {
|
|
1388
|
+
async writeCookiesToFile(cookies, isSecondTry = false) {
|
|
1381
1389
|
if (!cookies) {
|
|
1382
1390
|
cookies = await this.getCookies(this.profile_id);
|
|
1383
1391
|
}
|
|
@@ -1404,10 +1412,26 @@ export class GoLogin {
|
|
|
1404
1412
|
}
|
|
1405
1413
|
}
|
|
1406
1414
|
} catch (error) {
|
|
1407
|
-
|
|
1415
|
+
if (!isSecondTry && (error.message.includes('table cookies has no column') || error.message.includes('NOT NULL constraint failed'))) {
|
|
1416
|
+
await _promises.rm(cookiesPaths.primary, { recursive: true, force: true });
|
|
1417
|
+
await createDBFile({
|
|
1418
|
+
cookiesFilePath: cookiesPaths.primary,
|
|
1419
|
+
cookiesFileSecondPath: cookiesPaths.secondary,
|
|
1420
|
+
createCookiesTableQuery: this.createCookiesTableQuery,
|
|
1421
|
+
});
|
|
1422
|
+
await this.writeCookiesToFile(cookies, true);
|
|
1423
|
+
|
|
1424
|
+
return;
|
|
1425
|
+
}
|
|
1426
|
+
|
|
1427
|
+
console.error(error.message);
|
|
1408
1428
|
} finally {
|
|
1409
1429
|
db && await db.close();
|
|
1410
|
-
await
|
|
1430
|
+
await ensureDirectoryExists(cookiesPaths.primary);
|
|
1431
|
+
await ensureDirectoryExists(cookiesPaths.secondary);
|
|
1432
|
+
await copyFile(cookiesPaths.primary, cookiesPaths.secondary).catch((error) => {
|
|
1433
|
+
console.error('error in copyFile', error.message);
|
|
1434
|
+
});
|
|
1411
1435
|
}
|
|
1412
1436
|
}
|
|
1413
1437
|
|
|
@@ -1427,16 +1451,6 @@ export class GoLogin {
|
|
|
1427
1451
|
}
|
|
1428
1452
|
|
|
1429
1453
|
async start() {
|
|
1430
|
-
if (!this.executablePath) {
|
|
1431
|
-
await this.checkBrowser();
|
|
1432
|
-
}
|
|
1433
|
-
|
|
1434
|
-
const ORBITA_BROWSER = this.executablePath || this.browserChecker.getOrbitaPath;
|
|
1435
|
-
|
|
1436
|
-
const orbitaBrowserExists = await access(ORBITA_BROWSER).then(() => true).catch(() => false);
|
|
1437
|
-
if (!orbitaBrowserExists) {
|
|
1438
|
-
throw new Error(`Orbita browser is not exists on path ${ORBITA_BROWSER}, check executablePath param`);
|
|
1439
|
-
}
|
|
1440
1454
|
|
|
1441
1455
|
await this.createStartup();
|
|
1442
1456
|
// await this.createBrowserExtension();
|
package/src/utils/common.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { exec } from 'child_process';
|
|
2
|
+
import { promises as fsPromises } from 'fs';
|
|
2
3
|
import { homedir } from 'os';
|
|
3
4
|
import { join, sep } from 'path';
|
|
4
5
|
import { promisify } from 'util';
|
|
@@ -34,6 +35,17 @@ const getMacArmSpec = async () => {
|
|
|
34
35
|
return armVersion;
|
|
35
36
|
};
|
|
36
37
|
|
|
38
|
+
export const ensureDirectoryExists = async (filePath) => {
|
|
39
|
+
try {
|
|
40
|
+
const directory = filePath.substring(0, filePath.lastIndexOf('/'));
|
|
41
|
+
await fsPromises.mkdir(directory, { recursive: true });
|
|
42
|
+
} catch (error) {
|
|
43
|
+
if (error.code !== 'EEXIST') {
|
|
44
|
+
console.error('Error creating directory:', error.message);
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
};
|
|
48
|
+
|
|
37
49
|
const getOsAdvanced = async () => {
|
|
38
50
|
const os = getOS();
|
|
39
51
|
if (!['mac', 'macM1'].includes(os)) {
|
package/src/utils/constants.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export const STORAGE_GATEWAY_BASE_URL = 'https://
|
|
1
|
+
export const STORAGE_GATEWAY_BASE_URL = 'https://storage-worker-test.gologin.com';
|