gologin 2.1.14 → 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.
- package/examples/example-cloud.js +17 -0
- package/examples/example-iphey.js +1 -1
- package/package.json +1 -1
- package/src/gologin-api.js +15 -8
- package/src/gologin.js +106 -123
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { exitAll, GologinApi } from '../src/gologin-api.js';
|
|
2
|
+
|
|
3
|
+
const token = process.env.GOLOGIN_API_TOKEN; // get token https://app.gologin.com/personalArea/TokenApi
|
|
4
|
+
const gologin = GologinApi({ token });
|
|
5
|
+
|
|
6
|
+
async function main() {
|
|
7
|
+
const { browser } = await gologin.launch({ cloud: true });
|
|
8
|
+
const page = await browser.newPage();
|
|
9
|
+
await page.goto('https://iphey.com/', { waitUntil: 'networkidle2' });
|
|
10
|
+
const status = await page.$eval('.trustworthy:not(.hide)', (elt) =>
|
|
11
|
+
elt?.innerText?.trim(),
|
|
12
|
+
);
|
|
13
|
+
|
|
14
|
+
return status; // Expecting 'Trustworthy'
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
main().catch(console.error).then(console.info).finally(exitAll);
|
|
@@ -7,7 +7,7 @@ async function main() {
|
|
|
7
7
|
const { browser } = await gologin.launch();
|
|
8
8
|
const page = await browser.newPage();
|
|
9
9
|
await page.goto('https://iphey.com/', { waitUntil: 'networkidle2' });
|
|
10
|
-
const status = await page.$eval('.trustworthy
|
|
10
|
+
const status = await page.$eval('.trustworthy:not(.hide)', (elt) =>
|
|
11
11
|
elt?.innerText?.trim(),
|
|
12
12
|
);
|
|
13
13
|
|
package/package.json
CHANGED
package/src/gologin-api.js
CHANGED
|
@@ -61,15 +61,20 @@ export function GologinApi({ token }) {
|
|
|
61
61
|
};
|
|
62
62
|
|
|
63
63
|
const launchCloudProfile = async (params) => {
|
|
64
|
-
const
|
|
65
|
-
|
|
66
|
-
|
|
64
|
+
const legacyGologin = createLegacyGologin({
|
|
65
|
+
...params,
|
|
66
|
+
token,
|
|
67
|
+
});
|
|
68
|
+
|
|
69
|
+
if (!params.profileId) {
|
|
70
|
+
const { id } = await legacyGologin.quickCreateProfile();
|
|
71
|
+
await legacyGologin.setProfileId(id);
|
|
72
|
+
params.profileId = id;
|
|
73
|
+
}
|
|
67
74
|
|
|
68
|
-
|
|
69
|
-
? `&geolocation=${params.geolocation}`
|
|
70
|
-
: '';
|
|
75
|
+
legacyGls.push(legacyGologin);
|
|
71
76
|
|
|
72
|
-
const browserWSEndpoint = `https://
|
|
77
|
+
const browserWSEndpoint = `https://cloudbrowser.gologin.com/connect?token=${token}&profile=${params.profileId}`;
|
|
73
78
|
const browser = await puppeteer.connect({
|
|
74
79
|
browserWSEndpoint,
|
|
75
80
|
ignoreHTTPSErrors: true,
|
|
@@ -94,7 +99,9 @@ export function GologinApi({ token }) {
|
|
|
94
99
|
Promise.allSettled(
|
|
95
100
|
legacyGls.map((gl) => gl.stopLocal({ posting: false })),
|
|
96
101
|
);
|
|
97
|
-
|
|
102
|
+
Promise.allSettled(
|
|
103
|
+
legacyGls.map((gl) => gl.stopRemote({ posting: true })),
|
|
104
|
+
);
|
|
98
105
|
},
|
|
99
106
|
|
|
100
107
|
delay,
|
package/src/gologin.js
CHANGED
|
@@ -252,63 +252,105 @@ export class GoLogin {
|
|
|
252
252
|
return profile;
|
|
253
253
|
}
|
|
254
254
|
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
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
|
|
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:
|
|
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:
|
|
743
|
+
data = await requests.get(TIMEZONE_URL, { timeout: 13 * 1000, maxAttempts: 3 });
|
|
761
744
|
}
|
|
762
745
|
|
|
763
746
|
debug('getTimeZone finish', data.body);
|