gologin 2.1.2 → 2.1.4
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.
|
@@ -15,19 +15,12 @@ const [_execPath, _filePath, GOLOGIN_API_TOKEN, GOLOGIN_PROFILE_ID] = process.ar
|
|
|
15
15
|
profile_id: GOLOGIN_PROFILE_ID,
|
|
16
16
|
});
|
|
17
17
|
|
|
18
|
-
const { _status, wsUrl } = await GL.startRemote();
|
|
19
18
|
const browser = await puppeteer.connect({
|
|
20
|
-
browserWSEndpoint:
|
|
19
|
+
browserWSEndpoint: `https://cloudbrowser.gologin.com/connect?token=${GOLOGIN_API_TOKEN}&profile=${GOLOGIN_PROFILE_ID}`,
|
|
21
20
|
ignoreHTTPSErrors: true,
|
|
22
21
|
});
|
|
23
22
|
|
|
24
23
|
const page = await browser.newPage();
|
|
25
|
-
const viewPort = GL.getViewPort();
|
|
26
|
-
await page.setViewport({ width: Math.round(viewPort.width * 0.994), height: Math.round(viewPort.height * 0.92) });
|
|
27
|
-
const session = await page.target().createCDPSession();
|
|
28
|
-
const { windowId } = await session.send('Browser.getWindowForTarget');
|
|
29
|
-
await session.send('Browser.setWindowBounds', { windowId, bounds: viewPort });
|
|
30
|
-
await session.detach();
|
|
31
24
|
|
|
32
25
|
await page.goto('https://www.amazon.com/-/dp/B0771V1JZX');
|
|
33
26
|
const content = await page.content();
|
package/package.json
CHANGED
package/src/gologin.js
CHANGED
|
@@ -44,7 +44,6 @@ const delay = (time) => new Promise((resolve) => setTimeout(resolve, time));
|
|
|
44
44
|
export class GoLogin {
|
|
45
45
|
constructor(options = {}) {
|
|
46
46
|
this.browserLang = 'en-US';
|
|
47
|
-
this.is_remote = options.remote || false;
|
|
48
47
|
this.access_token = options.token;
|
|
49
48
|
this.profile_id = options.profile_id;
|
|
50
49
|
this.password = options.password;
|
|
@@ -59,7 +58,6 @@ export class GoLogin {
|
|
|
59
58
|
this.waitWebsocket = options.waitWebsocket ?? true;
|
|
60
59
|
|
|
61
60
|
this.isCloudHeadless = options.isCloudHeadless ?? true;
|
|
62
|
-
this.isNewCloudBrowser = options.isNewCloudBrowser ?? true;
|
|
63
61
|
|
|
64
62
|
this.tmpdir = tmpdir();
|
|
65
63
|
this.autoUpdateBrowser = !!options.autoUpdateBrowser;
|
|
@@ -427,9 +425,6 @@ export class GoLogin {
|
|
|
427
425
|
const prefFileExists = await access(pref_file_name).then(() => true).catch(() => false);
|
|
428
426
|
if (!prefFileExists) {
|
|
429
427
|
debug('Preferences file not exists waiting', pref_file_name, '. Using empty profile');
|
|
430
|
-
profile_folder = await this.emptyProfileFolder();
|
|
431
|
-
await writeFile(this.profile_zip_path, profile_folder);
|
|
432
|
-
await this.extractProfile(profilePath, this.profile_zip_path);
|
|
433
428
|
await writeFile(pref_file_name, '{}');
|
|
434
429
|
}
|
|
435
430
|
|
|
@@ -1372,10 +1367,6 @@ export class GoLogin {
|
|
|
1372
1367
|
}
|
|
1373
1368
|
|
|
1374
1369
|
async start() {
|
|
1375
|
-
if (this.is_remote) {
|
|
1376
|
-
return this.startRemote();
|
|
1377
|
-
}
|
|
1378
|
-
|
|
1379
1370
|
if (!this.executablePath) {
|
|
1380
1371
|
await this.checkBrowser();
|
|
1381
1372
|
}
|
|
@@ -1406,9 +1397,6 @@ export class GoLogin {
|
|
|
1406
1397
|
|
|
1407
1398
|
async stop() {
|
|
1408
1399
|
await new Promise(resolve => setTimeout(resolve, 500));
|
|
1409
|
-
if (this.is_remote) {
|
|
1410
|
-
return this.stopRemote();
|
|
1411
|
-
}
|
|
1412
1400
|
|
|
1413
1401
|
await this.stopAndCommit({ posting: true }, false);
|
|
1414
1402
|
}
|
|
@@ -1447,78 +1435,9 @@ export class GoLogin {
|
|
|
1447
1435
|
return wsUrl;
|
|
1448
1436
|
}
|
|
1449
1437
|
|
|
1450
|
-
async startRemote(delay_ms = 10000) {
|
|
1451
|
-
debug(`startRemote ${this.profile_id}`);
|
|
1452
|
-
|
|
1453
|
-
/*
|
|
1454
|
-
if (profileResponse.statusCode !== 202) {
|
|
1455
|
-
return {'status': 'failure', 'code': profileResponse.statusCode};
|
|
1456
|
-
}
|
|
1457
|
-
*/
|
|
1458
|
-
|
|
1459
|
-
const profile = await this.getProfile();
|
|
1460
|
-
const profileResponse = await requests.post(`${API_URL}/browser/${this.profile_id}/web`, {
|
|
1461
|
-
headers: { 'Authorization': `Bearer ${this.access_token}`, 'User-Agent': 'gologin-api' },
|
|
1462
|
-
json: { isNewCloudBrowser: this.isNewCloudBrowser, isHeadless: this.isCloudHeadless },
|
|
1463
|
-
}).catch(() => null);
|
|
1464
|
-
|
|
1465
|
-
if (!profileResponse) {
|
|
1466
|
-
throw new Error('invalid request');
|
|
1467
|
-
}
|
|
1468
|
-
|
|
1469
|
-
const { body, statusCode } = profileResponse;
|
|
1470
|
-
debug('profileResponse', statusCode, body);
|
|
1471
|
-
|
|
1472
|
-
if (profileResponse.statusCode === 401) {
|
|
1473
|
-
throw new Error('invalid token');
|
|
1474
|
-
}
|
|
1475
|
-
|
|
1476
|
-
if (body.status === 'profileStatuses.pending') {
|
|
1477
|
-
return { status: 'pending', message: 'remote browser is being prepared, please try in 1 minute.' };
|
|
1478
|
-
}
|
|
1479
|
-
|
|
1480
|
-
let remoteOrbitaUrl = `https://${this.profile_id}.orbita.gologin.com`;
|
|
1481
|
-
if (this.isNewCloudBrowser) {
|
|
1482
|
-
if (!profileResponse.body.remoteOrbitaUrl) {
|
|
1483
|
-
throw new Error('Couldn\' start the remote browser');
|
|
1484
|
-
}
|
|
1485
|
-
|
|
1486
|
-
remoteOrbitaUrl = profileResponse.body.remoteOrbitaUrl;
|
|
1487
|
-
}
|
|
1488
|
-
|
|
1489
|
-
const { navigator = {}, fonts, os: profileOs } = profile;
|
|
1490
|
-
this.fontsMasking = fonts?.enableMasking;
|
|
1491
|
-
this.profileOs = profileOs;
|
|
1492
|
-
this.differentOs =
|
|
1493
|
-
profileOs !== 'android' && (
|
|
1494
|
-
OS_PLATFORM === 'win32' && profileOs !== 'win' ||
|
|
1495
|
-
OS_PLATFORM === 'darwin' && profileOs !== 'mac' ||
|
|
1496
|
-
OS_PLATFORM === 'linux' && profileOs !== 'lin'
|
|
1497
|
-
);
|
|
1498
|
-
|
|
1499
|
-
const {
|
|
1500
|
-
resolution = '1920x1080',
|
|
1501
|
-
language = 'en-US,en;q=0.9',
|
|
1502
|
-
} = navigator;
|
|
1503
|
-
|
|
1504
|
-
this.language = language;
|
|
1505
|
-
const [screenWidth, screenHeight] = resolution.split('x');
|
|
1506
|
-
this.resolution = {
|
|
1507
|
-
width: parseInt(screenWidth, 10),
|
|
1508
|
-
height: parseInt(screenHeight, 10),
|
|
1509
|
-
};
|
|
1510
|
-
|
|
1511
|
-
const wsUrl = await this.waitDebuggingUrl(delay_ms, 0, remoteOrbitaUrl);
|
|
1512
|
-
if (wsUrl !== '') {
|
|
1513
|
-
return { status: 'success', wsUrl };
|
|
1514
|
-
}
|
|
1515
|
-
|
|
1516
|
-
return { status: 'failure', message: body };
|
|
1517
|
-
}
|
|
1518
|
-
|
|
1519
1438
|
async stopRemote() {
|
|
1520
1439
|
debug(`stopRemote ${this.profile_id}`);
|
|
1521
|
-
const profileResponse = await requests.delete(`${API_URL}/browser/${this.profile_id}/web
|
|
1440
|
+
const profileResponse = await requests.delete(`${API_URL}/browser/${this.profile_id}/web`, {
|
|
1522
1441
|
headers: {
|
|
1523
1442
|
'Authorization': `Bearer ${this.access_token}`,
|
|
1524
1443
|
'User-Agent': 'gologin-api',
|
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
// Usage example: in the terminal enter
|
|
2
|
-
// node example-startremote.js yU0token yU0Pr0f1leiD
|
|
3
|
-
|
|
4
|
-
// your token api (located in the settings, api)
|
|
5
|
-
// https://github.com/gologinapp/gologin#usage
|
|
6
|
-
import GoLogin from '../src/gologin.js';
|
|
7
|
-
|
|
8
|
-
const GOLOGIN_API_TOKEN = process.argv[2];
|
|
9
|
-
// your profile id
|
|
10
|
-
const GOLOGIN_PROFILE_ID = process.argv[3];
|
|
11
|
-
|
|
12
|
-
(async () => {
|
|
13
|
-
const GL = new GoLogin({
|
|
14
|
-
token: GOLOGIN_API_TOKEN,
|
|
15
|
-
profile_id: GOLOGIN_PROFILE_ID,
|
|
16
|
-
});
|
|
17
|
-
|
|
18
|
-
// connection of the remote work method
|
|
19
|
-
const { status, wsUrl } = await GL.startRemote();
|
|
20
|
-
|
|
21
|
-
const GOLOGIN_PROFILE_CLOUD_URL = wsUrl.split('/')[2];
|
|
22
|
-
console.log('Done! Launch web browser and navigate to URL:', GOLOGIN_PROFILE_CLOUD_URL);
|
|
23
|
-
})();
|
|
24
|
-
|
|
25
|
-
// after running the script, the url will appear on the terminal
|