gologin 2.0.13 → 2.0.15

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.13",
3
+ "version": "2.0.15",
4
4
  "description": "A high-level API to control Orbita browser over GoLogin API",
5
5
  "main": "./src/gologin.js",
6
6
  "repository": {
@@ -40,7 +40,7 @@ export const downloadCookies = ({ profileId, ACCESS_TOKEN, API_BASE_URL }) =>
40
40
  });
41
41
 
42
42
  export const uploadCookies = ({ cookies = [], profileId, ACCESS_TOKEN, API_BASE_URL }) =>
43
- requestretry.post(`${API_BASE_URL}/browser/${profileId}/cookies`, {
43
+ requestretry.post(`${API_BASE_URL}/browser/${profileId}/cookies/?encrypted=true`, {
44
44
  headers: {
45
45
  Authorization: `Bearer ${ACCESS_TOKEN}`,
46
46
  'User-Agent': 'gologin-api',
@@ -1,5 +1,9 @@
1
1
  import { open } from 'sqlite';
2
2
  import sqlite3 from 'sqlite3';
3
+ import { promises as fsPromises } from 'fs';
4
+ import { join } from 'path';
5
+
6
+ const { access } = fsPromises;
3
7
  const { Database, OPEN_READONLY } = sqlite3;
4
8
 
5
9
  const MAX_SQLITE_VARIABLES = 76;
@@ -117,7 +121,7 @@ export const loadCookiesFromFile = async (filePath) => {
117
121
  } catch (error) {
118
122
  console.log(error);
119
123
  } finally {
120
- await db && db.close();
124
+ db && await db.close();
121
125
  }
122
126
 
123
127
  return cookies;
@@ -170,4 +174,16 @@ export const chunk = (arr, chunkSize = 1, cache = []) => {
170
174
  }
171
175
 
172
176
  return cache;
173
- }
177
+ }
178
+
179
+ export const getCookiesFilePath = async (profileId, tmpdir) => {
180
+ const baseCookiesFilePath = join(tmpdir, `gologin_profile_${profileId}`, 'Default', 'Cookies');
181
+ const bypassCookiesFilePath = join(tmpdir, `gologin_profile_${profileId}`, 'Default', 'Network', 'Cookies');
182
+
183
+ return access(baseCookiesFilePath)
184
+ .then(() => baseCookiesFilePath)
185
+ .catch(() => access(bypassCookiesFilePath)
186
+ .then(() => bypassCookiesFilePath)
187
+ .catch(() => baseCookiesFilePath)
188
+ );
189
+ }
package/src/gologin.js CHANGED
@@ -14,9 +14,15 @@ import { fontsCollection } from '../fonts.js';
14
14
  import { getCurrentProfileBookmarks } from './bookmarks/utils.js';
15
15
  import { updateProfileBookmarks, updateProfileProxy, updateProfileResolution, updateProfileUserAgent } from './browser/browser-api.js';
16
16
  import BrowserChecker from './browser/browser-checker.js';
17
- import { composeFonts, downloadCookies, setExtPathsAndRemoveDeleted,
18
- setOriginalExtPaths, uploadCookies } from './browser/browser-user-data-manager.js';
19
- import { getChunckedInsertValues, getDB, loadCookiesFromFile } from './cookies/cookies-manager.js';
17
+ import {
18
+ composeFonts, downloadCookies, setExtPathsAndRemoveDeleted, setOriginalExtPaths, uploadCookies,
19
+ } from './browser/browser-user-data-manager.js';
20
+ import {
21
+ getChunckedInsertValues,
22
+ getDB,
23
+ loadCookiesFromFile,
24
+ getCookiesFilePath,
25
+ } from './cookies/cookies-manager.js';
20
26
  import ExtensionsManager from './extensions/extensions-manager.js';
21
27
  import { archiveProfile } from './profile/profile-archiver.js';
22
28
  import { checkAutoLang } from './utils/browser.js';
@@ -56,7 +62,7 @@ export class GoLogin {
56
62
  this.autoUpdateBrowser = !!options.autoUpdateBrowser;
57
63
  this.browserChecker = new BrowserChecker(options.skipOrbitaHashChecking);
58
64
  this.uploadCookiesToServer = options.uploadCookiesToServer || false;
59
- this.writeCookesFromServer = options.writeCookesFromServer;
65
+ this.writeCookiesFromServer = options.writeCookiesFromServer;
60
66
  this.remote_debugging_port = options.remote_debugging_port || 0;
61
67
  this.timezone = options.timezone;
62
68
  this.extensionPathsToInstall = [];
@@ -70,7 +76,6 @@ export class GoLogin {
70
76
  }
71
77
  }
72
78
 
73
- this.cookiesFilePath = join(this.tmpdir, `gologin_profile_${this.profile_id}`, 'Default', 'Network', 'Cookies');
74
79
  this.profile_zip_path = join(this.tmpdir, `gologin_${this.profile_id}.zip`);
75
80
  this.bookmarksFilePath = join(this.tmpdir, `gologin_profile_${this.profile_id}`, 'Default', 'Bookmarks');
76
81
  debug('INIT GOLOGIN', this.profile_id);
@@ -82,7 +87,7 @@ export class GoLogin {
82
87
 
83
88
  async setProfileId(profile_id) {
84
89
  this.profile_id = profile_id;
85
- this.cookiesFilePath = join(this.tmpdir, `gologin_profile_${this.profile_id}`, 'Default', 'Network', 'Cookies');
90
+ this.cookiesFilePath = await getCookiesFilePath(profile_id, this.tmpdir);
86
91
  this.profile_zip_path = join(this.tmpdir, `gologin_${this.profile_id}.zip`);
87
92
  }
88
93
 
@@ -581,8 +586,9 @@ export class GoLogin {
581
586
  debug(`Writing profile for screenWidth ${profilePath}`, JSON.stringify(gologin));
582
587
  gologin.screenWidth = this.resolution.width;
583
588
  gologin.screenHeight = this.resolution.height;
584
- debug('writeCookesFromServer', this.writeCookesFromServer);
585
- if (this.writeCookesFromServer) {
589
+ debug('writeCookiesFromServer', this.writeCookiesFromServer);
590
+ this.cookiesFilePath = await getCookiesFilePath(this.profile_id, this.tmpdir);
591
+ if (this.writeCookiesFromServer) {
586
592
  await this.writeCookiesToFile();
587
593
  }
588
594