gologin 1.0.28 → 1.0.32
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/README.md +1 -1
- package/browser-checker.js +26 -9
- package/examples/example-amazon-headless.js +4 -1
- package/gologin.js +160 -72
- package/package.json +3 -3
- package/selenium/gologin.py +1 -1
package/README.md
CHANGED
|
@@ -18,7 +18,7 @@ for running example.js install puppeteer-core
|
|
|
18
18
|
Where is token? API token is <a href="https://app.gologin.com/#/personalArea/TokenApi" target="_blank">here</a>.
|
|
19
19
|
To have an access to the page below you need <a href="https://app.gologin.com/#/createUser" target="_blank">register</a> GoLogin account.
|
|
20
20
|
|
|
21
|
-

|
|
22
22
|
|
|
23
23
|
### Example
|
|
24
24
|
|
package/browser-checker.js
CHANGED
|
@@ -260,7 +260,8 @@ class BrowserChecker {
|
|
|
260
260
|
async replaceBrowser() {
|
|
261
261
|
console.log('Copy Orbita to target path');
|
|
262
262
|
if (PLATFORM === 'darwin') {
|
|
263
|
-
await
|
|
263
|
+
await this.deleteDir(path.join(this.#browserPath, 'Orbita-Browser.app'));
|
|
264
|
+
|
|
264
265
|
const files = await readdir(path.join(this.#browserPath, EXTRACTED_FOLDER));
|
|
265
266
|
const promises = [];
|
|
266
267
|
files.forEach((filename) => {
|
|
@@ -268,22 +269,25 @@ class BrowserChecker {
|
|
|
268
269
|
promises.push(copyFile(path.join(this.#browserPath, EXTRACTED_FOLDER, filename), path.join(this.#browserPath, filename)));
|
|
269
270
|
}
|
|
270
271
|
});
|
|
272
|
+
|
|
271
273
|
return Promise.all(promises);
|
|
272
|
-
} else {
|
|
273
|
-
await rmdir(path.join(this.#browserPath, 'orbita-browser'), { recursive: true });
|
|
274
|
-
await this.copyDir(
|
|
275
|
-
path.join(this.#browserPath, EXTRACTED_FOLDER, 'orbita-browser'),
|
|
276
|
-
path.join(this.#browserPath, 'orbita-browser')
|
|
277
|
-
);
|
|
278
274
|
}
|
|
275
|
+
|
|
276
|
+
const targetBrowserPath = path.join(this.#browserPath, 'orbita-browser');
|
|
277
|
+
await this.deleteDir(targetBrowserPath);
|
|
278
|
+
|
|
279
|
+
await this.copyDir(
|
|
280
|
+
path.join(this.#browserPath, EXTRACTED_FOLDER, 'orbita-browser'),
|
|
281
|
+
targetBrowserPath
|
|
282
|
+
);
|
|
279
283
|
}
|
|
280
284
|
|
|
281
285
|
async deleteOldArchives(deleteCurrentBrowser = false) {
|
|
282
286
|
if (deleteCurrentBrowser) {
|
|
283
|
-
return
|
|
287
|
+
return this.deleteDir(path.join(this.#browserPath));
|
|
284
288
|
}
|
|
285
289
|
|
|
286
|
-
await
|
|
290
|
+
await this.deleteDir(path.join(this.#browserPath, EXTRACTED_FOLDER));
|
|
287
291
|
return readdir(this.#browserPath)
|
|
288
292
|
.then((files) => {
|
|
289
293
|
const promises = [];
|
|
@@ -355,6 +359,19 @@ class BrowserChecker {
|
|
|
355
359
|
get getOrbitaPath() {
|
|
356
360
|
return this.#executableFilePath;
|
|
357
361
|
}
|
|
362
|
+
|
|
363
|
+
async deleteDir(path = '') {
|
|
364
|
+
if (!path) {
|
|
365
|
+
return;
|
|
366
|
+
}
|
|
367
|
+
|
|
368
|
+
const directoryExists = await access(path).then(() => true).catch(() => false);
|
|
369
|
+
if (!directoryExists) {
|
|
370
|
+
return;
|
|
371
|
+
}
|
|
372
|
+
|
|
373
|
+
return rmdir(path, { recursive: true });
|
|
374
|
+
}
|
|
358
375
|
}
|
|
359
376
|
|
|
360
377
|
module.exports = BrowserChecker;
|
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
const puppeteer = require('puppeteer-core');
|
|
2
2
|
const GoLogin = require('../gologin');
|
|
3
3
|
|
|
4
|
-
(
|
|
4
|
+
const delay = (time) => new Promise((resolve) => setTimeout(resolve, time));
|
|
5
|
+
|
|
6
|
+
(async () =>{
|
|
5
7
|
const GL = new GoLogin({
|
|
6
8
|
token: 'yU0token',
|
|
7
9
|
profile_id: 'yU0Pr0f1leiD',
|
|
@@ -14,6 +16,7 @@ const GoLogin = require('../gologin');
|
|
|
14
16
|
});
|
|
15
17
|
|
|
16
18
|
const page = await browser.newPage();
|
|
19
|
+
await delay(300);
|
|
17
20
|
|
|
18
21
|
const viewPort = GL.getViewPort();
|
|
19
22
|
await page.setViewport({ width: Math.round(viewPort.width * 0.994), height: Math.round(viewPort.height * 0.92) });
|
package/gologin.js
CHANGED
|
@@ -5,6 +5,7 @@ const fs = require('fs');
|
|
|
5
5
|
const os = require('os');
|
|
6
6
|
const util = require('util');
|
|
7
7
|
const rimraf = util.promisify(require('rimraf'));
|
|
8
|
+
const { access, unlink, writeFile, readFile } = require('fs').promises;
|
|
8
9
|
const exec = util.promisify(require('child_process').exec);
|
|
9
10
|
const { spawn, execFile } = require('child_process');
|
|
10
11
|
const FormData = require('form-data');
|
|
@@ -12,7 +13,7 @@ const ProxyAgent = require('simple-proxy-agent');
|
|
|
12
13
|
const decompress = require('decompress');
|
|
13
14
|
const decompressUnzip = require('decompress-unzip');
|
|
14
15
|
const path = require('path');
|
|
15
|
-
const
|
|
16
|
+
const zipdir = require('zip-dir');
|
|
16
17
|
|
|
17
18
|
const BrowserChecker = require('./browser-checker');
|
|
18
19
|
const { BrowserUserDataManager } = require('./browser-user-data-manager');
|
|
@@ -54,7 +55,7 @@ class GoLogin {
|
|
|
54
55
|
this.tmpdir = options.tmpdir;
|
|
55
56
|
if (!fs.existsSync(this.tmpdir)) {
|
|
56
57
|
debug('making tmpdir', this.tmpdir);
|
|
57
|
-
|
|
58
|
+
fs.mkdirSync(this.tmpdir, { recursive: true })
|
|
58
59
|
}
|
|
59
60
|
}
|
|
60
61
|
|
|
@@ -127,7 +128,7 @@ class GoLogin {
|
|
|
127
128
|
throw new Error(`Gologin /browser/${id} response error ${profileResponse.statusCode} INVALID TOKEN OR PROFILE NOT FOUND`);
|
|
128
129
|
}
|
|
129
130
|
|
|
130
|
-
if(profileResponse.statusCode
|
|
131
|
+
if (profileResponse.statusCode === 401) {
|
|
131
132
|
throw new Error("invalid token");
|
|
132
133
|
}
|
|
133
134
|
|
|
@@ -135,12 +136,13 @@ class GoLogin {
|
|
|
135
136
|
}
|
|
136
137
|
|
|
137
138
|
async emptyProfile() {
|
|
138
|
-
|
|
139
|
+
return readFile(path.resolve(__dirname, 'gologin_zeroprofile.b64')).then(res => res.toString());
|
|
139
140
|
}
|
|
140
141
|
|
|
141
142
|
async getProfileS3(s3path) {
|
|
142
143
|
const token = this.access_token;
|
|
143
144
|
debug('getProfileS3 token=', token, 'profile=', this.profile_id, 's3path=', s3path);
|
|
145
|
+
|
|
144
146
|
if (s3path) { //загрузка профиля из публичного бакета s3 быстрее
|
|
145
147
|
const s3url = `https://gprofiles.gologin.com/${s3path}`.replace(/\s+/mg, '+');
|
|
146
148
|
debug('loading profile from public s3 bucket, url=', s3url);
|
|
@@ -151,6 +153,7 @@ class GoLogin {
|
|
|
151
153
|
debug(`Gologin S3 BUCKET ${s3url} response error ${profileResponse.statusCode} - use empty`);
|
|
152
154
|
return '';
|
|
153
155
|
}
|
|
156
|
+
|
|
154
157
|
return Buffer.from(profileResponse.body);
|
|
155
158
|
}
|
|
156
159
|
|
|
@@ -161,15 +164,33 @@ class GoLogin {
|
|
|
161
164
|
},
|
|
162
165
|
encoding: null
|
|
163
166
|
});
|
|
167
|
+
|
|
164
168
|
if (profileResponse.statusCode !== 200) {
|
|
165
169
|
debug(`Gologin /browser/${this.profile_id} response error ${profileResponse.statusCode} - use empty`);
|
|
166
170
|
return '';
|
|
167
171
|
}
|
|
172
|
+
|
|
168
173
|
return Buffer.from(profileResponse.body);
|
|
169
174
|
}
|
|
170
175
|
|
|
171
176
|
async postFile(fileName, fileBody) {
|
|
172
177
|
debug('POSTING FILE', fileBody.length);
|
|
178
|
+
debug('Getting signed URL for S3');
|
|
179
|
+
const apiUrl = `${API_URL}/browser/${this.profile_id}/storage-signature`;
|
|
180
|
+
|
|
181
|
+
const signedUrl = await requests.get(apiUrl, {
|
|
182
|
+
headers: {
|
|
183
|
+
Authorization: `Bearer ${this.access_token}`,
|
|
184
|
+
'user-agent': 'gologin-api',
|
|
185
|
+
},
|
|
186
|
+
maxAttempts: 3,
|
|
187
|
+
retryDelay: 2000,
|
|
188
|
+
timeout: 10 * 1000,
|
|
189
|
+
fullResponse: false,
|
|
190
|
+
});
|
|
191
|
+
|
|
192
|
+
const [uploadedProfileUrl] = signedUrl.split('?');
|
|
193
|
+
|
|
173
194
|
const fd = new FormData();
|
|
174
195
|
const boundary = fd.getBoundary();
|
|
175
196
|
const body = Buffer.concat([
|
|
@@ -186,26 +207,44 @@ class GoLogin {
|
|
|
186
207
|
Buffer.from('--'),
|
|
187
208
|
Buffer.from('\r\n')
|
|
188
209
|
]);
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
210
|
+
|
|
211
|
+
console.log('Uploading profile by signed URL to S3');
|
|
212
|
+
const bodyBufferBiteLength = Buffer.byteLength(body);
|
|
213
|
+
console.log('BUFFER SIZE', bodyBufferBiteLength);
|
|
214
|
+
|
|
215
|
+
await requests.put(signedUrl, {
|
|
216
|
+
headers: {
|
|
217
|
+
'Content-Type': 'application/zip',
|
|
218
|
+
'Content-Length': bodyBufferBiteLength,
|
|
219
|
+
},
|
|
220
|
+
body,
|
|
221
|
+
maxBodyLength: Infinity,
|
|
222
|
+
maxContentLength: Infinity,
|
|
223
|
+
maxAttempts: 3,
|
|
224
|
+
retryDelay: 2000,
|
|
225
|
+
timeout: 30 * 1000,
|
|
226
|
+
fullResponse: false,
|
|
227
|
+
});
|
|
228
|
+
|
|
229
|
+
const uploadedProfileMetadata = await requests.head(uploadedProfileUrl, {
|
|
230
|
+
maxAttempts: 3,
|
|
231
|
+
retryDelay: 2000,
|
|
232
|
+
timeout: 10 * 1000,
|
|
233
|
+
fullResponse: true,
|
|
203
234
|
});
|
|
235
|
+
|
|
236
|
+
const uploadedFileLength = +uploadedProfileMetadata.headers['content-length'];
|
|
237
|
+
if (uploadedFileLength !== bodyBufferBiteLength) {
|
|
238
|
+
console.log('Uploaded file is incorrect. Retry with China File size:', uploadedFileLength);
|
|
239
|
+
throw new Error('Uploaded file is incorrect. Retry with China File size: ' + uploadedFileLength);
|
|
240
|
+
}
|
|
241
|
+
|
|
242
|
+
console.log('Profile has been uploaded to S3 successfully');
|
|
204
243
|
}
|
|
205
244
|
|
|
206
245
|
async emptyProfileFolder() {
|
|
207
246
|
debug('get emptyProfileFolder');
|
|
208
|
-
const profile =
|
|
247
|
+
const profile = await readFile(path.resolve(__dirname, 'gologin_zeroprofile.zip'));
|
|
209
248
|
debug('emptyProfileFolder LENGTH ::', profile.length);
|
|
210
249
|
return profile;
|
|
211
250
|
}
|
|
@@ -246,9 +285,8 @@ class GoLogin {
|
|
|
246
285
|
.then(() => {
|
|
247
286
|
debug('extraction done');
|
|
248
287
|
debug('create uid.json');
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
return extPath;
|
|
288
|
+
return writeFile(path.join(extPath, 'uid.json'), JSON.stringify({ uid: that.profile_id }, null, 2))
|
|
289
|
+
.then(() => extPath);
|
|
252
290
|
})
|
|
253
291
|
.catch(async (e) => {
|
|
254
292
|
debug('orbita extension error', e);
|
|
@@ -299,7 +337,8 @@ class GoLogin {
|
|
|
299
337
|
height: parseInt(screenHeight, 10),
|
|
300
338
|
};
|
|
301
339
|
|
|
302
|
-
|
|
340
|
+
const profileZipExists = await access(this.profile_zip_path).then(() => true).catch(() => false);
|
|
341
|
+
if (!(local && profileZipExists)) {
|
|
303
342
|
try {
|
|
304
343
|
profile_folder = await this.getProfileS3(_.get(profile, 's3Path', ''));
|
|
305
344
|
}
|
|
@@ -310,8 +349,8 @@ class GoLogin {
|
|
|
310
349
|
if (!profile_folder.length) {
|
|
311
350
|
profile_folder = await this.emptyProfileFolder();
|
|
312
351
|
}
|
|
313
|
-
|
|
314
|
-
|
|
352
|
+
|
|
353
|
+
await writeFile(this.profile_zip_path, profile_folder);
|
|
315
354
|
|
|
316
355
|
debug('PROFILE LENGTH', profile_folder.length);
|
|
317
356
|
} else {
|
|
@@ -323,20 +362,23 @@ class GoLogin {
|
|
|
323
362
|
await this.extractProfile(profilePath, this.profile_zip_path);
|
|
324
363
|
debug('extraction done');
|
|
325
364
|
|
|
326
|
-
|
|
365
|
+
const singletonLockPath = path.join(profilePath, 'SingletonLock');
|
|
366
|
+
const singletonLockExists = await access(singletonLockPath).then(() => true).catch(() => false);
|
|
367
|
+
if (singletonLockExists) {
|
|
327
368
|
debug('removing SingletonLock');
|
|
328
|
-
|
|
369
|
+
await unlink(singletonLockPath);
|
|
329
370
|
debug('SingletonLock removed');
|
|
330
371
|
}
|
|
331
372
|
|
|
332
373
|
const pref_file_name = path.join(profilePath, 'Default', 'Preferences');
|
|
333
374
|
debug('reading', pref_file_name);
|
|
334
375
|
|
|
335
|
-
|
|
376
|
+
const prefFileExists = await access(pref_file_name).then(() => true).catch(() => false);
|
|
377
|
+
if (!prefFileExists) {
|
|
336
378
|
debug('Preferences file not exists waiting', pref_file_name);
|
|
337
379
|
}
|
|
338
380
|
|
|
339
|
-
const preferences_raw =
|
|
381
|
+
const preferences_raw = await readFile(pref_file_name);
|
|
340
382
|
let preferences = JSON.parse(preferences_raw.toString());
|
|
341
383
|
let proxy = _.get(profile, 'proxy');
|
|
342
384
|
let name = _.get(profile, 'name');
|
|
@@ -359,6 +401,11 @@ class GoLogin {
|
|
|
359
401
|
profile.proxy.password = _.get(profile, 'autoProxyPassword');
|
|
360
402
|
}
|
|
361
403
|
// console.log('proxy=', proxy);
|
|
404
|
+
|
|
405
|
+
if (proxy.mode === 'geolocation') {
|
|
406
|
+
proxy.mode = 'http';
|
|
407
|
+
}
|
|
408
|
+
|
|
362
409
|
if (proxy.mode === 'none') {
|
|
363
410
|
proxy = null;
|
|
364
411
|
}
|
|
@@ -386,6 +433,8 @@ class GoLogin {
|
|
|
386
433
|
publicIP: _.get(profile, 'webRTC.fillBasedOnIp') ? this._tz.ip : _.get(profile, 'webRTC.publicIp'),
|
|
387
434
|
localIps: _.get(profile, 'webRTC.localIps', []),
|
|
388
435
|
};
|
|
436
|
+
|
|
437
|
+
debug('profile.webRtc=', profile.webRtc);
|
|
389
438
|
|
|
390
439
|
const audioContext = profile.audioContext || {};
|
|
391
440
|
const { mode: audioCtxMode = 'off', noise: audioCtxNoise } = audioContext;
|
|
@@ -429,7 +478,7 @@ class GoLogin {
|
|
|
429
478
|
await BrowserUserDataManager.composeFonts(families, profilePath, this.differentOs);
|
|
430
479
|
}
|
|
431
480
|
|
|
432
|
-
|
|
481
|
+
await writeFile(path.join(profilePath, 'Default', 'Preferences'), JSON.stringify(_.merge(preferences, {
|
|
433
482
|
gologin
|
|
434
483
|
})));
|
|
435
484
|
|
|
@@ -443,12 +492,14 @@ class GoLogin {
|
|
|
443
492
|
|
|
444
493
|
async commitProfile() {
|
|
445
494
|
const data = await this.getProfileDataToUpdate();
|
|
495
|
+
|
|
446
496
|
debug('begin updating', data.length);
|
|
447
497
|
if (!data.length) {
|
|
448
498
|
debug('WARN: profile zip data empty - SKIPPING PROFILE COMMIT');
|
|
449
499
|
|
|
450
500
|
return;
|
|
451
501
|
}
|
|
502
|
+
|
|
452
503
|
try {
|
|
453
504
|
debug('Patching profile');
|
|
454
505
|
await this.postFile('profile', data);
|
|
@@ -456,6 +507,7 @@ class GoLogin {
|
|
|
456
507
|
catch (e) {
|
|
457
508
|
debug('CANNOT COMMIT PROFILE', e);
|
|
458
509
|
}
|
|
510
|
+
|
|
459
511
|
debug('COMMIT COMPLETED');
|
|
460
512
|
}
|
|
461
513
|
|
|
@@ -475,16 +527,16 @@ class GoLogin {
|
|
|
475
527
|
|
|
476
528
|
async checkPortAvailable(port) {
|
|
477
529
|
debug('CHECKING PORT AVAILABLE', port);
|
|
530
|
+
|
|
478
531
|
try {
|
|
479
532
|
const { stdout, stderr } = await exec(`lsof -i:${port}`);
|
|
480
|
-
if (
|
|
481
|
-
stdout && stdout.match(/LISTEN/gmi)
|
|
482
|
-
) {
|
|
533
|
+
if (stdout && stdout.match(/LISTEN/gmi)) {
|
|
483
534
|
debug(`PORT ${port} IS BUSY`)
|
|
484
535
|
return false;
|
|
485
536
|
}
|
|
486
|
-
} catch (e) {
|
|
537
|
+
} catch (e) {}
|
|
487
538
|
debug(`PORT ${port} IS OPEN`);
|
|
539
|
+
|
|
488
540
|
return true;
|
|
489
541
|
}
|
|
490
542
|
|
|
@@ -499,23 +551,24 @@ class GoLogin {
|
|
|
499
551
|
}
|
|
500
552
|
|
|
501
553
|
async getTimeZone(proxy) {
|
|
502
|
-
|
|
554
|
+
debug('getting timeZone proxy=', proxy);
|
|
555
|
+
if (this.timezone) {
|
|
503
556
|
debug('getTimeZone from options', this.timezone);
|
|
504
557
|
this._tz = this.timezone;
|
|
505
558
|
return this._tz.timezone;
|
|
506
559
|
}
|
|
507
560
|
|
|
508
561
|
let data = null;
|
|
509
|
-
if (proxy) {
|
|
562
|
+
if (proxy!==null && proxy.mode !== "none") {
|
|
510
563
|
if (proxy.mode.includes('socks')) {
|
|
511
564
|
return this.getTimezoneWithSocks(proxy);
|
|
512
565
|
}
|
|
513
566
|
|
|
514
567
|
const proxyUrl = `${proxy.mode}://${proxy.username}:${proxy.password}@${proxy.host}:${proxy.port}`;
|
|
515
568
|
debug('getTimeZone start https://time.gologin.com', proxyUrl);
|
|
516
|
-
data = await requests.get('https://time.gologin.com', { proxy: proxyUrl, timeout:
|
|
569
|
+
data = await requests.get('https://time.gologin.com', { proxy: proxyUrl, timeout: 20 * 1000, maxAttempts: 5 });
|
|
517
570
|
} else {
|
|
518
|
-
data = await requests.get('https://time.gologin.com', { timeout:
|
|
571
|
+
data = await requests.get('https://time.gologin.com', { timeout: 20 * 1000, maxAttempts: 5 });
|
|
519
572
|
}
|
|
520
573
|
debug('getTimeZone finish', data.body);
|
|
521
574
|
this._tz = JSON.parse(data.body);
|
|
@@ -563,7 +616,6 @@ class GoLogin {
|
|
|
563
616
|
}
|
|
564
617
|
debug('getTimeZone finish', body.body);
|
|
565
618
|
this._tz = body;
|
|
566
|
-
|
|
567
619
|
return this._tz.timezone;
|
|
568
620
|
}
|
|
569
621
|
|
|
@@ -597,7 +649,7 @@ class GoLogin {
|
|
|
597
649
|
|
|
598
650
|
async spawnBrowser() {
|
|
599
651
|
let remote_debugging_port = this.remote_debugging_port;
|
|
600
|
-
if(!remote_debugging_port){
|
|
652
|
+
if (!remote_debugging_port) {
|
|
601
653
|
remote_debugging_port = await this.getRandomPort();
|
|
602
654
|
}
|
|
603
655
|
|
|
@@ -699,7 +751,9 @@ class GoLogin {
|
|
|
699
751
|
if (this.is_stopping) {
|
|
700
752
|
return true;
|
|
701
753
|
}
|
|
702
|
-
const is_posting = options.
|
|
754
|
+
const is_posting = options.posting ||
|
|
755
|
+
options.postings || // backward compability
|
|
756
|
+
false;
|
|
703
757
|
|
|
704
758
|
if (this.uploadCookiesToServer) {
|
|
705
759
|
await this.uploadProfileCookiesToServer();
|
|
@@ -775,34 +829,39 @@ class GoLogin {
|
|
|
775
829
|
|
|
776
830
|
async getProfileDataToUpdate() {
|
|
777
831
|
const zipPath = path.join(this.tmpdir, `gologin_${this.profile_id}_upload.zip`);
|
|
778
|
-
|
|
779
|
-
|
|
780
|
-
|
|
781
|
-
catch (e) {
|
|
832
|
+
const zipExists = await access(zipPath).then(() => true).catch(() => false);
|
|
833
|
+
if (zipExists) {
|
|
834
|
+
await unlink(zipPath);
|
|
782
835
|
}
|
|
836
|
+
|
|
783
837
|
await this.sanitizeProfile();
|
|
784
838
|
debug('profile sanitized');
|
|
785
|
-
|
|
786
|
-
|
|
787
|
-
|
|
788
|
-
|
|
789
|
-
|
|
790
|
-
|
|
791
|
-
|
|
792
|
-
|
|
793
|
-
|
|
794
|
-
|
|
795
|
-
|
|
796
|
-
|
|
797
|
-
|
|
839
|
+
|
|
840
|
+
const profilePath = this.profilePath();
|
|
841
|
+
await new Promise((resolve, reject) => zipdir(profilePath,
|
|
842
|
+
{
|
|
843
|
+
saveTo: zipPath,
|
|
844
|
+
filter: (path) => !/RunningChromeVersion/.test(path),
|
|
845
|
+
}, (err, buffer) => {
|
|
846
|
+
if (err) {
|
|
847
|
+
reject(err);
|
|
848
|
+
return;
|
|
849
|
+
}
|
|
850
|
+
|
|
851
|
+
resolve(buffer);
|
|
852
|
+
})
|
|
853
|
+
)
|
|
854
|
+
|
|
855
|
+
debug('PROFILE ZIP CREATED', profilePath, zipPath);
|
|
856
|
+
|
|
857
|
+
let data = '';
|
|
798
858
|
try {
|
|
799
|
-
|
|
800
|
-
|
|
801
|
-
}
|
|
802
|
-
catch (e) {
|
|
859
|
+
data = await readFile(zipPath);
|
|
860
|
+
} catch (e) {
|
|
803
861
|
debug('saveprofile error', e);
|
|
804
|
-
return '';
|
|
805
862
|
}
|
|
863
|
+
|
|
864
|
+
return data;
|
|
806
865
|
}
|
|
807
866
|
|
|
808
867
|
async profileExists() {
|
|
@@ -846,11 +905,11 @@ class GoLogin {
|
|
|
846
905
|
const fingerprint = await this.getRandomFingerprint(options);
|
|
847
906
|
debug("fingerprint=", fingerprint)
|
|
848
907
|
|
|
849
|
-
if(fingerprint.statusCode
|
|
908
|
+
if (fingerprint.statusCode === 500) {
|
|
850
909
|
throw new Error("no valid random fingerprint check os param");
|
|
851
910
|
}
|
|
852
911
|
|
|
853
|
-
if(fingerprint.statusCode
|
|
912
|
+
if (fingerprint.statusCode === 401) {
|
|
854
913
|
throw new Error("invalid token");
|
|
855
914
|
}
|
|
856
915
|
|
|
@@ -880,7 +939,7 @@ class GoLogin {
|
|
|
880
939
|
let user_agent = options.navigator?.userAgent;
|
|
881
940
|
let orig_user_agent = json.navigator.userAgent;
|
|
882
941
|
Object.keys(options).map((e)=>{ json[e] = options[e] });
|
|
883
|
-
if(user_agent
|
|
942
|
+
if (user_agent === 'random') {
|
|
884
943
|
json.navigator.userAgent = orig_user_agent;
|
|
885
944
|
}
|
|
886
945
|
// console.log('profileOptions', json);
|
|
@@ -893,11 +952,11 @@ class GoLogin {
|
|
|
893
952
|
json,
|
|
894
953
|
});
|
|
895
954
|
|
|
896
|
-
if(response.body.statusCode
|
|
955
|
+
if (response.body.statusCode === 400) {
|
|
897
956
|
throw new Error(`gologin failed account creation with status code, ${data.statusCode} DATA ${JSON.stringify(response.body.message)}`);
|
|
898
957
|
}
|
|
899
958
|
|
|
900
|
-
if(response.body.statusCode
|
|
959
|
+
if (response.body.statusCode === 500) {
|
|
901
960
|
throw new Error(`gologin failed account creation with status code, ${data.statusCode}`);
|
|
902
961
|
}
|
|
903
962
|
debug(JSON.stringify(response.body));
|
|
@@ -1035,6 +1094,13 @@ class GoLogin {
|
|
|
1035
1094
|
if (!this.executablePath) {
|
|
1036
1095
|
await this.checkBrowser();
|
|
1037
1096
|
}
|
|
1097
|
+
|
|
1098
|
+
const ORBITA_BROWSER = this.executablePath || this.browserChecker.getOrbitaPath;
|
|
1099
|
+
|
|
1100
|
+
const orbitaBrowserExists = await access(ORBITA_BROWSER).then(() => true).catch(() => false);
|
|
1101
|
+
if (!orbitaBrowserExists) {
|
|
1102
|
+
throw new Error(`Orbita browser is not exists on path ${ORBITA_BROWSER}, check executablePath param`);
|
|
1103
|
+
}
|
|
1038
1104
|
|
|
1039
1105
|
await this.createStartup();
|
|
1040
1106
|
// await this.createBrowserExtension();
|
|
@@ -1058,12 +1124,12 @@ class GoLogin {
|
|
|
1058
1124
|
return this.stopRemote();
|
|
1059
1125
|
}
|
|
1060
1126
|
|
|
1061
|
-
await this.stopAndCommit({ posting:
|
|
1127
|
+
await this.stopAndCommit({ posting: true }, false);
|
|
1062
1128
|
}
|
|
1063
1129
|
|
|
1064
1130
|
async stopLocal(options) {
|
|
1065
1131
|
const opts = options || { posting: false };
|
|
1066
|
-
await this.stopAndCommit(
|
|
1132
|
+
await this.stopAndCommit(opts, true);
|
|
1067
1133
|
}
|
|
1068
1134
|
|
|
1069
1135
|
async waitDebuggingUrl(delay_ms, try_count=0) {
|
|
@@ -1085,7 +1151,7 @@ class GoLogin {
|
|
|
1085
1151
|
if (try_count < 3) {
|
|
1086
1152
|
return this.waitDebuggingUrl(delay_ms, try_count+1);
|
|
1087
1153
|
}
|
|
1088
|
-
return { 'status': 'failure', wsUrl }
|
|
1154
|
+
return { 'status': 'failure', wsUrl, 'message': 'Check proxy settings', 'profile_id': this.profile_id }
|
|
1089
1155
|
}
|
|
1090
1156
|
|
|
1091
1157
|
wsUrl = wsUrl.replace('ws://', `wss://`).replace('127.0.0.1', `${this.profile_id}.orbita.gologin.com`)
|
|
@@ -1100,7 +1166,7 @@ class GoLogin {
|
|
|
1100
1166
|
}
|
|
1101
1167
|
});
|
|
1102
1168
|
|
|
1103
|
-
if(profileResponse.statusCode
|
|
1169
|
+
if (profileResponse.statusCode === 401){
|
|
1104
1170
|
throw new Error("invalid token");
|
|
1105
1171
|
}
|
|
1106
1172
|
|
|
@@ -1110,6 +1176,28 @@ class GoLogin {
|
|
|
1110
1176
|
}
|
|
1111
1177
|
|
|
1112
1178
|
if (profileResponse.body === 'ok') {
|
|
1179
|
+
const profile = await this.getProfile();
|
|
1180
|
+
const { navigator = {}, fonts, os: profileOs } = profile;
|
|
1181
|
+
this.fontsMasking = fonts?.enableMasking;
|
|
1182
|
+
this.profileOs = profileOs;
|
|
1183
|
+
this.differentOs =
|
|
1184
|
+
profileOs !== 'android' && (
|
|
1185
|
+
OS_PLATFORM === 'win32' && profileOs !== 'win' ||
|
|
1186
|
+
OS_PLATFORM === 'darwin' && profileOs !== 'mac' ||
|
|
1187
|
+
OS_PLATFORM === 'linux' && profileOs !== 'lin'
|
|
1188
|
+
);
|
|
1189
|
+
|
|
1190
|
+
const {
|
|
1191
|
+
resolution = '1920x1080',
|
|
1192
|
+
language = 'en-US,en;q=0.9',
|
|
1193
|
+
} = navigator;
|
|
1194
|
+
this.language = language;
|
|
1195
|
+
const [screenWidth, screenHeight] = resolution.split('x');
|
|
1196
|
+
this.resolution = {
|
|
1197
|
+
width: parseInt(screenWidth, 10),
|
|
1198
|
+
height: parseInt(screenHeight, 10),
|
|
1199
|
+
};
|
|
1200
|
+
|
|
1113
1201
|
let wsUrl = await this.waitDebuggingUrl(delay_ms);
|
|
1114
1202
|
return { 'status': 'success', wsUrl }
|
|
1115
1203
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "gologin",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.32",
|
|
4
4
|
"description": "A high-level API to control Orbita browser over GoLogin API",
|
|
5
5
|
"main": "./gologin.js",
|
|
6
6
|
"repository": {
|
|
@@ -26,10 +26,10 @@
|
|
|
26
26
|
"requestretry": "^4.1.0",
|
|
27
27
|
"rimraf": "^3.0.2",
|
|
28
28
|
"selenium-webdriver": "^4.0.0-alpha.7",
|
|
29
|
-
"shelljs": "^0.8.4",
|
|
30
29
|
"simple-proxy-agent": "^1.1.0",
|
|
31
30
|
"sqlite": "^4.0.23",
|
|
32
|
-
"sqlite3": "^5.0.2"
|
|
31
|
+
"sqlite3": "^5.0.2",
|
|
32
|
+
"zip-dir": "^2.0.0"
|
|
33
33
|
},
|
|
34
34
|
"bugs": {
|
|
35
35
|
"url": "https://github.com/gologinapp/gologin/issues"
|
package/selenium/gologin.py
CHANGED
|
@@ -45,7 +45,7 @@ class GoLogin(object):
|
|
|
45
45
|
proxy = self.proxy
|
|
46
46
|
proxy_host = ''
|
|
47
47
|
if proxy:
|
|
48
|
-
if proxy.get('mode')==None:
|
|
48
|
+
if proxy.get('mode')==None or proxy.get('mode')=='geolocation':
|
|
49
49
|
proxy['mode'] = 'http'
|
|
50
50
|
proxy_host = proxy.get('host')
|
|
51
51
|
proxy = self.formatProxyUrl(proxy)
|