gologin 2.0.9 → 2.0.11

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.9",
3
+ "version": "2.0.11",
4
4
  "description": "A high-level API to control Orbita browser over GoLogin API",
5
5
  "main": "./src/gologin.js",
6
6
  "repository": {
@@ -0,0 +1,16 @@
1
+ import { promises as _promises } from 'fs';
2
+
3
+ const { readFile } = _promises;
4
+
5
+ export const getCurrentProfileBookmarks = async (pathToBookmarks) => {
6
+ const currentBookmarksFileData = await readFile(pathToBookmarks, { encoding: 'utf-8' });
7
+
8
+ let bookmarks = {};
9
+ try {
10
+ bookmarks = JSON.parse(currentBookmarksFileData);
11
+ } catch (error) {
12
+ console.log(error);
13
+ }
14
+
15
+ return bookmarks;
16
+ };
@@ -69,3 +69,27 @@ export const updateProfileProxy = (profileId, ACCESS_TOKEN, browserProxyData) =>
69
69
 
70
70
  return { body: [] };
71
71
  });
72
+
73
+ /**
74
+ * @param {string} profileId
75
+ * @param {string} ACCESS_TOKEN
76
+ * @param {Object} bookmarks
77
+ */
78
+ export const updateProfileBookmarks = async (profileIds, ACCESS_TOKEN, bookmarks) => {
79
+ const params = {
80
+ profileIds,
81
+ bookmarks,
82
+ };
83
+
84
+ return requestretry.patch(`${API_URL}/browser/bookmarks/many`, {
85
+ headers: {
86
+ Authorization: `Bearer ${ACCESS_TOKEN}`,
87
+ 'user-agent': 'gologin-api',
88
+ },
89
+ json: params,
90
+ maxAttempts: 3,
91
+ retryDelay: 2000,
92
+ timeout: 10 * 1000,
93
+ }).catch((error) => console.log(error));
94
+ };
95
+
@@ -9,6 +9,8 @@ import ProgressBar from 'progress';
9
9
  import { createInterface } from 'readline';
10
10
  import util from 'util';
11
11
 
12
+ import { findLatestBrowserVersionDirectory } from '../utils/utils.js';
13
+
12
14
  const exec = util.promisify(execNonPromise);
13
15
  const { access, mkdir, readdir, rmdir, unlink, copyFile, readlink, symlink, lstat } = _promises;
14
16
 
