gologin 2.0.20 → 2.0.22
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 +4 -3
- package/examples/{example-amazon-goless.js → example-amazon-cloud-browser.js} +12 -7
- package/examples/example-amazon-headless.js +12 -8
- package/examples/example-amazon.js +12 -7
- package/examples/example-create-custom-profile.js +10 -4
- package/examples/example-create-profile.js +10 -9
- package/package.json +1 -1
- package/src/gologin.js +29 -5
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
|
-
|
|
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 '
|
|
7
|
+
import GoLogin from 'gologin';
|
|
8
|
+
import puppeteer from 'puppeteer-core';
|
|
4
9
|
|
|
5
|
-
const
|
|
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:
|
|
10
|
-
profile_id:
|
|
14
|
+
token: GOLOGIN_API_TOKEN,
|
|
15
|
+
profile_id: GOLOGIN_PROFILE_ID,
|
|
11
16
|
});
|
|
12
17
|
|
|
13
|
-
const {
|
|
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
|
-
|
|
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 '
|
|
7
|
+
import GoLogin from 'gologin';
|
|
8
|
+
import puppeteer from 'puppeteer-core';
|
|
4
9
|
|
|
5
|
-
const
|
|
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:
|
|
12
|
-
profile_id:
|
|
16
|
+
token: GOLOGIN_API_TOKEN,
|
|
17
|
+
profile_id: GOLOGIN_PROFILE_ID,
|
|
13
18
|
extra_params: ['--headless', '--no-sandbox'],
|
|
14
19
|
});
|
|
15
20
|
|
|
16
|
-
const {
|
|
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
|
-
|
|
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 '
|
|
7
|
+
import GoLogin from 'gologin';
|
|
8
|
+
import puppeteer from 'puppeteer-core';
|
|
4
9
|
|
|
5
|
-
const
|
|
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:
|
|
10
|
-
profile_id:
|
|
14
|
+
token: GOLOGIN_API_TOKEN,
|
|
15
|
+
profile_id: GOLOGIN_PROFILE_ID,
|
|
11
16
|
});
|
|
12
17
|
|
|
13
|
-
const {
|
|
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
|
-
|
|
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
|
-
|
|
1
|
+
// Usage example: in the terminal enter
|
|
2
|
+
// node example-create-profile.js yU0token
|
|
2
3
|
|
|
3
|
-
|
|
4
|
+
// your token api (located in the settings, api)
|
|
5
|
+
// https://github.com/gologinapp/gologin#usage
|
|
4
6
|
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
});
|
|
7
|
+
import GoLogin from 'gologin';
|
|
8
|
+
|
|
9
|
+
const [_execPath, _filePath, GOLOGIN_API_TOKEN] = process.argv;
|
|
9
10
|
|
|
10
|
-
|
|
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
package/src/gologin.js
CHANGED
|
@@ -59,6 +59,7 @@ export class GoLogin {
|
|
|
59
59
|
this.waitWebsocket = false;
|
|
60
60
|
}
|
|
61
61
|
|
|
62
|
+
this.isCloudHeadless = options.isCloudHeadless || true;
|
|
62
63
|
this.isNewCloudBrowser = true;
|
|
63
64
|
if (options.isNewCloudBrowser === false) {
|
|
64
65
|
this.isNewCloudBrowser = false;
|
|
@@ -73,6 +74,8 @@ export class GoLogin {
|
|
|
73
74
|
this.timezone = options.timezone;
|
|
74
75
|
this.extensionPathsToInstall = [];
|
|
75
76
|
this.restoreLastSession = options.restoreLastSession || false;
|
|
77
|
+
this.processSpawned = null;
|
|
78
|
+
this.processKillTimeout = 1 * 1000;
|
|
76
79
|
|
|
77
80
|
if (options.tmpdir) {
|
|
78
81
|
this.tmpdir = options.tmpdir;
|
|
@@ -95,6 +98,7 @@ export class GoLogin {
|
|
|
95
98
|
this.profile_id = profile_id;
|
|
96
99
|
this.cookiesFilePath = await getCookiesFilePath(profile_id, this.tmpdir);
|
|
97
100
|
this.profile_zip_path = join(this.tmpdir, `gologin_${this.profile_id}.zip`);
|
|
101
|
+
this.bookmarksFilePath = join(this.tmpdir, `gologin_profile_${this.profile_id}`, 'Default', 'Bookmarks');
|
|
98
102
|
}
|
|
99
103
|
|
|
100
104
|
async getToken(username, password) {
|
|
@@ -744,10 +748,10 @@ export class GoLogin {
|
|
|
744
748
|
}
|
|
745
749
|
|
|
746
750
|
const proxyUrl = `${proxy.mode}://${proxy.username}:${proxy.password}@${proxy.host}:${proxy.port}`;
|
|
747
|
-
debug('getTimeZone start https://
|
|
748
|
-
data = await requests.get('https://
|
|
751
|
+
debug('getTimeZone start https://ipgeo.gologin.com', proxyUrl);
|
|
752
|
+
data = await requests.get('https://ipgeo.gologin.com', { proxy: proxyUrl, timeout: 20 * 1000, maxAttempts: 5 });
|
|
749
753
|
} else {
|
|
750
|
-
data = await requests.get('https://
|
|
754
|
+
data = await requests.get('https://ipgeo.gologin.com', { timeout: 20 * 1000, maxAttempts: 5 });
|
|
751
755
|
}
|
|
752
756
|
|
|
753
757
|
debug('getTimeZone finish', data.body);
|
|
@@ -771,7 +775,7 @@ export class GoLogin {
|
|
|
771
775
|
const agent = new ProxyAgent(proxy, { tunnel: true, timeout: 10000 });
|
|
772
776
|
|
|
773
777
|
const checkData = await new Promise((resolve, reject) => {
|
|
774
|
-
_get('https://
|
|
778
|
+
_get('https://ipgeo.gologin.com', { agent }, (res) => {
|
|
775
779
|
let resultResponse = '';
|
|
776
780
|
res.on('data', (data) => resultResponse += data);
|
|
777
781
|
|
|
@@ -926,6 +930,7 @@ export class GoLogin {
|
|
|
926
930
|
|
|
927
931
|
console.log(params);
|
|
928
932
|
const child = execFile(ORBITA_BROWSER, params, { env });
|
|
933
|
+
this.processSpawned = child;
|
|
929
934
|
// const child = spawn(ORBITA_BROWSER, params, { env, shell: true });
|
|
930
935
|
child.stdout.on('data', (data) => debug(data.toString()));
|
|
931
936
|
debug('SPAWN CMD', ORBITA_BROWSER, params.join(' '));
|
|
@@ -1009,6 +1014,25 @@ export class GoLogin {
|
|
|
1009
1014
|
debug('browser killed');
|
|
1010
1015
|
}
|
|
1011
1016
|
|
|
1017
|
+
killBrowser() {
|
|
1018
|
+
if (!this.processSpawned.pid) {
|
|
1019
|
+
return;
|
|
1020
|
+
}
|
|
1021
|
+
|
|
1022
|
+
try {
|
|
1023
|
+
this.processSpawned.kill();
|
|
1024
|
+
debug('browser killed');
|
|
1025
|
+
} catch (error) {
|
|
1026
|
+
console.error(error);
|
|
1027
|
+
}
|
|
1028
|
+
}
|
|
1029
|
+
|
|
1030
|
+
async killAndCommit(options, local = false) {
|
|
1031
|
+
this.killBrowser();
|
|
1032
|
+
await delay(this.processKillTimeout);
|
|
1033
|
+
await this.stopAndCommit(options, local).catch(console.error);
|
|
1034
|
+
}
|
|
1035
|
+
|
|
1012
1036
|
async sanitizeProfile() {
|
|
1013
1037
|
const remove_dirs = [
|
|
1014
1038
|
`${SEPARATOR}Default${SEPARATOR}Cache`,
|
|
@@ -1438,7 +1462,7 @@ export class GoLogin {
|
|
|
1438
1462
|
|
|
1439
1463
|
const profileResponse = await requests.post(`${API_URL}/browser/${this.profile_id}/web`, {
|
|
1440
1464
|
headers: { 'Authorization': `Bearer ${this.access_token}` },
|
|
1441
|
-
json: { isNewCloudBrowser: this.isNewCloudBrowser },
|
|
1465
|
+
json: { isNewCloudBrowser: this.isNewCloudBrowser, isHeadless: this.isCloudHeadless },
|
|
1442
1466
|
});
|
|
1443
1467
|
|
|
1444
1468
|
debug('profileResponse', profileResponse.statusCode, profileResponse.body);
|