gologin 2.0.11 → 2.0.12

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: {
23
+ mode: 'http',
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
 
@@ -3,7 +3,7 @@
3
3
 
4
4
  // your token api (located in the settings, api)
5
5
  // https://github.com/gologinapp/gologin#usage
6
- import GoLogin from '../gologin.js';
6
+ import GoLogin from '../src/gologin.js';
7
7
 
8
8
  const GOLOGIN_API_TOKEN = process.argv[2];
9
9
  // your profile id
@@ -3,7 +3,7 @@
3
3
 
4
4
  // your token api (located in the settings, api)
5
5
  // https://github.com/gologinapp/gologin#usage
6
- import GoLogin from '../gologin.js';
6
+ import GoLogin from '../src/gologin.js';
7
7
 
8
8
  const GOLOGIN_API_TOKEN = process.argv[2];
9
9
  // your profile id
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "gologin",
3
- "version": "2.0.11",
3
+ "version": "2.0.12",
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
@@ -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) {
@@ -1140,6 +1145,29 @@ export class GoLogin {
1140
1145
  return response.body.id;
1141
1146
  }
1142
1147
 
1148
+ async createCustom(options) {
1149
+ debug('createCustomProfile', options);
1150
+ const response = await requests.post(`${API_URL}/browser/custom`, {
1151
+ headers: {
1152
+ 'Authorization': `Bearer ${this.access_token}`,
1153
+ 'User-Agent': 'gologin-api',
1154
+ },
1155
+ json: options,
1156
+ });
1157
+
1158
+ if (response.statusCode === 400) {
1159
+ throw new Error(`gologin failed account creation with status code, ${response.statusCode} DATA ${JSON.stringify(response.body.message)}`);
1160
+ }
1161
+
1162
+ if (response.statusCode === 500) {
1163
+ throw new Error(`gologin failed account creation with status code, ${response.statusCode}`);
1164
+ }
1165
+
1166
+ debug(JSON.stringify(response));
1167
+
1168
+ return response.body.id;
1169
+ }
1170
+
1143
1171
  async delete(pid) {
1144
1172
  const profile_id = pid || this.profile_id;
1145
1173
  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
+ };