gologin 2.1.15 → 2.1.16

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.
Files changed (2) hide show
  1. package/package.json +1 -1
  2. package/src/gologin.js +106 -123
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "gologin",
3
- "version": "2.1.15",
3
+ "version": "2.1.16",
4
4
  "description": "A high-level API to control Orbita browser over GoLogin API",
5
5
  "types": "./index.d.ts",
6
6
  "main": "./src/gologin.js",
package/src/gologin.js CHANGED
@@ -252,63 +252,105 @@ export class GoLogin {
252
252
  return profile;
253
253
  }
254
254
 
255
- convertPreferences(preferences) {
256
- if (get(preferences, 'navigator.userAgent')) {
257
- preferences.userAgent = get(preferences, 'navigator.userAgent');
258
- }
259
-
260
- if (get(preferences, 'navigator.doNotTrack')) {
261
- preferences.doNotTrack = get(preferences, 'navigator.doNotTrack');
262
- }
263
-
264
- if (get(preferences, 'navigator.hardwareConcurrency')) {
265
- preferences.hardwareConcurrency = get(preferences, 'navigator.hardwareConcurrency');
266
- }
267
-
268
- if (get(preferences, 'navigator.deviceMemory')) {
269
- preferences.deviceMemory = get(preferences, 'navigator.deviceMemory') * 1024;
270
- }
271
-
272
- if (get(preferences, 'navigator.language')) {
273
- preferences.langHeader = get(preferences, 'navigator.language');
274
- preferences.languages = get(preferences, 'navigator.language').replace(/;|q=[\d\.]+/img, '');
275
- }
276
-
277
- if (get(preferences, 'navigator.maxTouchPoints')) {
278
- preferences.navigator.max_touch_points = get(preferences, 'navigator.maxTouchPoints');
279
- }
280
-
281
- if (get(preferences, 'isM1')) {
282
- preferences.is_m1 = get(preferences, 'isM1');
283
- }
284
-
285
- if (get(preferences, 'os') == 'android') {
286
- const devicePixelRatio = get(preferences, 'devicePixelRatio');
287
- const deviceScaleFactorCeil = Math.ceil(devicePixelRatio || 3.5);
288
- let deviceScaleFactor = devicePixelRatio;
289
- if (deviceScaleFactorCeil === devicePixelRatio) {
290
- deviceScaleFactor += 0.00000001;
291
- }
292
-
293
- preferences.mobile = {
294
- enable: true,
295
- width: parseInt(this.resolution.width, 10),
296
- height: parseInt(this.resolution.height, 10),
297
- device_scale_factor: deviceScaleFactor,
298
- };
299
- }
300
-
301
- preferences.mediaDevices = {
302
- enable: preferences.mediaDevices.enableMasking,
303
- videoInputs: preferences.mediaDevices.videoInputs,
304
- audioInputs: preferences.mediaDevices.audioInputs,
305
- audioOutputs: preferences.mediaDevices.audioOutputs,
306
- };
307
-
308
- preferences.webRtc = {
309
- ...preferences.webRtc,
310
- fill_based_on_ip: !!get(preferences, 'webRTC.fillBasedOnIp'),
311
- local_ip_masking: !!get(preferences, 'webRTC.local_ip_masking'),
255
+ getGologinPreferences(profileData) {
256
+ const os = profileData.os || '';
257
+ const osSpec = profileData.osSpec || '';
258
+ const isM1 = profileData.isM1 || false;
259
+ const isArm = (os === 'mac' && osSpec && osSpec.includes('M')) || isM1;
260
+ const resolution = (profileData.navigator && profileData.navigator.resolution) || '1920x1080';
261
+ const [screenWidth, screenHeight] = resolution.split('x').map(Number);
262
+ const langHeader = (profileData.navigator && profileData.navigator.language) || '';
263
+ console.log('langHeader', langHeader);
264
+ const splittedLangs = langHeader ? langHeader.split(',')[0] : 'en-US';
265
+
266
+ const startupUrl = (profileData.startUrl || '').trim().split(',')[0];
267
+ const startupUrls = (profileData.startUrl || '').split(',')
268
+ .map(url => url.trim())
269
+ .filter(url => url);
270
+
271
+ const preferences = {
272
+ profile_id: profileData.id,
273
+ name: profileData.name,
274
+ is_m1: isArm,
275
+ navigator: {
276
+ platform: (profileData.navigator?.platform) || '',
277
+ max_touch_points: (profileData.navigator?.maxTouchPoints) || 0,
278
+ },
279
+ dns: profileData.dns || {},
280
+ proxy: {
281
+ username: (profileData.proxy?.username) || '',
282
+ password: (profileData.proxy?.password) || '',
283
+ },
284
+ webRTC: profileData.webRTC || {},
285
+ screenHeight,
286
+ screenWidth,
287
+ userAgent: (profileData.navigator?.userAgent) || '',
288
+ webGl: {
289
+ vendor: (profileData.webGLMetadata?.vendor) || '',
290
+ renderer: (profileData.webGLMetadata?.renderer) || '',
291
+ mode: (profileData.webGLMetadata?.mode) === 'mask',
292
+ },
293
+ webgl: {
294
+ metadata: {
295
+ vendor: (profileData.webGLMetadata?.vendor) || '',
296
+ renderer: (profileData.webGLMetadata?.renderer) || '',
297
+ mode: (profileData.webGLMetadata?.mode) === 'mask',
298
+ },
299
+ },
300
+ mobile: {
301
+ enable: profileData.os === 'android',
302
+ width: profileData.screenWidth || 1920,
303
+ height: profileData.screenHeight || 1080,
304
+ device_scale_factor: profileData.devicePixelRatio || 1,
305
+ },
306
+ webglParams: profileData.webglParams || {},
307
+ webGpu: profileData.webGpu || {},
308
+ webgl_noice_enable: (profileData.webGL?.mode) === 'noise',
309
+ webglNoiceEnable: (profileData.webGL?.mode) === 'noise',
310
+ webgl_noise_enable: (profileData.webGL?.mode) === 'noise',
311
+ webgl_noise_value: profileData.webGL?.noise,
312
+ webglNoiseValue: profileData.webGL?.noise,
313
+ getClientRectsNoice: (profileData.clientRects?.noise) || (profileData.webGL?.getClientRectsNoise),
314
+ client_rects_noise_enable: (profileData.clientRects?.mode) === 'noise',
315
+ media_devices: {
316
+ enable: profileData.mediaDevices?.enableMasking,
317
+ uid: (profileData.mediaDevices?.uid) || '',
318
+ audioInputs: (profileData.mediaDevices?.audioInputs) || 1,
319
+ audioOutputs: (profileData.mediaDevices?.audioOutputs) || 1,
320
+ videoInputs: (profileData.mediaDevices?.videoInputs) || 1,
321
+ },
322
+ doNotTrack: (profileData.navigator?.doNotTrack) || false,
323
+ plugins: {
324
+ all_enable: profileData.plugins?.enableVulnerable,
325
+ flash_enable: profileData.plugins?.enableFlash,
326
+ },
327
+ storage: {
328
+ enable: profileData.storage?.local,
329
+ },
330
+ audioContext: {
331
+ enable: (profileData.audioContext?.mode) !== 'off',
332
+ noiseValue: (profileData.audioContext?.noise) || '',
333
+ },
334
+ canvas: {
335
+ mode: (profileData.canvas?.mode) || '',
336
+ },
337
+ languages: splittedLangs,
338
+ langHeader,
339
+ canvasMode: (profileData.canvas?.mode) || '',
340
+ canvasNoise: (profileData.canvas?.noise) || '',
341
+ deviceMemory: ((profileData.navigator?.deviceMemory) || 2) * 1024,
342
+ hardwareConcurrency: (profileData.navigator?.hardwareConcurrency) || 2,
343
+ startupUrl,
344
+ startup_urls: startupUrls,
345
+ geolocation: {
346
+ mode: (profileData.geolocation?.mode) || 'prompt',
347
+ latitude: parseFloat((this._tz && this._tz.ll && this._tz.ll[0]) || 0),
348
+ longitude: parseFloat((this._tz && this._tz.ll && this._tz.ll[1]) || 0),
349
+ accuracy: parseFloat((this._tz && this._tz.accuracy) || 0),
350
+ },
351
+ timezone: {
352
+ id: (this._tz && this._tz.timezone) || '',
353
+ },
312
354
  };
313
355
 
314
356
  return preferences;
@@ -420,6 +462,10 @@ export class GoLogin {
420
462
  await rimraf(profilePath, () => null);
421
463
  debug('-', profilePath, 'dropped');
422
464
  const profile = await this.getProfile();
465
+ if (!profile) {
466
+ throw new Error('Error fetching profile data');
467
+ }
468
+
423
469
  const { navigator = {}, fonts, os: profileOs } = profile;
424
470
  this.fontsMasking = fonts?.enableMasking;
425
471
  this.profileOs = profileOs;
@@ -461,7 +507,6 @@ export class GoLogin {
461
507
  const preferences_raw = await readFile(pref_file_name);
462
508
  const preferences = JSON.parse(preferences_raw.toString());
463
509
  let proxy = get(profile, 'proxy');
464
- const name = get(profile, 'name');
465
510
  const chromeExtensions = get(profile, 'chromeExtensions') || [];
466
511
  const userChromeExtensions = get(profile, 'userChromeExtensions') || [];
467
512
  const allExtensions = [...chromeExtensions, ...userChromeExtensions];
@@ -554,60 +599,7 @@ export class GoLogin {
554
599
  throw new Error(`Proxy Error. ${e.message}`);
555
600
  });
556
601
 
557
- const [latitude, longitude] = this._tz.ll;
558
- const { accuracy } = this._tz;
559
-
560
- const profileGeolocation = profile.geolocation;
561
- const tzGeoLocation = {
562
- latitude,
563
- longitude,
564
- accuracy,
565
- };
566
-
567
- profile.geoLocation = this.getGeolocationParams(profileGeolocation, tzGeoLocation);
568
- profile.name = name;
569
- profile.name_base64 = Buffer.from(name).toString('base64');
570
- profile.profile_id = this.profile_id;
571
-
572
- profile.webRtc = {
573
- mode: get(profile, 'webRTC.mode') === 'alerted' ? 'public' : get(profile, 'webRTC.mode'),
574
- publicIP: get(profile, 'webRTC.fillBasedOnIp') ? this._tz.ip : get(profile, 'webRTC.publicIp'),
575
- localIps: get(profile, 'webRTC.localIps', []),
576
- };
577
-
578
- debug('profile.webRtc=', profile.webRtc);
579
- debug('profile.timezone=', profile.timezone);
580
- debug('profile.mediaDevices=', profile.mediaDevices);
581
-
582
- const audioContext = profile.audioContext || {};
583
- const { mode: audioCtxMode = 'off', noise: audioCtxNoise } = audioContext;
584
- if (profile.timezone.fillBasedOnIp === false) {
585
- profile.timezone = { id: profile.timezone.timezone };
586
- } else {
587
- profile.timezone = { id: this._tz.timezone };
588
- }
589
-
590
- profile.webgl_noise_value = profile.webGL.noise;
591
- profile.get_client_rects_noise = profile.webGL.getClientRectsNoise;
592
- profile.canvasMode = profile.canvas.mode;
593
- profile.canvasNoise = profile.canvas.noise;
594
- profile.audioContext = {
595
- enable: audioCtxMode !== 'off',
596
- noiseValue: audioCtxNoise,
597
- };
598
- profile.webgl = {
599
- metadata: {
600
- vendor: get(profile, 'webGLMetadata.vendor'),
601
- renderer: get(profile, 'webGLMetadata.renderer'),
602
- mode: get(profile, 'webGLMetadata.mode') === 'mask',
603
- },
604
- };
605
-
606
- profile.custom_fonts = {
607
- enable: !!fonts?.enableMasking,
608
- };
609
-
610
- const gologin = this.convertPreferences(profile);
602
+ const gologin = this.getGologinPreferences(profile);
611
603
 
612
604
  debug(`Writing profile for screenWidth ${profilePath}`, JSON.stringify(gologin));
613
605
  gologin.screenWidth = this.resolution.width;
@@ -632,19 +624,10 @@ export class GoLogin {
632
624
  }
633
625
  }
634
626
 
635
- const languages = this.language.replace(/;|q=[\d\.]+/img, '');
636
-
637
627
  if (preferences.gologin == null) {
638
628
  preferences.gologin = {};
639
629
  }
640
630
 
641
- preferences.gologin.langHeader = gologin.navigator.language;
642
- preferences.gologin.language = languages;
643
-
644
- const [splittedLangs] = gologin.navigator.language.split(';');
645
- const [browserLang] = splittedLangs.split(',');
646
- gologin.browserLang = browserLang;
647
-
648
631
  const isMAC = OS_PLATFORM === 'darwin';
649
632
  const checkAutoLangResult = checkAutoLang(gologin, this._tz);
650
633
  this.browserLang = isMAC ? 'en-US' : checkAutoLangResult;
@@ -755,9 +738,9 @@ export class GoLogin {
755
738
 
756
739
  const proxyUrl = `${proxy.mode}://${proxy.username}:${proxy.password}@${proxy.host}:${proxy.port}`;
757
740
  debug(`getTimeZone start ${TIMEZONE_URL}`, proxyUrl);
758
- data = await requests.get(TIMEZONE_URL, { proxy: proxyUrl, timeout: 20 * 1000, maxAttempts: 5 });
741
+ data = await requests.get(TIMEZONE_URL, { proxy: proxyUrl, timeout: 13 * 1000, maxAttempts: 3 });
759
742
  } else {
760
- data = await requests.get(TIMEZONE_URL, { timeout: 20 * 1000, maxAttempts: 5 });
743
+ data = await requests.get(TIMEZONE_URL, { timeout: 13 * 1000, maxAttempts: 3 });
761
744
  }
762
745
 
763
746
  debug('getTimeZone finish', data.body);