gologin 1.0.46 → 1.0.47

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.
@@ -3,6 +3,7 @@ const os = require('os');
3
3
  const request = require('requestretry');
4
4
  const { rmdirSync, createWriteStream } = require('fs');
5
5
  const { access, readFile, writeFile, mkdir, readdir, copyFile } = require('fs').promises;
6
+ const crypto = require('crypto');
6
7
 
7
8
  const fontsCollection = require('./fonts');
8
9
 
@@ -12,6 +13,7 @@ const FONTS_DIR_NAME = 'fonts';
12
13
  const HOMEDIR = os.homedir();
13
14
  const BROWSER_PATH = path.join(HOMEDIR, '.gologin', 'browser');
14
15
  const OS_PLATFORM = process.platform;
16
+ const DEFAULT_ORBITA_EXTENSIONS_NAMES = ['Google Hangouts', 'Chromium PDF Viewer', 'CryptoTokenExtension', 'Web Store'];
15
17
 
16
18
  class BrowserUserDataManager {
17
19
  static downloadCookies({ profileId, ACCESS_TOKEN, API_BASE_URL }) {
@@ -114,7 +116,7 @@ class BrowserUserDataManager {
114
116
  await writeFile(path.join(profilePath, 'Default', 'fonts_config'), result);
115
117
  }
116
118
 
117
- static setExtPaths(settings = {}, profileExtensionsCheckRes = []) {
119
+ static setExtPathsAndRemoveDeleted(settings = {}, profileExtensionsCheckRes = []) {
118
120
  const formattedLocalExtArray = profileExtensionsCheckRes.map((el) => {
119
121
  const [extFolderName = ''] = el.split(path.sep).reverse();
120
122
  const [originalId] = extFolderName.split('@');
@@ -128,21 +130,60 @@ class BrowserUserDataManager {
128
130
  }
129
131
  }).filter(Boolean);
130
132
 
131
- if (!formattedLocalExtArray.length) {
132
- return;
133
- }
134
-
135
133
  const extensionsSettings = settings.extensions?.settings || {};
136
134
  const extensionsEntries = Object.entries(extensionsSettings);
137
135
 
138
136
  extensionsEntries.forEach((extensionObj) => {
139
- const [extensionsId] = extensionObj;
140
- const localExtObj = formattedLocalExtArray.find(el => el.originalId === extensionsId);
137
+ let [extensionId, currentExtSettings = {}] = extensionObj;
138
+ const extName = currentExtSettings.manifest?.name || '';
139
+ let extPath = currentExtSettings.path || '';
140
+ let originalId = '';
141
+
142
+ const isExtensionToBeDeleted = ['resources', 'passwords-ext', 'cookies-ext'].some(substring => extPath.includes(substring))
143
+ || DEFAULT_ORBITA_EXTENSIONS_NAMES.includes(extName);
144
+ if (isExtensionToBeDeleted) {
145
+ delete extensionsSettings[extensionId];
146
+ return;
147
+ }
148
+
149
+ if (os.platform() === 'win32') {
150
+ extPath = extPath.replace(/\//g, '\\');
151
+ } else {
152
+ extPath = extPath.replace(/\\/g, '/');
153
+ }
154
+ extensionsSettings[extensionId].path = extPath;
155
+
156
+ const isExtensionManageable = ['chrome-extensions', 'user-extensions'].some(substring => extPath.includes(substring));
157
+ if (isExtensionManageable) {
158
+ const [extFolderName] = extPath.split(path.sep).reverse();
159
+ [originalId] = extFolderName.split('@');
160
+ const isExtensionInProfileSettings = formattedLocalExtArray.find(el => el.path.includes(originalId));
161
+ if (!isExtensionInProfileSettings) {
162
+ delete extensionsSettings[extensionId];
163
+ return;
164
+ }
165
+
166
+ if (!currentExtSettings.manifest?.key) {
167
+ const hexEncodedPath = crypto.createHash('sha256').update(extPath).digest('hex');
168
+ const newId = hexEncodedPath.split('').slice(0, 32).map(symbol => extIdEncoding[symbol]).join('');
169
+ delete extensionsSettings[extensionId];
170
+
171
+ extensionsSettings[newId] = currentExtSettings;
172
+ extensionId = newId;
173
+ }
174
+ } else {
175
+ const splittedPath = extPath.split(path.sep);
176
+ if (splittedPath.length === 2) {
177
+ [originalId] = splittedPath
178
+ }
179
+ }
180
+
181
+ const localExtObj = originalId && formattedLocalExtArray.find(el => el.path.includes(originalId));
141
182
  if (!localExtObj) {
142
183
  return;
143
184
  }
144
185
 
145
- extensionsSettings[extensionsId].path = localExtObj?.path || '';
186
+ extensionsSettings[extensionId].path = localExtObj?.path || '';
146
187
  });
147
188
 
148
189
  return extensionsSettings;
@@ -202,6 +243,25 @@ class BrowserUserDataManager {
202
243
  }
203
244
  }
204
245
 
246
+ const extIdEncoding = {
247
+ 0: 'a',
248
+ 1: 'b',
249
+ 2: 'c',
250
+ 3: 'd',
251
+ 4: 'e',
252
+ 5: 'f',
253
+ 6: 'g',
254
+ 7: 'h',
255
+ 8: 'i',
256
+ 9: 'j',
257
+ a: 'k',
258
+ b: 'l',
259
+ c: 'm',
260
+ d: 'n',
261
+ e: 'o',
262
+ f: 'p',
263
+ };
264
+
205
265
  module.exports = {
206
266
  BrowserUserDataManager,
207
267
  }
@@ -249,6 +249,28 @@ class ExtensionsManager {
249
249
 
250
250
  return Promise.all(removeFoldersPromises);
251
251
  }
252
+
253
+ getExtensionsToInstall(extensionsFromPref, extensionsFromDB) {
254
+ if (!extensionsFromPref) {
255
+ return [];
256
+ }
257
+
258
+ const objectEntries = Object.entries(extensionsFromPref);
259
+ const extensionsInPref = objectEntries?.map(([_, settings]) => {
260
+ const [extFolderName] = settings.path.split(path.sep).reverse();
261
+ const [originalId] = extFolderName.split('@');
262
+ return originalId;
263
+ }) || [];
264
+
265
+ return extensionsFromDB.reduce((acc, extension) => {
266
+ const [extFolderName] = extension.split(path.sep).reverse();
267
+ const [originalId] = extFolderName.split('@');
268
+ if (!extensionsInPref.includes(originalId)) {
269
+ acc.push(extension);
270
+ }
271
+ return acc;
272
+ }, []);
273
+ }
252
274
  }
253
275
 
254
276
  const crxToZip = (buf) => {
package/gologin.js CHANGED
@@ -50,6 +50,7 @@ class GoLogin {
50
50
  this.writeCookesFromServer = options.writeCookesFromServer;
51
51
  this.remote_debugging_port = options.remote_debugging_port || 0;
52
52
  this.timezone = options.timezone;
53
+ this.extensionPathsToInstall = [];
53
54
 
54
55
  if (options.tmpdir) {
55
56
  this.tmpdir = options.tmpdir;
@@ -406,13 +407,16 @@ class GoLogin {
406
407
  }
407
408
 
408
409
  let extSettings;
409
- if (ExtensionsManagerInst.useLocalExtStorage && profileExtensionsCheckRes.length) {
410
- extSettings = BrowserUserDataManager.setExtPaths(preferences, profileExtensionsCheckRes);
411
- } else if (!ExtensionsManagerInst.useLocalExtStorage) {
410
+ if (ExtensionsManagerInst.useLocalExtStorage) {
411
+ extSettings = BrowserUserDataManager.setExtPathsAndRemoveDeleted(preferences, profileExtensionsCheckRes);
412
+ } else {
412
413
  const originalExtensionsFolder = path.join(profilePath, 'Default', 'Extensions');
413
414
  extSettings = await BrowserUserDataManager.setOriginalExtPaths(preferences, originalExtensionsFolder);
414
415
  }
415
416
 
417
+ this.extensionPathsToInstall =
418
+ ExtensionsManagerInst.getExtensionsToInstall(extSettings, profileExtensionsCheckRes);
419
+
416
420
  if (extSettings) {
417
421
  const currentExtSettings = preferences.extensions || {};
418
422
  currentExtSettings.settings = extSettings
@@ -763,6 +767,22 @@ class GoLogin {
763
767
  `--lang=${browserLang}`,
764
768
  ];
765
769
 
770
+ if (this.extensionPathsToInstall.length) {
771
+ if (Array.isArray(this.extra_params) && this.extra_params.length) {
772
+ this.extra_params.forEach((param, index) => {
773
+ if (!param.includes('--load-extension=')) {
774
+ return;
775
+ }
776
+
777
+ const [_, extPathsString] = param.split('=');
778
+ const extPathsArray = extPathsString.split(',');
779
+ this.extensionPathsToInstall = [...this.extensionPathsToInstall, ...extPathsArray];
780
+ this.extra_params.splice(index, 1);
781
+ });
782
+ }
783
+ params.push(`--load-extension=${this.extensionPathsToInstall.join(',')}`);
784
+ }
785
+
766
786
  if (this.fontsMasking) {
767
787
  let arg = '--font-masking-mode=2';
768
788
  if (this.differentOs) {
@@ -945,7 +965,7 @@ class GoLogin {
945
965
  os = options.os;
946
966
  }
947
967
 
948
- let fingerprint = await requests.get(`https://api.gologin.com/browser/fingerprint?os=${os}`,{
968
+ let fingerprint = await requests.get(`${API_URL}/browser/fingerprint?os=${os}`,{
949
969
  headers: {
950
970
  'Authorization': `Bearer ${this.access_token}`,
951
971
  'User-Agent': 'gologin-api',
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "gologin",
3
- "version": "1.0.46",
3
+ "version": "1.0.47",
4
4
  "description": "A high-level API to control Orbita browser over GoLogin API",
5
5
  "main": "./gologin.js",
6
6
  "repository": {