gologin 1.0.47 → 1.0.50
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/gologin.js +59 -43
- package/package.json +1 -1
package/gologin.js
CHANGED
|
@@ -60,16 +60,16 @@ class GoLogin {
|
|
|
60
60
|
}
|
|
61
61
|
}
|
|
62
62
|
|
|
63
|
-
this.cookiesFilePath = path.join(this.tmpdir, `gologin_profile_${this.profile_id}`, 'Default', 'Cookies');
|
|
63
|
+
this.cookiesFilePath = path.join(this.tmpdir, `gologin_profile_${this.profile_id}`, 'Default', 'Network', 'Cookies');
|
|
64
64
|
this.profile_zip_path = path.join(this.tmpdir, `gologin_${this.profile_id}.zip`);
|
|
65
65
|
debug('INIT GOLOGIN', this.profile_id);
|
|
66
66
|
}
|
|
67
|
-
|
|
67
|
+
|
|
68
68
|
async checkBrowser() { return this.browserChecker.checkBrowser(this.autoUpdateBrowser) }
|
|
69
69
|
|
|
70
70
|
async setProfileId(profile_id) {
|
|
71
71
|
this.profile_id = profile_id;
|
|
72
|
-
this.cookiesFilePath = path.join(this.tmpdir, `gologin_profile_${this.profile_id}`, 'Default', 'Cookies');
|
|
72
|
+
this.cookiesFilePath = path.join(this.tmpdir, `gologin_profile_${this.profile_id}`, 'Default', 'Network', 'Cookies');
|
|
73
73
|
this.profile_zip_path = path.join(this.tmpdir, `gologin_${this.profile_id}.zip`);
|
|
74
74
|
}
|
|
75
75
|
|
|
@@ -125,15 +125,15 @@ class GoLogin {
|
|
|
125
125
|
}
|
|
126
126
|
})
|
|
127
127
|
debug("profileResponse", profileResponse.statusCode, profileResponse.body);
|
|
128
|
-
|
|
129
|
-
|
|
128
|
+
|
|
129
|
+
|
|
130
130
|
if (profileResponse.statusCode === 404) {
|
|
131
131
|
throw new Error(JSON.parse(profileResponse.body).message);
|
|
132
|
-
}
|
|
132
|
+
}
|
|
133
133
|
|
|
134
134
|
if (profileResponse.statusCode === 403) {
|
|
135
135
|
throw new Error(JSON.parse(profileResponse.body).message);
|
|
136
|
-
}
|
|
136
|
+
}
|
|
137
137
|
|
|
138
138
|
if (profileResponse.statusCode !== 200) {
|
|
139
139
|
throw new Error(`Gologin /browser/${id} response error ${profileResponse.statusCode} INVALID TOKEN OR PROFILE NOT FOUND`);
|
|
@@ -141,7 +141,7 @@ class GoLogin {
|
|
|
141
141
|
|
|
142
142
|
if (profileResponse.statusCode === 401) {
|
|
143
143
|
throw new Error("invalid token");
|
|
144
|
-
}
|
|
144
|
+
}
|
|
145
145
|
|
|
146
146
|
|
|
147
147
|
return JSON.parse(profileResponse.body);
|
|
@@ -255,14 +255,30 @@ class GoLogin {
|
|
|
255
255
|
if (_.get(preferences, 'isM1')) {
|
|
256
256
|
preferences.is_m1 = _.get(preferences, 'isM1');
|
|
257
257
|
}
|
|
258
|
-
|
|
258
|
+
|
|
259
|
+
if (_.get(preferences, 'os') == 'android'){
|
|
260
|
+
const devicePixelRatio = _.get(preferences, "devicePixelRatio");
|
|
261
|
+
const deviceScaleFactorCeil = Math.ceil(devicePixelRatio || 3.5);
|
|
262
|
+
let deviceScaleFactor = devicePixelRatio;
|
|
263
|
+
if (deviceScaleFactorCeil === devicePixelRatio) {
|
|
264
|
+
deviceScaleFactor += 0.00000001;
|
|
265
|
+
}
|
|
266
|
+
|
|
267
|
+
preferences.mobile = {
|
|
268
|
+
enable: true,
|
|
269
|
+
width: parseInt(this.resolution.width, 10),
|
|
270
|
+
height: parseInt(this.resolution.height, 10),
|
|
271
|
+
device_scale_factor: deviceScaleFactor,
|
|
272
|
+
}
|
|
273
|
+
}
|
|
274
|
+
|
|
259
275
|
preferences.mediaDevices = {
|
|
260
276
|
enable: preferences.mediaDevices.enableMasking,
|
|
261
277
|
videoInputs: preferences.mediaDevices.videoInputs,
|
|
262
278
|
audioInputs: preferences.mediaDevices.audioInputs,
|
|
263
279
|
audioOutputs: preferences.mediaDevices.audioOutputs,
|
|
264
280
|
}
|
|
265
|
-
|
|
281
|
+
|
|
266
282
|
return preferences;
|
|
267
283
|
}
|
|
268
284
|
|
|
@@ -290,7 +306,7 @@ class GoLogin {
|
|
|
290
306
|
});
|
|
291
307
|
|
|
292
308
|
debug('createBrowserExtension done');
|
|
293
|
-
}
|
|
309
|
+
}
|
|
294
310
|
|
|
295
311
|
extractProfile(path, zipfile) {
|
|
296
312
|
debug(`extactProfile ${zipfile}, ${path}`);
|
|
@@ -359,7 +375,7 @@ class GoLogin {
|
|
|
359
375
|
} catch(e) {
|
|
360
376
|
console.trace(e);
|
|
361
377
|
profile_folder = await this.emptyProfileFolder();
|
|
362
|
-
await writeFile(this.profile_zip_path, profile_folder);
|
|
378
|
+
await writeFile(this.profile_zip_path, profile_folder);
|
|
363
379
|
await this.extractProfile(profilePath, this.profile_zip_path);
|
|
364
380
|
}
|
|
365
381
|
|
|
@@ -378,12 +394,12 @@ class GoLogin {
|
|
|
378
394
|
if (!prefFileExists) {
|
|
379
395
|
debug('Preferences file not exists waiting', pref_file_name, '. Using empty profile');
|
|
380
396
|
profile_folder = await this.emptyProfileFolder();
|
|
381
|
-
await writeFile(this.profile_zip_path, profile_folder);
|
|
397
|
+
await writeFile(this.profile_zip_path, profile_folder);
|
|
382
398
|
await this.extractProfile(profilePath, this.profile_zip_path);
|
|
383
399
|
}
|
|
384
400
|
|
|
385
401
|
const preferences_raw = await readFile(pref_file_name);
|
|
386
|
-
let preferences = JSON.parse(preferences_raw.toString());
|
|
402
|
+
let preferences = JSON.parse(preferences_raw.toString());
|
|
387
403
|
let proxy = _.get(profile, 'proxy');
|
|
388
404
|
let name = _.get(profile, 'name');
|
|
389
405
|
const chromeExtensions = _.get(profile, 'chromeExtensions');
|
|
@@ -437,7 +453,7 @@ class GoLogin {
|
|
|
437
453
|
'username': _.get(profile, 'autoProxyUsername'),
|
|
438
454
|
'password': _.get(profile, 'autoProxyPassword'),
|
|
439
455
|
}
|
|
440
|
-
|
|
456
|
+
|
|
441
457
|
profile.proxy.username = _.get(profile, 'autoProxyUsername');
|
|
442
458
|
profile.proxy.password = _.get(profile, 'autoProxyPassword');
|
|
443
459
|
}
|
|
@@ -474,7 +490,7 @@ class GoLogin {
|
|
|
474
490
|
publicIP: _.get(profile, 'webRTC.fillBasedOnIp') ? this._tz.ip : _.get(profile, 'webRTC.publicIp'),
|
|
475
491
|
localIps: _.get(profile, 'webRTC.localIps', []),
|
|
476
492
|
};
|
|
477
|
-
|
|
493
|
+
|
|
478
494
|
debug('profile.webRtc=', profile.webRtc);
|
|
479
495
|
debug('profile.timezone=', profile.timezone);
|
|
480
496
|
debug('profile.mediaDevices=', profile.mediaDevices);
|
|
@@ -530,11 +546,11 @@ class GoLogin {
|
|
|
530
546
|
}
|
|
531
547
|
|
|
532
548
|
const [languages] = this.language.split(';');
|
|
533
|
-
|
|
549
|
+
|
|
534
550
|
if(preferences.gologin==null){
|
|
535
551
|
preferences.gologin = {};
|
|
536
552
|
}
|
|
537
|
-
|
|
553
|
+
|
|
538
554
|
preferences.gologin.langHeader = gologin.language;
|
|
539
555
|
preferences.gologin.languages = languages;
|
|
540
556
|
// debug("convertedPreferences=", preferences.gologin)
|
|
@@ -689,7 +705,7 @@ class GoLogin {
|
|
|
689
705
|
|
|
690
706
|
async spawnArguments() {
|
|
691
707
|
const profile_path = this.profilePath();
|
|
692
|
-
|
|
708
|
+
|
|
693
709
|
let proxy = this.proxy;
|
|
694
710
|
proxy = `${proxy.mode}://${proxy.host}:${proxy.port}`;
|
|
695
711
|
|
|
@@ -719,10 +735,10 @@ class GoLogin {
|
|
|
719
735
|
let remote_debugging_port = this.remote_debugging_port;
|
|
720
736
|
if (!remote_debugging_port) {
|
|
721
737
|
remote_debugging_port = await this.getRandomPort();
|
|
722
|
-
}
|
|
723
|
-
|
|
738
|
+
}
|
|
739
|
+
|
|
724
740
|
const profile_path = this.profilePath();
|
|
725
|
-
|
|
741
|
+
|
|
726
742
|
let proxy = this.proxy;
|
|
727
743
|
let proxy_host = '';
|
|
728
744
|
if (proxy) {
|
|
@@ -731,9 +747,9 @@ class GoLogin {
|
|
|
731
747
|
}
|
|
732
748
|
|
|
733
749
|
this.port = remote_debugging_port;
|
|
734
|
-
|
|
750
|
+
|
|
735
751
|
const ORBITA_BROWSER = this.executablePath || this.browserChecker.getOrbitaPath;
|
|
736
|
-
|
|
752
|
+
debug(`ORBITA_BROWSER=${ORBITA_BROWSER}`)
|
|
737
753
|
const env = {};
|
|
738
754
|
Object.keys(process.env).forEach((key) => {
|
|
739
755
|
env[key] = process.env[key];
|
|
@@ -761,8 +777,8 @@ class GoLogin {
|
|
|
761
777
|
|
|
762
778
|
let params = [
|
|
763
779
|
`--remote-debugging-port=${remote_debugging_port}`,
|
|
764
|
-
`--user-data-dir=${profile_path}`,
|
|
765
|
-
`--password-store=basic`,
|
|
780
|
+
`--user-data-dir=${profile_path}`,
|
|
781
|
+
`--password-store=basic`,
|
|
766
782
|
`--tz=${tz}`,
|
|
767
783
|
`--lang=${browserLang}`,
|
|
768
784
|
];
|
|
@@ -808,13 +824,13 @@ class GoLogin {
|
|
|
808
824
|
const child = execFile(ORBITA_BROWSER, params, {env});
|
|
809
825
|
// const child = spawn(ORBITA_BROWSER, params, { env, shell: true });
|
|
810
826
|
child.stdout.on('data', (data) => debug(data.toString()));
|
|
811
|
-
debug('SPAWN CMD', ORBITA_BROWSER, params.join(" "));
|
|
827
|
+
debug('SPAWN CMD', ORBITA_BROWSER, params.join(" "));
|
|
812
828
|
}
|
|
813
829
|
|
|
814
830
|
debug('GETTING WS URL FROM BROWSER');
|
|
815
831
|
|
|
816
832
|
let data = await requests.get(`http://127.0.0.1:${remote_debugging_port}/json/version`, {json: true});
|
|
817
|
-
|
|
833
|
+
|
|
818
834
|
debug('WS IS', _.get(data, 'body.webSocketDebuggerUrl', ''))
|
|
819
835
|
this.is_active = true;
|
|
820
836
|
|
|
@@ -857,7 +873,7 @@ class GoLogin {
|
|
|
857
873
|
|
|
858
874
|
if (!local) {
|
|
859
875
|
await rimraf(path.join(this.tmpdir, `gologin_${this.profile_id}.zip`));
|
|
860
|
-
}
|
|
876
|
+
}
|
|
861
877
|
debug(`PROFILE ${this.profile_id} STOPPED AND CLEAR`);
|
|
862
878
|
return false;
|
|
863
879
|
}
|
|
@@ -867,7 +883,7 @@ class GoLogin {
|
|
|
867
883
|
if (!this.port) {
|
|
868
884
|
throw new Error('Empty GoLogin port');
|
|
869
885
|
}
|
|
870
|
-
const ls = await spawn('fuser',
|
|
886
|
+
const ls = await spawn('fuser',
|
|
871
887
|
[
|
|
872
888
|
'-k TERM',
|
|
873
889
|
`-n tcp ${this.port}`
|
|
@@ -902,7 +918,7 @@ class GoLogin {
|
|
|
902
918
|
await Promise.all(remove_dirs.map(d => {
|
|
903
919
|
const path_to_remove = `${that.profilePath()}${d}`
|
|
904
920
|
return new Promise(resolve => {
|
|
905
|
-
debug('DROPPING', path_to_remove);
|
|
921
|
+
debug('DROPPING', path_to_remove);
|
|
906
922
|
rimraf(path_to_remove, { maxBusyTries: 100 }, (e) => {
|
|
907
923
|
// debug('DROPPING RESULT', e);
|
|
908
924
|
resolve();
|
|
@@ -954,7 +970,7 @@ class GoLogin {
|
|
|
954
970
|
return false;
|
|
955
971
|
}
|
|
956
972
|
debug('profile is', profileResponse.body);
|
|
957
|
-
return true;
|
|
973
|
+
return true;
|
|
958
974
|
}
|
|
959
975
|
|
|
960
976
|
|
|
@@ -963,16 +979,16 @@ class GoLogin {
|
|
|
963
979
|
|
|
964
980
|
if (options.os) {
|
|
965
981
|
os = options.os;
|
|
966
|
-
}
|
|
982
|
+
}
|
|
967
983
|
|
|
968
984
|
let fingerprint = await requests.get(`${API_URL}/browser/fingerprint?os=${os}`,{
|
|
969
985
|
headers: {
|
|
970
986
|
'Authorization': `Bearer ${this.access_token}`,
|
|
971
987
|
'User-Agent': 'gologin-api',
|
|
972
988
|
}
|
|
973
|
-
});
|
|
989
|
+
});
|
|
974
990
|
|
|
975
|
-
return JSON.parse(fingerprint.body);
|
|
991
|
+
return JSON.parse(fingerprint.body);
|
|
976
992
|
}
|
|
977
993
|
|
|
978
994
|
async create(options) {
|
|
@@ -980,7 +996,7 @@ class GoLogin {
|
|
|
980
996
|
|
|
981
997
|
const fingerprint = await this.getRandomFingerprint(options);
|
|
982
998
|
debug("fingerprint=", fingerprint)
|
|
983
|
-
|
|
999
|
+
|
|
984
1000
|
if (fingerprint.statusCode === 500) {
|
|
985
1001
|
throw new Error("no valid random fingerprint check os param");
|
|
986
1002
|
}
|
|
@@ -1052,7 +1068,7 @@ class GoLogin {
|
|
|
1052
1068
|
async update(options) {
|
|
1053
1069
|
this.profile_id = options.id;
|
|
1054
1070
|
const profile = await this.getProfile();
|
|
1055
|
-
|
|
1071
|
+
|
|
1056
1072
|
if (options.navigator) {
|
|
1057
1073
|
Object.keys(options.navigator).map((e)=>{profile.navigator[e]=options.navigator[e]});
|
|
1058
1074
|
}
|
|
@@ -1065,7 +1081,7 @@ class GoLogin {
|
|
|
1065
1081
|
headers: {
|
|
1066
1082
|
'Authorization': `Bearer ${this.access_token}`
|
|
1067
1083
|
}
|
|
1068
|
-
});
|
|
1084
|
+
});
|
|
1069
1085
|
debug('response', JSON.stringify(response.body));
|
|
1070
1086
|
return response.body
|
|
1071
1087
|
}
|
|
@@ -1090,7 +1106,7 @@ class GoLogin {
|
|
|
1090
1106
|
accuracy: profileGeolocationParams.accuracy,
|
|
1091
1107
|
}
|
|
1092
1108
|
};
|
|
1093
|
-
|
|
1109
|
+
|
|
1094
1110
|
getViewPort() {
|
|
1095
1111
|
return { ...this.resolution };
|
|
1096
1112
|
};
|
|
@@ -1170,7 +1186,7 @@ class GoLogin {
|
|
|
1170
1186
|
if (!this.executablePath) {
|
|
1171
1187
|
await this.checkBrowser();
|
|
1172
1188
|
}
|
|
1173
|
-
|
|
1189
|
+
|
|
1174
1190
|
const ORBITA_BROWSER = this.executablePath || this.browserChecker.getOrbitaPath;
|
|
1175
1191
|
|
|
1176
1192
|
const orbitaBrowserExists = await access(ORBITA_BROWSER).then(() => true).catch(() => false);
|
|
@@ -1242,7 +1258,7 @@ class GoLogin {
|
|
|
1242
1258
|
return {'status': 'failure', 'code': profileResponse.statusCode};
|
|
1243
1259
|
}
|
|
1244
1260
|
*/
|
|
1245
|
-
|
|
1261
|
+
|
|
1246
1262
|
// if (profileResponse.body === 'ok') {
|
|
1247
1263
|
const profile = await this.getProfile();
|
|
1248
1264
|
|
|
@@ -1251,7 +1267,7 @@ class GoLogin {
|
|
|
1251
1267
|
'Authorization': `Bearer ${this.access_token}`
|
|
1252
1268
|
}
|
|
1253
1269
|
});
|
|
1254
|
-
|
|
1270
|
+
|
|
1255
1271
|
debug('profileResponse', profileResponse.statusCode, profileResponse.body);
|
|
1256
1272
|
|
|
1257
1273
|
if (profileResponse.statusCode === 401){
|
|
@@ -1282,7 +1298,7 @@ class GoLogin {
|
|
|
1282
1298
|
let wsUrl = await this.waitDebuggingUrl(delay_ms);
|
|
1283
1299
|
if(wsUrl!=''){
|
|
1284
1300
|
return { 'status': 'success', wsUrl }
|
|
1285
|
-
}
|
|
1301
|
+
}
|
|
1286
1302
|
|
|
1287
1303
|
return { 'status': 'failure', 'message': profileResponse.body };
|
|
1288
1304
|
}
|