gologin 2.0.20 → 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.20",
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": {
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,6 +1013,25 @@ 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`,