gologin 2.1.13 → 2.1.15
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 +33 -4
|
@@ -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
|
@@ -63,6 +63,7 @@ export class GoLogin {
|
|
|
63
63
|
this.isEmptyFonts = false;
|
|
64
64
|
this.isFirstSession = false;
|
|
65
65
|
this.isCloudHeadless = options.isCloudHeadless ?? true;
|
|
66
|
+
this.storageGatewayUrl = `${STORAGE_GATEWAY_BASE_URL}/upload`;
|
|
66
67
|
|
|
67
68
|
this.tmpdir = tmpdir();
|
|
68
69
|
this.autoUpdateBrowser = !!options.autoUpdateBrowser;
|
|
@@ -218,12 +219,11 @@ export class GoLogin {
|
|
|
218
219
|
async postFile(fileName, fileBuff) {
|
|
219
220
|
debug('POSTING FILE', fileBuff.length);
|
|
220
221
|
debug('Getting signed URL for S3');
|
|
221
|
-
const apiUrl = `${STORAGE_GATEWAY_BASE_URL}/upload`;
|
|
222
222
|
|
|
223
223
|
const bodyBufferBiteLength = Buffer.byteLength(fileBuff);
|
|
224
224
|
console.log('BUFFER SIZE', bodyBufferBiteLength);
|
|
225
225
|
|
|
226
|
-
await requests.put(
|
|
226
|
+
await requests.put(this.storageGatewayUrl, {
|
|
227
227
|
headers: {
|
|
228
228
|
Authorization: `Bearer ${this.access_token}`,
|
|
229
229
|
browserId: this.profile_id,
|
|
@@ -976,14 +976,14 @@ export class GoLogin {
|
|
|
976
976
|
false;
|
|
977
977
|
|
|
978
978
|
if (this.uploadCookiesToServer) {
|
|
979
|
-
await this.
|
|
979
|
+
const updateResult = await this.uploadProfileDataToServer();
|
|
980
|
+
this.storageGatewayUrl = updateResult.storageGateway.url;
|
|
980
981
|
}
|
|
981
982
|
|
|
982
983
|
this.is_stopping = true;
|
|
983
984
|
await this.sanitizeProfile();
|
|
984
985
|
|
|
985
986
|
if (is_posting) {
|
|
986
|
-
await this.saveBookmarksToDb();
|
|
987
987
|
await this.commitProfile();
|
|
988
988
|
}
|
|
989
989
|
|
|
@@ -1001,6 +1001,35 @@ export class GoLogin {
|
|
|
1001
1001
|
return false;
|
|
1002
1002
|
}
|
|
1003
1003
|
|
|
1004
|
+
async uploadProfileDataToServer() {
|
|
1005
|
+
const cookies = await loadCookiesFromFile(this.cookiesFilePath);
|
|
1006
|
+
const bookmarks = await getCurrentProfileBookmarks(this.bookmarksFilePath);
|
|
1007
|
+
|
|
1008
|
+
const body = {
|
|
1009
|
+
cookies,
|
|
1010
|
+
bookmarks,
|
|
1011
|
+
isCookiesEncrypted: true,
|
|
1012
|
+
isStorageGateway: true,
|
|
1013
|
+
};
|
|
1014
|
+
|
|
1015
|
+
const updateResult = await requests.post(`${API_URL}/browser/features/profile/${this.profile_id}/update_after_close`, {
|
|
1016
|
+
headers: {
|
|
1017
|
+
Authorization: `Bearer ${this.access_token}`,
|
|
1018
|
+
'User-Agent': 'gologin-api',
|
|
1019
|
+
},
|
|
1020
|
+
json: body,
|
|
1021
|
+
maxAttempts: 3,
|
|
1022
|
+
retryDelay: 2000,
|
|
1023
|
+
timeout: 20 * 1000,
|
|
1024
|
+
}).catch((e) => {
|
|
1025
|
+
console.log(e);
|
|
1026
|
+
|
|
1027
|
+
return e;
|
|
1028
|
+
});
|
|
1029
|
+
|
|
1030
|
+
return updateResult.body;
|
|
1031
|
+
}
|
|
1032
|
+
|
|
1004
1033
|
async stopBrowser() {
|
|
1005
1034
|
if (!this.port) {
|
|
1006
1035
|
throw new Error('Empty GoLogin port');
|