gologin 2.0.11 → 2.0.13
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.
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import GoLogin from '../src/gologin.js';
|
|
2
|
+
|
|
3
|
+
(async () => {
|
|
4
|
+
const GL = new GoLogin({
|
|
5
|
+
token: 'yU0token',
|
|
6
|
+
});
|
|
7
|
+
|
|
8
|
+
const profileId = await GL.createCustom({
|
|
9
|
+
os: 'win', // required param ('lin', 'mac', 'win', 'android'), for macM1 write (os: 'mac') and add property 'isM1'
|
|
10
|
+
// isM1: true,
|
|
11
|
+
name: 'testName',
|
|
12
|
+
fingerprint: {
|
|
13
|
+
autoLang: true,
|
|
14
|
+
resolution: '800x400',
|
|
15
|
+
language: 'de',
|
|
16
|
+
dns: 'testDNS',
|
|
17
|
+
hardwareConcurrency: 8,
|
|
18
|
+
deviceMemory: 4, // 0.5, 1, 2, 4, 6, 8
|
|
19
|
+
startUrl: 'https://testurl.com',
|
|
20
|
+
googleServicesEnabled: true,
|
|
21
|
+
lockEnabled: true,
|
|
22
|
+
// proxy: { // uncomment and check input if you need to use proxy
|
|
23
|
+
// mode: 'http', // 'socks4', 'socks5'
|
|
24
|
+
// host: '123.12.123.12',
|
|
25
|
+
// port: 1234,
|
|
26
|
+
// username: 'user',
|
|
27
|
+
// password: 'password',
|
|
28
|
+
// },
|
|
29
|
+
},
|
|
30
|
+
});
|
|
31
|
+
|
|
32
|
+
console.log('profile id=', profileId);
|
|
33
|
+
})();
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import GoLogin from '../gologin.js';
|
|
1
|
+
import GoLogin from '../src/gologin.js';
|
|
2
2
|
|
|
3
3
|
const delay = ms => new Promise(res => setTimeout(res, ms));
|
|
4
4
|
|
|
@@ -11,17 +11,17 @@ const delay = ms => new Promise(res => setTimeout(res, ms));
|
|
|
11
11
|
|
|
12
12
|
const profile_id = await GL.create({
|
|
13
13
|
name: 'profile_mac',
|
|
14
|
-
os: 'mac',
|
|
14
|
+
os: 'mac', // 'win', 'lin', 'android'
|
|
15
|
+
// isM1: true, // for Mac M1
|
|
15
16
|
navigator: {
|
|
16
|
-
language: '
|
|
17
|
+
language: 'en-US,en;q=0.9',
|
|
17
18
|
userAgent: 'random', // get random user agent for selected os
|
|
18
19
|
resolution: '1024x768',
|
|
19
|
-
platform: 'mac',
|
|
20
20
|
},
|
|
21
21
|
proxyEnabled: false,
|
|
22
22
|
proxy: {
|
|
23
23
|
mode: 'none',
|
|
24
|
-
}
|
|
24
|
+
},
|
|
25
25
|
});
|
|
26
26
|
|
|
27
27
|
console.log('profile id=', profile_id);
|
package/package.json
CHANGED
package/src/gologin.js
CHANGED
|
@@ -19,6 +19,7 @@ import { composeFonts, downloadCookies, setExtPathsAndRemoveDeleted,
|
|
|
19
19
|
import { getChunckedInsertValues, getDB, loadCookiesFromFile } from './cookies/cookies-manager.js';
|
|
20
20
|
import ExtensionsManager from './extensions/extensions-manager.js';
|
|
21
21
|
import { archiveProfile } from './profile/profile-archiver.js';
|
|
22
|
+
import { checkAutoLang } from './utils/browser.js';
|
|
22
23
|
import { API_URL } from './utils/common.js';
|
|
23
24
|
import { get, isPortReachable } from './utils/utils.js';
|
|
24
25
|
|
|
@@ -33,6 +34,7 @@ const delay = (time) => new Promise((resolve) => setTimeout(resolve, time));
|
|
|
33
34
|
|
|
34
35
|
export class GoLogin {
|
|
35
36
|
constructor(options = {}) {
|
|
37
|
+
this.browserLang = 'en-US';
|
|
36
38
|
this.is_remote = options.remote || false;
|
|
37
39
|
this.access_token = options.token;
|
|
38
40
|
this.profile_id = options.profile_id;
|
|
@@ -597,15 +599,23 @@ export class GoLogin {
|
|
|
597
599
|
}
|
|
598
600
|
}
|
|
599
601
|
|
|
600
|
-
const languages = this.language.replace(/;|q=[\d\.]+/img, '')
|
|
602
|
+
const languages = this.language.replace(/;|q=[\d\.]+/img, '');
|
|
601
603
|
|
|
602
604
|
if (preferences.gologin==null) {
|
|
603
605
|
preferences.gologin = {};
|
|
604
606
|
}
|
|
605
607
|
|
|
606
|
-
preferences.gologin.langHeader = gologin.language;
|
|
608
|
+
preferences.gologin.langHeader = gologin.navigator.language;
|
|
607
609
|
preferences.gologin.language = languages;
|
|
608
610
|
|
|
611
|
+
const [splittedLangs] = gologin.navigator.language.split(';');
|
|
612
|
+
const [browserLang] = splittedLangs.split(',');
|
|
613
|
+
gologin.browserLang = browserLang;
|
|
614
|
+
|
|
615
|
+
const isMAC = OS_PLATFORM === 'darwin';
|
|
616
|
+
const checkAutoLangResult = checkAutoLang(gologin, this._tz);
|
|
617
|
+
this.browserLang = isMAC ? 'en-US' : checkAutoLangResult;
|
|
618
|
+
|
|
609
619
|
await writeFile(join(profilePath, 'Default', 'Preferences'), JSON.stringify(Object.assign(preferences, {
|
|
610
620
|
gologin,
|
|
611
621
|
})));
|
|
@@ -838,18 +848,13 @@ export class GoLogin {
|
|
|
838
848
|
{ env },
|
|
839
849
|
);
|
|
840
850
|
} else {
|
|
841
|
-
const [splittedLangs] = this.language.split(';');
|
|
842
|
-
let [browserLang] = splittedLangs.split(',');
|
|
843
|
-
if (process.platform === 'darwin') {
|
|
844
|
-
browserLang = 'en-US';
|
|
845
|
-
}
|
|
846
851
|
|
|
847
852
|
let params = [
|
|
848
853
|
`--remote-debugging-port=${remote_debugging_port}`,
|
|
849
854
|
`--user-data-dir=${profile_path}`,
|
|
850
855
|
'--password-store=basic',
|
|
851
856
|
`--tz=${tz}`,
|
|
852
|
-
`--lang=${browserLang}`,
|
|
857
|
+
`--lang=${this.browserLang}`,
|
|
853
858
|
];
|
|
854
859
|
|
|
855
860
|
if (this.extensionPathsToInstall.length) {
|
|
@@ -1060,7 +1065,12 @@ export class GoLogin {
|
|
|
1060
1065
|
os = options.os;
|
|
1061
1066
|
}
|
|
1062
1067
|
|
|
1063
|
-
|
|
1068
|
+
let url = `${API_URL}/browser/fingerprint?os=${os}`;
|
|
1069
|
+
if (options.isM1) {
|
|
1070
|
+
url += '&isM1=true';
|
|
1071
|
+
}
|
|
1072
|
+
|
|
1073
|
+
const fingerprint = await requests.get(url,{
|
|
1064
1074
|
headers: {
|
|
1065
1075
|
'Authorization': `Bearer ${this.access_token}`,
|
|
1066
1076
|
'User-Agent': 'gologin-api',
|
|
@@ -1111,12 +1121,20 @@ export class GoLogin {
|
|
|
1111
1121
|
|
|
1112
1122
|
const user_agent = options.navigator?.userAgent;
|
|
1113
1123
|
const orig_user_agent = json.navigator.userAgent;
|
|
1114
|
-
Object.keys(options).
|
|
1115
|
-
json[
|
|
1124
|
+
Object.keys(options).forEach((key) => {
|
|
1125
|
+
if (typeof json[key] === 'object') {
|
|
1126
|
+
json[key] = { ...json[key], ...options[key] };
|
|
1127
|
+
|
|
1128
|
+
return;
|
|
1129
|
+
}
|
|
1130
|
+
|
|
1131
|
+
json[key] = options[key];
|
|
1116
1132
|
});
|
|
1133
|
+
|
|
1117
1134
|
if (user_agent === 'random') {
|
|
1118
1135
|
json.navigator.userAgent = orig_user_agent;
|
|
1119
1136
|
}
|
|
1137
|
+
|
|
1120
1138
|
// console.log('profileOptions', json);
|
|
1121
1139
|
|
|
1122
1140
|
const response = await requests.post(`${API_URL}/browser`, {
|
|
@@ -1140,6 +1158,29 @@ export class GoLogin {
|
|
|
1140
1158
|
return response.body.id;
|
|
1141
1159
|
}
|
|
1142
1160
|
|
|
1161
|
+
async createCustom(options) {
|
|
1162
|
+
debug('createCustomProfile', options);
|
|
1163
|
+
const response = await requests.post(`${API_URL}/browser/custom`, {
|
|
1164
|
+
headers: {
|
|
1165
|
+
'Authorization': `Bearer ${this.access_token}`,
|
|
1166
|
+
'User-Agent': 'gologin-api',
|
|
1167
|
+
},
|
|
1168
|
+
json: options,
|
|
1169
|
+
});
|
|
1170
|
+
|
|
1171
|
+
if (response.statusCode === 400) {
|
|
1172
|
+
throw new Error(`gologin failed account creation with status code, ${response.statusCode} DATA ${JSON.stringify(response.body.message)}`);
|
|
1173
|
+
}
|
|
1174
|
+
|
|
1175
|
+
if (response.statusCode === 500) {
|
|
1176
|
+
throw new Error(`gologin failed account creation with status code, ${response.statusCode}`);
|
|
1177
|
+
}
|
|
1178
|
+
|
|
1179
|
+
debug(JSON.stringify(response));
|
|
1180
|
+
|
|
1181
|
+
return response.body.id;
|
|
1182
|
+
}
|
|
1183
|
+
|
|
1143
1184
|
async delete(pid) {
|
|
1144
1185
|
const profile_id = pid || this.profile_id;
|
|
1145
1186
|
await requests.delete(`${API_URL}/browser/${profile_id}`, {
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
export const checkAutoLang = (profileData, timezoneCheckResult) => {
|
|
2
|
+
if (!profileData.autoLang) {
|
|
3
|
+
return checkBrowserLang(profileData);
|
|
4
|
+
}
|
|
5
|
+
|
|
6
|
+
let timezoneLang = '';
|
|
7
|
+
const { country: timezoneCountry = '', languages } = timezoneCheckResult || {};
|
|
8
|
+
if (languages) {
|
|
9
|
+
const [firstDetectedLangLocale] = languages.split(',');
|
|
10
|
+
timezoneLang = `${firstDetectedLangLocale}-${timezoneCountry}` || '';
|
|
11
|
+
|
|
12
|
+
let resultLangsArr = [];
|
|
13
|
+
const [lang = '', country = ''] = timezoneLang.split('-');
|
|
14
|
+
if (country) {
|
|
15
|
+
resultLangsArr.push([lang, country].join('-'));
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
resultLangsArr.push(lang, 'en-US', 'en');
|
|
19
|
+
resultLangsArr = [...new Set(resultLangsArr)];
|
|
20
|
+
|
|
21
|
+
const gologinLangsArr = [];
|
|
22
|
+
const result = resultLangsArr.reduce((acc, cur, index) => {
|
|
23
|
+
if (!index) {
|
|
24
|
+
acc += `${cur},`;
|
|
25
|
+
gologinLangsArr.push(cur);
|
|
26
|
+
|
|
27
|
+
return acc;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
const qualityParam = 10-index;
|
|
31
|
+
if (qualityParam > 0) {
|
|
32
|
+
const separator = (resultLangsArr.length - index) < 2 ? '' : ',';
|
|
33
|
+
gologinLangsArr.push(cur);
|
|
34
|
+
acc += `${cur};q=${Number(qualityParam * 0.1).toFixed(1)}${separator}`;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
return acc;
|
|
38
|
+
}, '');
|
|
39
|
+
|
|
40
|
+
[profileData.browserLang] = resultLangsArr;
|
|
41
|
+
profileData.languages = gologinLangsArr.join(',');
|
|
42
|
+
profileData.langHeader = result;
|
|
43
|
+
profileData.navigator.language = result;
|
|
44
|
+
|
|
45
|
+
return profileData.browserLang;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
return checkBrowserLang(profileData);
|
|
49
|
+
};
|
|
50
|
+
|
|
51
|
+
const checkBrowserLang = (profileData, defaultLocale = 'en-US') => {
|
|
52
|
+
if (profileData.langHeader) {
|
|
53
|
+
return profileData.browserLang;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
profileData.browserLang = defaultLocale;
|
|
57
|
+
profileData.languages = defaultLocale;
|
|
58
|
+
profileData.langHeader = defaultLocale;
|
|
59
|
+
profileData.navigator.language = defaultLocale;
|
|
60
|
+
|
|
61
|
+
return defaultLocale;
|
|
62
|
+
};
|