gologin 2.0.19 → 2.0.21

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/.eslintrc.json CHANGED
@@ -104,9 +104,10 @@
104
104
  ],
105
105
  "no-unused-vars": [
106
106
  "warn", {
107
- "vars": "all",
108
- "args": "after-used",
109
- "ignoreRestSiblings": false
107
+ "vars": "all",
108
+ "args": "after-used",
109
+ "ignoreRestSiblings": false,
110
+ "varsIgnorePattern": "^_"
110
111
  }
111
112
  ],
112
113
  "keyword-spacing": [
@@ -1,17 +1,22 @@
1
- import puppeteer from 'puppeteer-core';
1
+ // Usage example: in the terminal enter
2
+ // node example-amazon-cloud-browser.js yU0token yU0Pr0f1leiD
3
+
4
+ // your token api (located in the settings, api)
5
+ // https://github.com/gologinapp/gologin#usage
2
6
 
3
- import GoLogin from '../src/gologin.js';
7
+ import GoLogin from 'gologin';
8
+ import puppeteer from 'puppeteer-core';
4
9
 
5
- const { connect } = puppeteer;
10
+ const [_execPath, _filePath, GOLOGIN_API_TOKEN, GOLOGIN_PROFILE_ID] = process.argv;
6
11
 
7
12
  (async () => {
8
13
  const GL = new GoLogin({
9
- token: 'yU0token',
10
- profile_id: 'yU0Pr0f1leiD',
14
+ token: GOLOGIN_API_TOKEN,
15
+ profile_id: GOLOGIN_PROFILE_ID,
11
16
  });
12
17
 
13
- const { status, wsUrl } = await GL.startRemote();
14
- const browser = await connect({
18
+ const { _status, wsUrl } = await GL.startRemote();
19
+ const browser = await puppeteer.connect({
15
20
  browserWSEndpoint: wsUrl,
16
21
  ignoreHTTPSErrors: true,
17
22
  });
@@ -1,20 +1,25 @@
1
- import puppeteer from 'puppeteer-core';
1
+ // Usage example: in the terminal enter
2
+ // node example-amazon-headless.js yU0token yU0Pr0f1leiD
3
+
4
+ // your token api (located in the settings, api)
5
+ // https://github.com/gologinapp/gologin#usage
2
6
 
3
- import GoLogin from '../src/gologin.js';
7
+ import GoLogin from 'gologin';
8
+ import puppeteer from 'puppeteer-core';
4
9
 
5
- const { connect } = puppeteer;
10
+ const [_execPath, _filePath, GOLOGIN_API_TOKEN, GOLOGIN_PROFILE_ID] = process.argv;
6
11
 
7
12
  const delay = (time) => new Promise((resolve) => setTimeout(resolve, time));
8
13
 
9
14
  (async () => {
10
15
  const GL = new GoLogin({
11
- token: 'yU0token',
12
- profile_id: 'yU0Pr0f1leiD',
16
+ token: GOLOGIN_API_TOKEN,
17
+ profile_id: GOLOGIN_PROFILE_ID,
13
18
  extra_params: ['--headless', '--no-sandbox'],
14
19
  });
15
20
 
16
- const { status, wsUrl } = await GL.start();
17
- const browser = await connect({
21
+ const { _status, wsUrl } = await GL.start();
22
+ const browser = await puppeteer.connect({
18
23
  browserWSEndpoint: wsUrl.toString(),
19
24
  ignoreHTTPSErrors: true,
20
25
  });
@@ -30,7 +35,6 @@ const delay = (time) => new Promise((resolve) => setTimeout(resolve, time));
30
35
  await session.detach();
31
36
 
32
37
  await page.goto('https://www.amazon.com/-/dp/B0771V1JZX');
33
-
34
38
  const content = await page.content();
35
39
  const matchData = content.match(/'initial': (.*)}/);
36
40
  if (matchData === null || matchData.length === 0){
@@ -1,17 +1,22 @@
1
- import puppeteer from 'puppeteer-core';
1
+ // Usage example: in the terminal enter
2
+ // node example-amazon.js yU0token yU0Pr0f1leiD
3
+
4
+ // your token api (located in the settings, api)
5
+ // https://github.com/gologinapp/gologin#usage
2
6
 
3
- import GoLogin from '../src/gologin.js';
7
+ import GoLogin from 'gologin';
8
+ import puppeteer from 'puppeteer-core';
4
9
 
5
- const { connect } = puppeteer;
10
+ const [_execPath, _filePath, GOLOGIN_API_TOKEN, GOLOGIN_PROFILE_ID] = process.argv;
6
11
 
7
12
  (async () => {
8
13
  const GL = new GoLogin({
9
- token: 'yU0token',
10
- profile_id: 'yU0Pr0f1leiD',
14
+ token: GOLOGIN_API_TOKEN,
15
+ profile_id: GOLOGIN_PROFILE_ID,
11
16
  });
12
17
 
13
- const { status, wsUrl } = await GL.start();
14
- const browser = await connect({
18
+ const { _status, wsUrl } = await GL.start();
19
+ const browser = await puppeteer.connect({
15
20
  browserWSEndpoint: wsUrl.toString(),
16
21
  ignoreHTTPSErrors: true,
17
22
  });
@@ -1,9 +1,15 @@
1
- import GoLogin from '../src/gologin.js';
1
+ // Usage example: in the terminal enter
2
+ // node example-create-custom-profile.js yU0token
3
+
4
+ // your token api (located in the settings, api)
5
+ // https://github.com/gologinapp/gologin#usage
6
+
7
+ import GoLogin from 'gologin';
8
+
9
+ const [_execPath, _filePath, GOLOGIN_API_TOKEN] = process.argv;
2
10
 
3
11
  (async () => {
4
- const GL = new GoLogin({
5
- token: 'yU0token',
6
- });
12
+ const GL = new GoLogin({ token: GOLOGIN_API_TOKEN });
7
13
 
8
14
  const profileId = await GL.createCustom({
9
15
  os: 'win', // required param ('lin', 'mac', 'win', 'android'), for macM1 write (os: 'mac') and add property 'isM1'
@@ -1,14 +1,17 @@
1
- import GoLogin from '../src/gologin.js';
1
+ // Usage example: in the terminal enter
2
+ // node example-create-profile.js yU0token
2
3
 
3
- const delay = ms => new Promise(res => setTimeout(res, ms));
4
+ // your token api (located in the settings, api)
5
+ // https://github.com/gologinapp/gologin#usage
4
6
 
5
- (async () => {
6
- const GL = new GoLogin({
7
- token: 'yU0token',
8
- });
7
+ import GoLogin from 'gologin';
8
+
9
+ const [_execPath, _filePath, GOLOGIN_API_TOKEN] = process.argv;
9
10
 
10
- // next parameters are required for creating
11
+ (async () => {
12
+ const GL = new GoLogin({ token: GOLOGIN_API_TOKEN });
11
13
 
14
+ // the following parameters are required for profile creation
12
15
  const profile_id = await GL.create({
13
16
  name: 'profile_mac',
14
17
  os: 'mac', // 'win', 'lin', 'android'
@@ -25,14 +28,12 @@ const delay = ms => new Promise(res => setTimeout(res, ms));
25
28
  });
26
29
 
27
30
  console.log('profile id=', profile_id);
28
-
29
31
  await GL.update({
30
32
  id: profile_id,
31
33
  name: 'profile_mac2',
32
34
  });
33
35
 
34
36
  const profile = await GL.getProfile(profile_id);
35
-
36
37
  console.log('new profile name=', profile.name);
37
38
 
38
39
  // await GL.delete(profile_id);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "gologin",
3
- "version": "2.0.19",
3
+ "version": "2.0.21",
4
4
  "description": "A high-level API to control Orbita browser over GoLogin API",
5
5
  "main": "./src/gologin.js",
6
6
  "repository": {
@@ -12,14 +12,16 @@ import util from 'util';
12
12
  import { findLatestBrowserVersionDirectory } from '../utils/utils.js';
13
13
 
14
14
  const exec = util.promisify(execNonPromise);
15
- const { access, mkdir, readdir, rmdir, unlink, copyFile, readlink, symlink, lstat } = _promises;
15
+ const { access, mkdir, readdir, rmdir, unlink, copyFile, readlink, symlink, lstat, rename, writeFile } = _promises;
16
16
 
17
17
  const PLATFORM = process.platform;
18
+ const ARCH = process.arch;
18
19
 
19
20
  const VERSION_FILE = 'latest-version.txt';
20
21
  const MAC_VERSION_FILE_URL = `https://orbita-browser-mac.gologin.com/${VERSION_FILE}`;
21
22
  const DEB_VERSION_FILE_URL = `https://orbita-browser-linux.gologin.com/${VERSION_FILE}`;
22
23
  const WIN_VERSION_FILE_URL = `https://orbita-browser-windows.gologin.com/${VERSION_FILE}`;
24
+ const MAC_ARM_VERSION_FILE_URL = `https://orbita-browser-mac-arm.gologin.com/${VERSION_FILE}`;
23
25
 
24
26
  const WIN_FOLDERSIZE_FILE = 'foldersize.txt';
25
27
  const WIN_FOLDERSIZE_FILE_LINK = `https://orbita-browser-windows.gologin.com/${WIN_FOLDERSIZE_FILE}`;
@@ -28,6 +30,7 @@ const BROWSER_ARCHIVE_NAME = `orbita-browser-latest.${PLATFORM === 'win32' ? 'zi
28
30
  const MAC_BROWSER_LINK = `https://orbita-browser-mac.gologin.com/${BROWSER_ARCHIVE_NAME}`;
29
31
  const DEB_BROWSER_LINK = `https://orbita-browser-linux.gologin.com/${BROWSER_ARCHIVE_NAME}`;
30
32
  const WIN_BROWSER_LINK = `https://orbita-browser-windows.gologin.com/${BROWSER_ARCHIVE_NAME}`;
33
+ const MAC_ARM_BROWSER_LINK = `https://orbita-browser-mac-arm.gologin.com/${BROWSER_ARCHIVE_NAME}`;
31
34
 
32
35
  const MAC_HASH_FILE = 'hashfile.mtree';
33
36
  const DEB_HASH_FILE = 'hashfile.txt';
@@ -35,6 +38,7 @@ const WIN_HASH_FILE = DEB_HASH_FILE;
35
38
  const MAC_HASHFILE_LINK = `https://orbita-browser-mac.gologin.com/${MAC_HASH_FILE}`;
36
39
  const DEB_HASHFILE_LINK = `https://orbita-browser-linux.gologin.com/${DEB_HASH_FILE}`;
37
40
  const WIN_HASHFILE_LINK = `https://orbita-browser-windows.gologin.com/${WIN_HASH_FILE}`;
41
+ const MAC_ARM_HASHFILE_LINK = `https://orbita-browser-mac-arm.gologin.com/${MAC_HASH_FILE}`;
38
42
 
39
43
  const FAIL_SUM_MATCH_MESSAGE = 'hash_sum_not_matched';
40
44
  const EXTRACTED_FOLDER = 'extracted-browser';
@@ -69,11 +73,12 @@ export class BrowserChecker {
69
73
  async checkBrowser(autoUpdateBrowser = false) {
70
74
  const browserFolderExists = await access(this.#executableFilePath).then(() => true).catch(() => false);
71
75
 
76
+ const browserLatestVersion = await this.getLatestBrowserVersion();
72
77
  if (!browserFolderExists) {
73
- return this.downloadBrowser();
78
+ return this.downloadBrowser(browserLatestVersion);
74
79
  }
75
80
 
76
- const browserLatestVersion = await this.getLatestBrowserVersion();
81
+
77
82
  const currentVersionReq = await this.getCurrentVersion();
78
83
  const currentVersion = (currentVersionReq?.stdout || '').replace(/(\r\n|\n|\r)/gm, '');
79
84
 
@@ -82,7 +87,7 @@ export class BrowserChecker {
82
87
  }
83
88
 
84
89
  if (autoUpdateBrowser) {
85
- return this.downloadBrowser();
90
+ return this.downloadBrowser(browserLatestVersion);
86
91
  }
87
92
 
88
93
  return new Promise(resolve => {
@@ -96,7 +101,7 @@ export class BrowserChecker {
96
101
  clearTimeout(timeout);
97
102
  rl.close();
98
103
  if (answer && answer[0].toString().toLowerCase() === 'y') {
99
- return this.downloadBrowser().then(() => resolve());
104
+ return this.downloadBrowser(browserLatestVersion).then(() => resolve());
100
105
  }
101
106
 
102
107
  console.log(`Continue with current ${currentVersion} version.`);
@@ -105,7 +110,7 @@ export class BrowserChecker {
105
110
  });
106
111
  }
107
112
 
108
- async downloadBrowser() {
113
+ async downloadBrowser(latestVersion) {
109
114
  await this.deleteOldArchives(true);
110
115
  await mkdir(this.#browserPath, { recursive: true });
111
116
 
@@ -115,6 +120,10 @@ export class BrowserChecker {
115
120
  link = WIN_BROWSER_LINK;
116
121
  } else if (PLATFORM === 'darwin') {
117
122
  link = MAC_BROWSER_LINK;
123
+
124
+ if (ARCH === 'arm64') {
125
+ link = MAC_ARM_BROWSER_LINK;
126
+ }
118
127
  }
119
128
 
120
129
  await this.downloadBrowserArchive(link, pathStr);
@@ -123,10 +132,16 @@ export class BrowserChecker {
123
132
  await this.checkBrowserSum();
124
133
  console.log('Orbita hash checked successfully');
125
134
  await this.replaceBrowser();
135
+ await this.addLatestVersion(latestVersion).catch(() => null);
126
136
  await this.deleteOldArchives();
127
137
  console.log('Orbita updated successfully');
128
138
  }
129
139
 
140
+ addLatestVersion(latestVersion) {
141
+ return mkdir(join(this.#browserPath, 'orbita-browser', 'version'), { recursive: true })
142
+ .then(() => writeFile(join(this.#browserPath, 'orbita-browser', 'version', 'latest-version.txt'), latestVersion));
143
+ }
144
+
130
145
  downloadBrowserArchive(link, pathStr) {
131
146
  return new Promise((resolve, reject) => {
132
147
  const writableStream = createWriteStream(pathStr);
@@ -207,6 +222,9 @@ export class BrowserChecker {
207
222
  let resultPath = join(this.#browserPath, DEB_HASH_FILE);
208
223
  if (PLATFORM === 'darwin') {
209
224
  hashLink = MAC_HASHFILE_LINK;
225
+ if (ARCH === 'arm64') {
226
+ hashLink = MAC_ARM_HASHFILE_LINK;
227
+ }
210
228
  resultPath = join(this.#browserPath, MAC_HASH_FILE);
211
229
  }
212
230
 
@@ -279,17 +297,7 @@ export class BrowserChecker {
279
297
  async replaceBrowser() {
280
298
  console.log('Copy Orbita to target path');
281
299
  if (PLATFORM === 'darwin') {
282
- await this.deleteDir(join(this.#browserPath, 'Orbita-Browser.app'));
283
-
284
- const files = await readdir(join(this.#browserPath, EXTRACTED_FOLDER));
285
- const promises = [];
286
- files.forEach((filename) => {
287
- if (filename.match(/.*\.dylib$/)) {
288
- promises.push(copyFile(join(this.#browserPath, EXTRACTED_FOLDER, filename), join(this.#browserPath, filename)));
289
- }
290
- });
291
-
292
- return Promise.all(promises);
300
+ return rename(join(this.#browserPath, EXTRACTED_FOLDER), join(this.#browserPath, 'orbita-browser'))
293
301
  }
294
302
 
295
303
  const targetBrowserPath = join(this.#browserPath, 'orbita-browser');
@@ -303,7 +311,7 @@ export class BrowserChecker {
303
311
 
304
312
  async deleteOldArchives(deleteCurrentBrowser = false) {
305
313
  if (deleteCurrentBrowser) {
306
- return this.deleteDir(join(this.#browserPath));
314
+ return this.deleteDir(join(this.#browserPath, 'orbita-browser'));
307
315
  }
308
316
 
309
317
  await this.deleteDir(join(this.#browserPath, EXTRACTED_FOLDER));
@@ -347,7 +355,7 @@ export class BrowserChecker {
347
355
  if (PLATFORM === 'win32') {
348
356
  command = `if exist "${join(this.#browserPath, 'orbita-browser', 'version')}" (type "${join(this.#browserPath, 'orbita-browser', 'version')}") else (echo 0.0.0)`;
349
357
  } else if (PLATFORM === 'darwin') {
350
- command = `if [ -f ${join(this.#browserPath, 'version', VERSION_FILE)} ]; then cat ${join(this.#browserPath, 'version', VERSION_FILE)}; else echo 0.0.0; fi`;
358
+ command = `if [ -f ${join(this.#browserPath, 'orbita-browser', 'version', VERSION_FILE)} ]; then cat ${join(this.#browserPath, 'orbita-browser', 'version', VERSION_FILE)}; else echo 0.0.0; fi`;
351
359
  }
352
360
 
353
361
  return exec(command);
@@ -359,6 +367,10 @@ export class BrowserChecker {
359
367
  url = WIN_VERSION_FILE_URL;
360
368
  } else if (PLATFORM === 'darwin') {
361
369
  url = MAC_VERSION_FILE_URL;
370
+
371
+ if (ARCH === 'arm64') {
372
+ url = MAC_ARM_VERSION_FILE_URL;
373
+ }
362
374
  }
363
375
 
364
376
  return new Promise(resolve => get(url,
package/src/gologin.js CHANGED
@@ -73,6 +73,8 @@ export class GoLogin {
73
73
  this.timezone = options.timezone;
74
74
  this.extensionPathsToInstall = [];
75
75
  this.restoreLastSession = options.restoreLastSession || false;
76
+ this.processSpawned = null;
77
+ this.processKillTimeout = 1 * 1000;
76
78
 
77
79
  if (options.tmpdir) {
78
80
  this.tmpdir = options.tmpdir;
@@ -95,6 +97,7 @@ export class GoLogin {
95
97
  this.profile_id = profile_id;
96
98
  this.cookiesFilePath = await getCookiesFilePath(profile_id, this.tmpdir);
97
99
  this.profile_zip_path = join(this.tmpdir, `gologin_${this.profile_id}.zip`);
100
+ this.bookmarksFilePath = join(this.tmpdir, `gologin_profile_${this.profile_id}`, 'Default', 'Bookmarks');
98
101
  }
99
102
 
100
103
  async getToken(username, password) {
@@ -744,10 +747,10 @@ export class GoLogin {
744
747
  }
745
748
 
746
749
  const proxyUrl = `${proxy.mode}://${proxy.username}:${proxy.password}@${proxy.host}:${proxy.port}`;
747
- debug('getTimeZone start https://time.gologin.com/timezone', proxyUrl);
748
- data = await requests.get('https://time.gologin.com/timezone', { proxy: proxyUrl, timeout: 20 * 1000, maxAttempts: 5 });
750
+ debug('getTimeZone start https://ipgeo.gologin.com', proxyUrl);
751
+ data = await requests.get('https://ipgeo.gologin.com', { proxy: proxyUrl, timeout: 20 * 1000, maxAttempts: 5 });
749
752
  } else {
750
- data = await requests.get('https://time.gologin.com/timezone', { timeout: 20 * 1000, maxAttempts: 5 });
753
+ data = await requests.get('https://ipgeo.gologin.com', { timeout: 20 * 1000, maxAttempts: 5 });
751
754
  }
752
755
 
753
756
  debug('getTimeZone finish', data.body);
@@ -771,7 +774,7 @@ export class GoLogin {
771
774
  const agent = new ProxyAgent(proxy, { tunnel: true, timeout: 10000 });
772
775
 
773
776
  const checkData = await new Promise((resolve, reject) => {
774
- _get('https://time.gologin.com/timezone', { agent }, (res) => {
777
+ _get('https://ipgeo.gologin.com', { agent }, (res) => {
775
778
  let resultResponse = '';
776
779
  res.on('data', (data) => resultResponse += data);
777
780
 
@@ -926,6 +929,7 @@ export class GoLogin {
926
929
 
927
930
  console.log(params);
928
931
  const child = execFile(ORBITA_BROWSER, params, { env });
932
+ this.processSpawned = child;
929
933
  // const child = spawn(ORBITA_BROWSER, params, { env, shell: true });
930
934
  child.stdout.on('data', (data) => debug(data.toString()));
931
935
  debug('SPAWN CMD', ORBITA_BROWSER, params.join(' '));
@@ -1009,12 +1013,36 @@ export class GoLogin {
1009
1013
  debug('browser killed');
1010
1014
  }
1011
1015
 
1016
+ killBrowser() {
1017
+ if (!this.processSpawned.pid) {
1018
+ return;
1019
+ }
1020
+
1021
+ try {
1022
+ this.processSpawned.kill();
1023
+ debug('browser killed');
1024
+ } catch (error) {
1025
+ console.error(error);
1026
+ }
1027
+ }
1028
+
1029
+ async killAndCommit(options, local = false) {
1030
+ this.killBrowser();
1031
+ await delay(this.processKillTimeout);
1032
+ await this.stopAndCommit(options, local).catch(console.error);
1033
+ }
1034
+
1012
1035
  async sanitizeProfile() {
1013
1036
  const remove_dirs = [
1014
1037
  `${SEPARATOR}Default${SEPARATOR}Cache`,
1015
- `${SEPARATOR}Default${SEPARATOR}Service Worker${SEPARATOR}CacheStorage`,
1038
+ `${SEPARATOR}Default${SEPARATOR}Service Worker`,
1016
1039
  `${SEPARATOR}Default${SEPARATOR}Code Cache`,
1017
1040
  `${SEPARATOR}Default${SEPARATOR}GPUCache`,
1041
+ `${SEPARATOR}Default${SEPARATOR}Extensions`,
1042
+ `${SEPARATOR}Default${SEPARATOR}IndexedDB`,
1043
+ `${SEPARATOR}Default${SEPARATOR}GPUCache`,
1044
+ `${SEPARATOR}Default${SEPARATOR}DawnCache`,
1045
+ `${SEPARATOR}Default${SEPARATOR}fonts_config`,
1018
1046
  `${SEPARATOR}GrShaderCache`,
1019
1047
  `${SEPARATOR}ShaderCache`,
1020
1048
  `${SEPARATOR}biahpgbdmdkfgndcmfiipgcebobojjkp`,
@@ -11,7 +11,7 @@ const DEFAULT_FOLDER_USELESS_FILE = [
11
11
  },
12
12
  {
13
13
  name: 'Service Worker',
14
- subs: ['CacheStorage', 'ScriptCache'],
14
+ subs: [],
15
15
  isDirectory: true,
16
16
  },
17
17
  {
@@ -19,6 +19,26 @@ const DEFAULT_FOLDER_USELESS_FILE = [
19
19
  subs: [],
20
20
  isDirectory: true,
21
21
  },
22
+ {
23
+ name: 'Extensions',
24
+ subs: [],
25
+ isDirectory: true,
26
+ },
27
+ {
28
+ name: 'IndexedDB',
29
+ subs: [],
30
+ isDirectory: true,
31
+ },
32
+ {
33
+ name: 'fonts_config',
34
+ subs: [],
35
+ isDirectory: true,
36
+ },
37
+ {
38
+ name: 'DawnCache',
39
+ subs: [],
40
+ isDirectory: true,
41
+ },
22
42
  {
23
43
  name: 'GPUCache',
24
44
  subs: [],