@@ -50,7 +52,12 @@ export class BrowserChecker {
50
52
 
51
53
  let executableFilePath = join(this.#browserPath, 'orbita-browser', 'chrome');
52
54
  if (PLATFORM === 'darwin') {
53
- executableFilePath = join(this.#browserPath, 'Orbita-Browser.app', 'Contents', 'MacOS', 'Orbita');
55
+ const orbitaFolderName = findLatestBrowserVersionDirectory(this.#browserPath);
56
+ if (orbitaFolderName === 'error') {
57
+ throw Error('Orbita folder not found in this directory: ' + this.#browserPath);
58
+ }
59
+
60
+ executableFilePath = join(this.#browserPath, orbitaFolderName, 'Orbita-Browser.app', 'Contents', 'MacOS', 'Orbita');
54
61
  } else if (PLATFORM === 'win32') {
55
62
  executableFilePath = join(this.#browserPath, 'orbita-browser', 'chrome.exe');
56
63
  }
package/src/gologin.js CHANGED
@@ -11,15 +11,16 @@ import rimraf from 'rimraf';
11
11
  import ProxyAgent from 'simple-proxy-agent';
12
12
 
13
13
  import { fontsCollection } from '../fonts.js';
14
- import { updateProfileProxy, updateProfileResolution, updateProfileUserAgent } from './browser/browser-api.js';
14
+ import { getCurrentProfileBookmarks } from './bookmarks/utils.js';
15
+ import { updateProfileBookmarks, updateProfileProxy, updateProfileResolution, updateProfileUserAgent } from './browser/browser-api.js';
15
16
  import BrowserChecker from './browser/browser-checker.js';
16
17
  import { composeFonts, downloadCookies, setExtPathsAndRemoveDeleted,
17
18
  setOriginalExtPaths, uploadCookies } from './browser/browser-user-data-manager.js';
18
19
  import { getChunckedInsertValues, getDB, loadCookiesFromFile } from './cookies/cookies-manager.js';
19
20
  import ExtensionsManager from './extensions/extensions-manager.js';
20
21
  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, isPortReachable } from './utils/utils.js';
23
24
 
24
25
  const { access, unlink, writeFile, readFile } = _promises;
25
26
 
@@ -69,6 +70,7 @@ export class GoLogin {
69
70
 
70
71
  this.cookiesFilePath = join(this.tmpdir, `gologin_profile_${this.profile_id}`, 'Default', 'Network', 'Cookies');
71
72
  this.profile_zip_path = join(this.tmpdir, `gologin_${this.profile_id}.zip`);
73
+ this.bookmarksFilePath = join(this.tmpdir, `gologin_profile_${this.profile_id}`, 'Default', 'Bookmarks');
72
74
  debug('INIT GOLOGIN', this.profile_id);
73
75
  }
74
76
 
@@ -255,8 +257,13 @@ export class GoLogin {
255
257
  preferences.hardwareConcurrency = get(preferences, 'navigator.hardwareConcurrency');
256
258
  }
257
259
 
260
+ if (get(preferences, 'navigator.deviceMemory')) {
261
+ preferences.deviceMemory = get(preferences, 'navigator.deviceMemory')*1024;
262
+ }
263
+
258
264
  if (get(preferences, 'navigator.language')) {
259
- preferences.language = get(preferences, 'navigator.language');
265
+ preferences.langHeader = get(preferences, 'navigator.language');
266
+ preferences.languages = get(preferences, 'navigator.language').replace(/;|q=[\d\.]+/img, '');
260
267
  }
261
268
 
262
269
  if (get(preferences, 'navigator.maxTouchPoints')) {
@@ -290,6 +297,12 @@ export class GoLogin {
290
297
  audioOutputs: preferences.mediaDevices.audioOutputs,
291
298
  };
292
299
 
300
+ preferences.webRtc = {
301
+ ...preferences.webRtc,
302
+ fill_based_on_ip: !!get(preferences, 'webRTC.fillBasedOnIp'),
303
+ local_ip_masking: !!get(preferences, 'webRTC.local_ip_masking'),
304
+ };
305
+
293
306
  return preferences;
294
307
  }
295
308
 
@@ -597,6 +610,11 @@ export class GoLogin {
597
610
  gologin,
598
611
  })));
599
612
 
613
+ const bookmarksParsedData = await getCurrentProfileBookmarks(this.bookmarksFilePath);
614
+ const bookmarksFromDb = profile.bookmarks?.bookmark_bar;
615
+ bookmarksParsedData.roots = bookmarksFromDb ? profile.bookmarks : bookmarksParsedData.roots;
616
+ await writeFile(this.bookmarksFilePath, JSON.stringify(bookmarksParsedData));
617
+
600
618
  debug('Profile ready. Path: ', profilePath, 'PROXY', JSON.stringify(get(preferences, 'gologin.proxy')));
601
619
 
602
620
  return profilePath;
@@ -922,6 +940,8 @@ export class GoLogin {
922
940
  await this.uploadProfileCookiesToServer();
923
941
  }
924
942
 
943
+ await this.saveBookmarksToDb();
944
+
925
945
  this.is_stopping = true;
926
946
  await this.sanitizeProfile();
927
947
 
@@ -1250,6 +1270,12 @@ export class GoLogin {
1250
1270
  return this.postCookies(this.profile_id, cookies);
1251
1271
  }
1252
1272
 
1273
+ async saveBookmarksToDb() {
1274
+ const bookmarksData = await getCurrentProfileBookmarks(this.bookmarksFilePath);
1275
+ const bookmarks = bookmarksData.roots || {};
1276
+ await updateProfileBookmarks([this.profile_id], this.access_token, bookmarks);
1277
+ }
1278
+
1253
1279
  async start() {
1254
1280
  if (this.is_remote) {
1255
1281
  return this.startRemote();
@@ -1,4 +1,6 @@
1
+ import { readdirSync, statSync } from 'node:fs';
1
2
  import net from 'node:net';
3
+ import { join } from 'node:path';
2
4
 
3
5
  export const get = (value, path, defaultValue) =>
4
6
  String(path).split('.').reduce((acc, v) => {
@@ -20,3 +22,28 @@ export const isPortReachable = (port) => new Promise(resolve => {
20
22
  .listen(port);
21
23
  });
22
24
 
25
+ export const findLatestBrowserVersionDirectory = (browserPath) => {
26
+ const folderContents = readdirSync(browserPath);
27
+ const directories = folderContents.filter(file => statSync(join(browserPath, file)).isDirectory());
28
+
29
+ const { folderName, version } = directories.reduce((newest, currentFolderName) => {
30
+ const match = currentFolderName.match(/\d+/);
31
+
32
+ if (match) {
33
+ const findedVersion = parseInt(match[0], 10);
34
+
35
+ if (findedVersion > newest.version) {
36
+ return { folderName: currentFolderName, version: findedVersion };
37
+ }
38
+ }
39
+
40
+ return newest;
41
+ }, { folderName: '', version: 0 });
42
+
43
+ if (!version) {
44
+ return 'error';
45
+ }
46
+
47
+ return folderName;
48
+ };
49
+