gologin 2.0.15 → 2.0.17

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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "gologin",
3
- "version": "2.0.15",
3
+ "version": "2.0.17",
4
4
  "description": "A high-level API to control Orbita browser over GoLogin API",
5
5
  "main": "./src/gologin.js",
6
6
  "repository": {
@@ -17,24 +17,24 @@ const { access, mkdir, readdir, rmdir, unlink, copyFile, readlink, symlink, lsta
17
17
  const PLATFORM = process.platform;
18
18
 
19
19
  const VERSION_FILE = 'latest-version.txt';
20
- const MAC_VERSION_FILE_URL = `https://orbita-browser-mac-wc.gologin.com/${VERSION_FILE}`;
21
- const DEB_VERSION_FILE_URL = `https://orbita-browser-linux-wc.gologin.com/${VERSION_FILE}`;
22
- const WIN_VERSION_FILE_URL = `https://orbita-browser-windows-wc.gologin.com/${VERSION_FILE}`;
20
+ const MAC_VERSION_FILE_URL = `https://orbita-browser-mac.gologin.com/${VERSION_FILE}`;
21
+ const DEB_VERSION_FILE_URL = `https://orbita-browser-linux.gologin.com/${VERSION_FILE}`;
22
+ const WIN_VERSION_FILE_URL = `https://orbita-browser-windows.gologin.com/${VERSION_FILE}`;
23
23
 
24
24
  const WIN_FOLDERSIZE_FILE = 'foldersize.txt';
25
25
  const WIN_FOLDERSIZE_FILE_LINK = `https://orbita-browser-windows.gologin.com/${WIN_FOLDERSIZE_FILE}`;
26
26
 
27
27
  const BROWSER_ARCHIVE_NAME = `orbita-browser-latest.${PLATFORM === 'win32' ? 'zip' : 'tar.gz'}`;
28
- const MAC_BROWSER_LINK = `https://orbita-browser-mac-wc.gologin.com/${BROWSER_ARCHIVE_NAME}`;
29
- const DEB_BROWSER_LINK = `https://orbita-browser-linux-wc.gologin.com/${BROWSER_ARCHIVE_NAME}`;
30
- const WIN_BROWSER_LINK = `https://orbita-browser-windows-wc.gologin.com/${BROWSER_ARCHIVE_NAME}`;
28
+ const MAC_BROWSER_LINK = `https://orbita-browser-mac.gologin.com/${BROWSER_ARCHIVE_NAME}`;
29
+ const DEB_BROWSER_LINK = `https://orbita-browser-linux.gologin.com/${BROWSER_ARCHIVE_NAME}`;
30
+ const WIN_BROWSER_LINK = `https://orbita-browser-windows.gologin.com/${BROWSER_ARCHIVE_NAME}`;
31
31
 
32
32
  const MAC_HASH_FILE = 'hashfile.mtree';
33
33
  const DEB_HASH_FILE = 'hashfile.txt';
34
34
  const WIN_HASH_FILE = DEB_HASH_FILE;
35
- const MAC_HASHFILE_LINK = `https://orbita-browser-mac-wc.gologin.com/${MAC_HASH_FILE}`;
36
- const DEB_HASHFILE_LINK = `https://orbita-browser-linux-wc.gologin.com/${DEB_HASH_FILE}`;
37
- const WIN_HASHFILE_LINK = `https://orbita-browser-windows-wc.gologin.com/${WIN_HASH_FILE}`;
35
+ const MAC_HASHFILE_LINK = `https://orbita-browser-mac.gologin.com/${MAC_HASH_FILE}`;
36
+ const DEB_HASHFILE_LINK = `https://orbita-browser-linux.gologin.com/${DEB_HASH_FILE}`;
37
+ const WIN_HASHFILE_LINK = `https://orbita-browser-windows.gologin.com/${WIN_HASH_FILE}`;
38
38
 
39
39
  const FAIL_SUM_MATCH_MESSAGE = 'hash_sum_not_matched';
40
40
  const EXTRACTED_FOLDER = 'extracted-browser';
package/src/gologin.js CHANGED
@@ -1,5 +1,5 @@
1
1
  import { execFile, spawn } from 'child_process';
2
- import debug from 'debug';
2
+ import debugDefault from 'debug';
3
3
  import decompress from 'decompress';
4
4
  import decompressUnzip from 'decompress-unzip';
5
5
  import { existsSync, mkdirSync, promises as _promises } from 'fs';
@@ -36,6 +36,7 @@ const OS_PLATFORM = process.platform;
36
36
 
37
37
  // process.env["NODE_TLS_REJECT_UNAUTHORIZED"] = 0;
38
38
 
39
+ const debug = debugDefault('gologin');
39
40
  const delay = (time) => new Promise((resolve) => setTimeout(resolve, time));
40
41
 
41
42
  export class GoLogin {
@@ -58,6 +59,11 @@ export class GoLogin {
58
59
  this.waitWebsocket = false;
59
60
  }
60
61
 
62
+ this.isNewCloudBrowser = true;
63
+ if (options.isNewCloudBrowser === false) {
64
+ this.isNewCloudBrowser = false;
65
+ }
66
+
61
67
  this.tmpdir = tmpdir();
62
68
  this.autoUpdateBrowser = !!options.autoUpdateBrowser;
63
69
  this.browserChecker = new BrowserChecker(options.skipOrbitaHashChecking);
@@ -1212,7 +1218,7 @@ export class GoLogin {
1212
1218
  });
1213
1219
 
1214
1220
  debug('update profile', profile);
1215
- const response = await requests.put(`https://api.gologin.com/browser/${options.id}`,{
1221
+ const response = await requests.put(`${API_URL}/browser/${options.id}`,{
1216
1222
  json: profile,
1217
1223
  headers: {
1218
1224
  'Authorization': `Bearer ${this.access_token}`,
@@ -1285,26 +1291,29 @@ export class GoLogin {
1285
1291
 
1286
1292
  async writeCookiesToFile() {
1287
1293
  const cookies = await this.getCookies(this.profile_id);
1288
- if (!cookies.length) {
1289
- return;
1290
- }
1291
-
1292
1294
  const resultCookies = cookies.map((el) => ({ ...el, value: Buffer.from(el.value) }));
1293
1295
 
1294
1296
  let db;
1295
1297
  try {
1296
1298
  db = await getDB(this.cookiesFilePath, false);
1297
- const chunckInsertValues = getChunckedInsertValues(resultCookies);
1298
-
1299
- for (const [query, queryParams] of chunckInsertValues) {
1299
+ if (resultCookies.length) {
1300
+ const chunckInsertValues = getChunckedInsertValues(resultCookies);
1301
+
1302
+ for (const [query, queryParams] of chunckInsertValues) {
1303
+ const insertStmt = await db.prepare(query);
1304
+ await insertStmt.run(queryParams);
1305
+ await insertStmt.finalize();
1306
+ }
1307
+ } else {
1308
+ const query = 'delete from cookies';
1300
1309
  const insertStmt = await db.prepare(query);
1301
- await insertStmt.run(queryParams);
1310
+ await insertStmt.run();
1302
1311
  await insertStmt.finalize();
1303
1312
  }
1304
1313
  } catch (error) {
1305
1314
  console.log(error.message);
1306
1315
  } finally {
1307
- await db && db.close();
1316
+ db && await db.close();
1308
1317
  }
1309
1318
  }
1310
1319
 
@@ -1370,9 +1379,9 @@ export class GoLogin {
1370
1379
  await this.stopAndCommit(opts, true);
1371
1380
  }
1372
1381
 
1373
- async waitDebuggingUrl(delay_ms, try_count=0) {
1382
+ async waitDebuggingUrl(delay_ms, try_count=0, remoteOrbitaUrl) {
1374
1383
  await delay(delay_ms);
1375
- const url = `https://${this.profile_id}.orbita.gologin.com/json/version`;
1384
+ const url = `${remoteOrbitaUrl}/json/version`;
1376
1385
  console.log('try_count=', try_count, 'url=', url);
1377
1386
  const response = await requests.get(url);
1378
1387
  let wsUrl = '';
@@ -1387,13 +1396,14 @@ export class GoLogin {
1387
1396
  wsUrl = parsedBody.webSocketDebuggerUrl;
1388
1397
  } catch (e) {
1389
1398
  if (try_count < 3) {
1390
- return this.waitDebuggingUrl(delay_ms, try_count+1);
1399
+ return this.waitDebuggingUrl(delay_ms, try_count + 1, remoteOrbitaUrl);
1391
1400
  }
1392
1401
 
1393
1402
  return { 'status': 'failure', wsUrl, 'message': 'Check proxy settings', 'profile_id': this.profile_id };
1394
1403
  }
1395
1404
 
1396
- wsUrl = wsUrl.replace('ws://', 'wss://').replace('127.0.0.1', `${this.profile_id}.orbita.gologin.com`);
1405
+ const remoteOrbitaUrlWithoutProtocol = remoteOrbitaUrl.replace('https://', '');
1406
+ wsUrl = wsUrl.replace('ws://', 'wss://').replace('127.0.0.1', remoteOrbitaUrlWithoutProtocol);
1397
1407
 
1398
1408
  return wsUrl;
1399
1409
  }
@@ -1410,10 +1420,9 @@ export class GoLogin {
1410
1420
  // if (profileResponse.body === 'ok') {
1411
1421
  const profile = await this.getProfile();
1412
1422
 
1413
- const profileResponse = await requests.post(`https://api.gologin.com/browser/${this.profile_id}/web`, {
1414
- headers: {
1415
- 'Authorization': `Bearer ${this.access_token}`,
1416
- },
1423
+ const profileResponse = await requests.post(`${API_URL}/browser/${this.profile_id}/web`, {
1424
+ headers: { 'Authorization': `Bearer ${this.access_token}` },
1425
+ json: { isNewCloudBrowser: this.isNewCloudBrowser },
1417
1426
  });
1418
1427
 
1419
1428
  debug('profileResponse', profileResponse.statusCode, profileResponse.body);
@@ -1422,6 +1431,15 @@ export class GoLogin {
1422
1431
  throw new Error('invalid token');
1423
1432
  }
1424
1433
 
1434
+ let remoteOrbitaUrl = `https://${this.profile_id}.orbita.gologin.com`;
1435
+ if (this.isNewCloudBrowser) {
1436
+ if (!profileResponse.body.remoteOrbitaUrl) {
1437
+ throw new Error('Couldn\' start the remote browser');
1438
+ }
1439
+
1440
+ remoteOrbitaUrl = profileResponse.body.remoteOrbitaUrl;
1441
+ }
1442
+
1425
1443
  const { navigator = {}, fonts, os: profileOs } = profile;
1426
1444
  this.fontsMasking = fonts?.enableMasking;
1427
1445
  this.profileOs = profileOs;
@@ -1444,7 +1462,7 @@ export class GoLogin {
1444
1462
  height: parseInt(screenHeight, 10),
1445
1463
  };
1446
1464
 
1447
- const wsUrl = await this.waitDebuggingUrl(delay_ms);
1465
+ const wsUrl = await this.waitDebuggingUrl(delay_ms, 0, remoteOrbitaUrl);
1448
1466
  if (wsUrl !== '') {
1449
1467
  return { 'status': 'success', wsUrl };
1450
1468
  }
@@ -1454,10 +1472,8 @@ export class GoLogin {
1454
1472
 
1455
1473
  async stopRemote() {
1456
1474
  debug(`stopRemote ${this.profile_id}`);
1457
- const profileResponse = await requests.delete(`https://api.gologin.com/browser/${this.profile_id}/web`, {
1458
- headers: {
1459
- 'Authorization': `Bearer ${this.access_token}`,
1460
- },
1475
+ const profileResponse = await requests.delete(`${API_URL}/browser/${this.profile_id}/web?isNewCloudBrowser=${this.isNewCloudBrowser}`, {
1476
+ headers: { 'Authorization': `Bearer ${this.access_token}` },
1461
1477
  });
1462
1478
 
1463
1479
  console.log(`stopRemote ${profileResponse.body}`);