gologin 2.1.21 → 2.1.23

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.
@@ -4,11 +4,13 @@ import request from 'requestretry';
4
4
 
5
5
  import { CHROME_EXTENSIONS_PATH, composeExtractionPromises, USER_EXTENSIONS_PATH } from '../utils/common.js';
6
6
  import UserExtensionsManager from './user-extensions-manager.js';
7
+ import { makeRequest } from '../utils/http.js';
8
+ import { FALLBACK_API_URL } from '../utils/common.js';
7
9
 
8
10
  const { mkdir, readdir, rmdir, unlink } = _promises;
9
11
 
10
12
  const EXTENSION_URL =
11
- 'https://clients2.google.com/service/update2/crx?response=redirect&acceptformat=crx2,crx3&x=id%3D{ext_id}%26uc&prodversion=97.0.4692.71';
13
+ 'https://clients2.google.com/service/update2/crx?response=redirect&acceptformat=crx2,crx3&x=id%3D{ext_id}%26uc&prodversion=135.0.7049.41';
12
14
 
13
15
  export class ExtensionsManager extends UserExtensionsManager {
14
16
  #existedChromeExtensions = [];
@@ -134,6 +136,7 @@ export class ExtensionsManager extends UserExtensionsManager {
134
136
 
135
137
  const buffer = await new Promise((res) => {
136
138
  const chunks = [];
139
+ console.log('extUrl', extUrl);
137
140
  request.get(extUrl, {
138
141
  maxAttempts: 3,
139
142
  retryDelay: 1000,
@@ -143,7 +146,7 @@ export class ExtensionsManager extends UserExtensionsManager {
143
146
  .on('data', (data) => chunks.push(data))
144
147
  .on('end', () => res(Buffer.concat(chunks)));
145
148
  });
146
-
149
+ console.log('buffer', buffer);
147
150
  let zipExt;
148
151
  try {
149
152
  zipExt = crxToZip(buffer);
@@ -166,17 +169,15 @@ export class ExtensionsManager extends UserExtensionsManager {
166
169
  }
167
170
 
168
171
  async getExtensionsPolicies() {
169
- const globalExtConfig = await request.get(`${this.apiBaseUrl}/gologin-settings/chrome_ext_policies`, {
170
- headers: {
171
- Authorization: `Bearer ${this.accessToken}`,
172
- 'user-agent': this.userAgent,
173
- 'x-two-factor-token': this.twoFaKey || '',
174
- },
172
+ const globalExtConfig = await makeRequest(`${this.apiBaseUrl}/gologin-settings/chrome_ext_policies`, {
175
173
  json: true,
176
174
  maxAttempts: 2,
177
175
  retryDelay: 1000,
178
176
  timeout: 10 * 1000,
179
- fullResponse: false,
177
+ method: 'GET',
178
+ }, {
179
+ token: this.accessToken,
180
+ fallbackUrl: `${FALLBACK_API_URL}/gologin-settings/chrome_ext_policies`,
180
181
  });
181
182
 
182
183
  const chromeExtPolicies = globalExtConfig?.chromeExtPolicies || {};
@@ -260,20 +261,17 @@ export class ExtensionsManager extends UserExtensionsManager {
260
261
  return;
261
262
  }
262
263
 
263
- const checkResponse = await request(`${this.apiBaseUrl}/extensions/check`, {
264
+ const checkResponse = await makeRequest(`${this.apiBaseUrl}/extensions/check`, {
264
265
  method: 'POST',
265
- headers: {
266
- Authorization: `Bearer ${this.accessToken}`,
267
- 'user-agent': this.userAgent,
268
- 'x-two-factor-token': this.twoFaKey || '',
269
- },
270
- body: {
266
+ json: {
271
267
  extensionsIds,
272
268
  },
273
- json: true,
269
+ }, {
270
+ token: this.accessToken,
271
+ fallbackUrl: `${FALLBACK_API_URL}/extensions/check`,
274
272
  });
275
273
 
276
- const { extensionsToAdd = [] } = checkResponse.body;
274
+ const { extensionsToAdd = [] } = checkResponse;
277
275
 
278
276
  if (!extensionsToAdd.length) {
279
277
  return;
@@ -281,17 +279,14 @@ export class ExtensionsManager extends UserExtensionsManager {
281
279
 
282
280
  const extensionsToUpdate = await this.getExtensionsNameAndImage(extensionsToAdd, pathToExtensions);
283
281
 
284
- request(`${this.apiBaseUrl}/extensions/create`, {
282
+ makeRequest(`${this.apiBaseUrl}/extensions/create`, {
285
283
  method: 'POST',
286
- headers: {
287
- Authorization: `Bearer ${this.accessToken}`,
288
- 'user-agent': this.userAgent,
289
- 'x-two-factor-token': this.twoFaKey || '',
290
- },
291
- body: {
284
+ json: {
292
285
  extensionsInfo: extensionsToUpdate,
293
286
  },
294
- json: true,
287
+ }, {
288
+ token: this.accessToken,
289
+ fallbackUrl: `${FALLBACK_API_URL}/extensions/create`,
295
290
  });
296
291
  }
297
292
 
@@ -78,19 +78,17 @@ export class UserExtensionsManager {
78
78
  return;
79
79
  }
80
80
 
81
- const extensionsToDownloadPaths = await request.post(`${this.#API_BASE_URL}/extensions/user_chrome_extensions_paths`, {
82
- json: true,
81
+ const extensionsToDownloadPaths = await makeRequest(`${this.#API_BASE_URL}/extensions/user_chrome_extensions_paths`, {
83
82
  fullResponse: false,
84
- headers: {
85
- Authorization: `Bearer ${this.#ACCESS_TOKEN}`,
86
- 'user-agent': this.#USER_AGENT,
87
- 'x-two-factor-token': this.#TWO_FA_KEY || '',
88
- },
89
- body: {
83
+ json: {
90
84
  existedUserChromeExtensions: this.#existedUserExtensions,
91
85
  profileId,
92
86
  userChromeExtensions,
93
87
  },
88
+ method: 'POST',
89
+ }, {
90
+ token: this.#ACCESS_TOKEN,
91
+ fallbackUrl: `${FALLBACK_API_URL}/extensions/user_chrome_extensions_paths`,
94
92
  }) || [];
95
93
 
96
94
  const extensionsToDownloadPathsFiltered =
@@ -1,7 +1,8 @@
1
1
  import puppeteer from 'puppeteer-core';
2
2
 
3
3
  import GoLogin from './gologin.js';
4
- import { API_URL, getOsAdvanced } from './utils/common.js';
4
+ import { API_URL, FALLBACK_API_URL, getOsAdvanced } from './utils/common.js';
5
+ import { makeRequest } from './utils/http.js';
5
6
 
6
7
  const trafficLimitMessage =
7
8
  'You dont have free traffic to use the proxy. Please go to app https://app.gologin.com/ and buy some traffic if you want to use the proxy';
@@ -10,11 +11,9 @@ export const getDefaultParams = () => ({
10
11
  token: process.env.GOLOGIN_API_TOKEN,
11
12
  profile_id: process.env.GOLOGIN_PROFILE_ID,
12
13
  executablePath: process.env.GOLOGIN_EXECUTABLE_PATH,
13
- autoUpdateBrowser: true,
14
14
  });
15
15
 
16
16
  const createGologinProfileManager = ({ profileId, ...params }) => {
17
- console.log({ params });
18
17
  const defaults = getDefaultParams();
19
18
  const mergedParams = {
20
19
  ...defaults,
@@ -23,8 +22,6 @@ const createGologinProfileManager = ({ profileId, ...params }) => {
23
22
 
24
23
  mergedParams.profile_id = profileId ?? mergedParams.profile_id;
25
24
 
26
- console.log({ mergedParams });
27
-
28
25
  return new GoLogin(mergedParams);
29
26
  };
30
27
 
@@ -50,9 +47,11 @@ export const GologinApi = ({ token }) => {
50
47
  }
51
48
 
52
49
  const startedProfile = await legacyGologin.start();
50
+
53
51
  const browser = await puppeteer.connect({
54
52
  browserWSEndpoint: startedProfile.wsUrl,
55
53
  ignoreHTTPSErrors: true,
54
+ defaultViewport: null,
56
55
  });
57
56
 
58
57
  browsers.push(browser);
@@ -88,7 +87,6 @@ export const GologinApi = ({ token }) => {
88
87
 
89
88
  const api = {
90
89
  async launch(params = {}) {
91
- console.log();
92
90
  if (params.cloud) {
93
91
  return launchCloudProfile(params);
94
92
  }
@@ -97,26 +95,12 @@ export const GologinApi = ({ token }) => {
97
95
  },
98
96
 
99
97
  async createProfileWithCustomParams(options) {
100
- const response = await fetch(`${API_URL}/browser/custom`, {
98
+ const response = await makeRequest(`${API_URL}/browser/custom`, {
101
99
  method: 'POST',
102
- headers: {
103
- 'Authorization': `Bearer ${token}`,
104
- 'User-Agent': 'gologin-api',
105
- },
106
- body: JSON.stringify(options),
107
- });
108
-
109
- if (response.status === 400) {
110
- throw new Error(`gologin failed account creation with status code, ${response.status} DATA ${JSON.stringify(await response.json())}`);
111
- }
100
+ json: options,
101
+ }, { token, fallbackUrl: `${FALLBACK_API_URL}/browser/custom` });
112
102
 
113
- if (response.status === 500) {
114
- throw new Error(`gologin failed account creation with status code, ${response.status}`);
115
- }
116
-
117
- const profile = await response.json();
118
-
119
- return profile.id;
103
+ return response.id;
120
104
  },
121
105
 
122
106
  async refreshProfilesFingerprint(profileIds) {
@@ -124,17 +108,12 @@ export const GologinApi = ({ token }) => {
124
108
  throw new Error('Profile ID is required');
125
109
  }
126
110
 
127
- const response = await fetch(`${API_URL}/browser/fingerprints`, {
128
- headers: {
129
- 'Authorization': `Bearer ${token}`,
130
- 'User-Agent': 'gologin-api',
131
- 'Content-Type': 'application/json',
132
- },
111
+ const response = await makeRequest(`${API_URL}/browser/fingerprints`, {
133
112
  method: 'PATCH',
134
- body: JSON.stringify({ browsersIds: profileIds }),
135
- });
113
+ json: { browsersIds: profileIds },
114
+ }, { token, fallbackUrl: `${FALLBACK_API_URL}/browser/fingerprints` });
136
115
 
137
- return response.json();
116
+ return response;
138
117
  },
139
118
 
140
119
  async createProfileRandomFingerprint(name = '') {
@@ -142,21 +121,16 @@ export const GologinApi = ({ token }) => {
142
121
  const { os, osSpec } = osInfo;
143
122
  const resultName = name || 'api-generated';
144
123
 
145
- const response = await fetch(`${API_URL}/browser/quick`, {
124
+ const response = await makeRequest(`${API_URL}/browser/quick`, {
146
125
  method: 'POST',
147
- headers: {
148
- 'Authorization': `Bearer ${token}`,
149
- 'User-Agent': 'gologin-api',
150
- 'Content-Type': 'application/json',
151
- },
152
- body: JSON.stringify({
126
+ json: {
153
127
  os,
154
128
  osSpec,
155
129
  name: resultName,
156
- }),
157
- });
130
+ },
131
+ }, { token, fallbackUrl: `${FALLBACK_API_URL}/browser/quick` });
158
132
 
159
- return response.json();
133
+ return response;
160
134
  },
161
135
 
162
136
  async updateUserAgentToLatestBrowser(profileIds, workspaceId = '') {
@@ -165,32 +139,21 @@ export const GologinApi = ({ token }) => {
165
139
  url += `?currentWorkspace=${workspaceId}`;
166
140
  }
167
141
 
168
- const response = await fetch(url, {
142
+ const response = await makeRequest(url, {
169
143
  method: 'PATCH',
170
- headers: {
171
- 'Authorization': `Bearer ${token}`,
172
- 'User-Agent': 'gologin-api',
173
- 'Content-Type': 'application/json',
174
- },
175
- body: JSON.stringify({ browserIds: profileIds, updateUaToNewBrowserV: true, updateAllProfiles: false, testOrbita: false }),
176
- });
144
+ json: { browserIds: profileIds, updateUaToNewBrowserV: true, updateAllProfiles: false, testOrbita: false },
145
+ }, { token, fallbackUrl: `${FALLBACK_API_URL}/browser/update_ua_to_new_browser_v` });
177
146
 
178
- return response.json();
147
+ return response;
179
148
  },
180
149
 
181
150
  async changeProfileProxy(profileId, proxyData) {
182
- console.log(proxyData);
183
- const response = await fetch(`${API_URL}/browser/${profileId}/proxy`, {
151
+ const response = await makeRequest(`${API_URL}/browser/${profileId}/proxy`, {
184
152
  method: 'PATCH',
185
- headers: {
186
- Authorization: `Bearer ${token}`,
187
- 'user-agent': 'gologin-api',
188
- 'Content-Type': 'application/json',
189
- },
190
- body: JSON.stringify(proxyData),
191
- });
153
+ json: proxyData,
154
+ }, { token, fallbackUrl: `${FALLBACK_API_URL}/browser/${profileId}/proxy` });
192
155
 
193
- return response.status;
156
+ return response;
194
157
  },
195
158
 
196
159
  getAvailableType(availableTrafficData) {
@@ -208,22 +171,16 @@ export const GologinApi = ({ token }) => {
208
171
 
209
172
  async addGologinProxyToProfile(profileId, countryCode, proxyType = '') {
210
173
  if (!proxyType) {
211
- const availableTraffic = await fetch(`${API_URL}/users-proxies/geolocation/traffic`, {
212
- headers: {
213
- Authorization: `Bearer ${token}`,
214
- 'user-agent': 'gologin-api',
215
- 'Content-Type': 'application/json',
216
- },
217
- });
218
-
219
- const availableTrafficData = await availableTraffic.json();
220
- console.log(availableTrafficData);
174
+ const availableTraffic = await makeRequest(`${API_URL}/users-proxies/geolocation/traffic`, {
175
+ method: 'GET',
176
+ }, { token, fallbackUrl: `${FALLBACK_API_URL}/users-proxies/geolocation/traffic` });
177
+
178
+ const availableTrafficData = availableTraffic;
221
179
  const availableType = this.getAvailableType(availableTrafficData);
222
180
  if (availableType === 'none') {
223
181
  throw new Error(trafficLimitMessage);
224
182
  }
225
183
 
226
- console.log(availableType);
227
184
  proxyType = availableType;
228
185
  }
229
186
 
@@ -247,22 +204,17 @@ export const GologinApi = ({ token }) => {
247
204
  throw new Error('Invalid proxy type');
248
205
  }
249
206
 
250
- const proxyResponse = await fetch(`${API_URL}/users-proxies/mobile-proxy`, {
251
- headers: {
252
- Authorization: `Bearer ${token}`,
253
- 'user-agent': 'gologin-api',
254
- 'Content-Type': 'application/json',
255
- },
207
+ const proxyResponse = await makeRequest(`${API_URL}/users-proxies/mobile-proxy`, {
256
208
  method: 'POST',
257
- body: JSON.stringify({
209
+ json: {
258
210
  countryCode,
259
211
  isDc,
260
212
  isMobile,
261
213
  profileIdToLink: profileId,
262
- }),
263
- });
214
+ },
215
+ }, { token, fallbackUrl: `${FALLBACK_API_URL}/users-proxies/mobile-proxy` });
264
216
 
265
- const proxy = await proxyResponse.json();
217
+ const proxy = proxyResponse;
266
218
  if (proxy.trafficLimitBytes < proxy.trafficUsedBytes) {
267
219
  throw new Error(trafficLimitMessage);
268
220
  }
@@ -271,27 +223,18 @@ export const GologinApi = ({ token }) => {
271
223
  },
272
224
 
273
225
  async addCookiesToProfile(profileId, cookies) {
274
- const response = await fetch(`${API_URL}/browser/${profileId}/cookies?fromUser=true`, {
226
+ const response = await makeRequest(`${API_URL}/browser/${profileId}/cookies?fromUser=true`, {
275
227
  method: 'POST',
276
- headers: {
277
- Authorization: `Bearer ${token}`,
278
- 'user-agent': 'gologin-api',
279
- 'Content-Type': 'application/json',
280
- },
281
- body: JSON.stringify(cookies),
282
- });
228
+ json: cookies,
229
+ }, { token, fallbackUrl: `${FALLBACK_API_URL}/browser/${profileId}/cookies?fromUser=true` });
283
230
 
284
231
  return response.status;
285
232
  },
286
233
 
287
234
  async deleteProfile(profileId) {
288
- const response = await fetch(`${API_URL}/browser/${profileId}`, {
235
+ const response = await makeRequest(`${API_URL}/browser/${profileId}`, {
289
236
  method: 'DELETE',
290
- headers: {
291
- Authorization: `Bearer ${token}`,
292
- 'user-agent': 'gologin-api',
293
- },
294
- });
237
+ }, { token, fallbackUrl: `${FALLBACK_API_URL}/browser/${profileId}` });
295
238
 
296
239
  return response.status;
297
240
  },
@@ -299,7 +242,7 @@ export const GologinApi = ({ token }) => {
299
242
  async exit() {
300
243
  Promise.allSettled(browsers.map((browser) => browser.close()));
301
244
  Promise.allSettled(
302
- legacyGls.map((gl) => gl.stopLocal({ posting: false })),
245
+ legacyGls.map((gl) => gl.stopLocal({ posting: true })),
303
246
  );
304
247
  Promise.allSettled(
305
248
  legacyGls.map((gl) => gl.stopRemote({ posting: true })),