gologin-commonjs 1.1.1 → 1.1.3
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/dist/src/gologin.js +546 -885
- package/package.json +1 -1
package/dist/src/gologin.js
CHANGED
|
@@ -1,21 +1,21 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
4
|
+
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.GoLogin = void 0;
|
|
7
7
|
Object.defineProperty(exports, "GologinApi", {
|
|
8
8
|
enumerable: true,
|
|
9
9
|
get: function () {
|
|
10
10
|
return _gologinApi.GologinApi;
|
|
11
|
-
}
|
|
11
|
+
}
|
|
12
12
|
});
|
|
13
13
|
exports.default = void 0;
|
|
14
14
|
Object.defineProperty(exports, "exitAll", {
|
|
15
15
|
enumerable: true,
|
|
16
16
|
get: function () {
|
|
17
17
|
return _gologinApi.exitAll;
|
|
18
|
-
}
|
|
18
|
+
}
|
|
19
19
|
});
|
|
20
20
|
var _child_process = require("child_process");
|
|
21
21
|
var _debug = _interopRequireDefault(require("debug"));
|
|
@@ -31,33 +31,32 @@ var _socksProxyAgent = require("socks-proxy-agent");
|
|
|
31
31
|
var _fonts = require("../fonts.js");
|
|
32
32
|
var _utils = require("./bookmarks/utils.js");
|
|
33
33
|
var _browserApi = require("./browser/browser-api.js");
|
|
34
|
-
var _browserChecker = _interopRequireDefault(
|
|
35
|
-
require("./browser/browser-checker.js")
|
|
36
|
-
);
|
|
34
|
+
var _browserChecker = _interopRequireDefault(require("./browser/browser-checker.js"));
|
|
37
35
|
var _browserUserDataManager = require("./browser/browser-user-data-manager.js");
|
|
38
36
|
var _cookiesManager = require("./cookies/cookies-manager.js");
|
|
39
|
-
var _extensionsManager = _interopRequireDefault(
|
|
40
|
-
require("./extensions/extensions-manager.js")
|
|
41
|
-
);
|
|
37
|
+
var _extensionsManager = _interopRequireDefault(require("./extensions/extensions-manager.js"));
|
|
42
38
|
var _profileArchiver = require("./profile/profile-archiver.js");
|
|
43
39
|
var _browser = require("./utils/browser.js");
|
|
44
40
|
var _common = require("./utils/common.js");
|
|
45
41
|
var _constants = require("./utils/constants.js");
|
|
46
42
|
var _utils2 = require("./utils/utils.js");
|
|
47
43
|
var _gologinApi = require("./gologin-api.js");
|
|
48
|
-
function _interopRequireDefault(e) {
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
44
|
+
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
|
45
|
+
const {
|
|
46
|
+
access,
|
|
47
|
+
unlink,
|
|
48
|
+
writeFile,
|
|
49
|
+
readFile
|
|
50
|
+
} = _fs.promises;
|
|
52
51
|
const SEPARATOR = _path.sep;
|
|
53
52
|
const OS_PLATFORM = process.platform;
|
|
54
|
-
const TIMEZONE_URL =
|
|
55
|
-
const PROXY_NONE =
|
|
56
|
-
const debug = (0, _debug.default)(
|
|
57
|
-
const delay =
|
|
53
|
+
const TIMEZONE_URL = 'https://geo.myip.link';
|
|
54
|
+
const PROXY_NONE = 'none';
|
|
55
|
+
const debug = (0, _debug.default)('gologin');
|
|
56
|
+
const delay = time => new Promise(resolve => setTimeout(resolve, time));
|
|
58
57
|
class GoLogin {
|
|
59
58
|
constructor(options = {}) {
|
|
60
|
-
this.browserLang =
|
|
59
|
+
this.browserLang = 'en-US';
|
|
61
60
|
this.is_remote = options.remote || false;
|
|
62
61
|
this.access_token = options.token;
|
|
63
62
|
this.profile_id = options.profile_id;
|
|
@@ -69,16 +68,14 @@ class GoLogin {
|
|
|
69
68
|
this.is_active = false;
|
|
70
69
|
this.is_stopping = false;
|
|
71
70
|
this.differentOs = false;
|
|
72
|
-
this.profileOs =
|
|
71
|
+
this.profileOs = 'lin';
|
|
73
72
|
this.waitWebsocket = options.waitWebsocket ?? true;
|
|
74
73
|
this.isCloudHeadless = options.isCloudHeadless ?? true;
|
|
75
74
|
this.isNewCloudBrowser = options.isNewCloudBrowser ?? true;
|
|
76
75
|
this.tmpdir = (0, _os.tmpdir)();
|
|
77
76
|
this.autoUpdateBrowser = !!options.autoUpdateBrowser;
|
|
78
77
|
this.checkBrowserUpdate = options.checkBrowserUpdate ?? true;
|
|
79
|
-
this.browserChecker = new _browserChecker.default(
|
|
80
|
-
options.skipOrbitaHashChecking
|
|
81
|
-
);
|
|
78
|
+
this.browserChecker = new _browserChecker.default(options.skipOrbitaHashChecking);
|
|
82
79
|
this.uploadCookiesToServer = options.uploadCookiesToServer || false;
|
|
83
80
|
this.writeCookiesFromServer = options.writeCookiesFromServer;
|
|
84
81
|
this.remote_debugging_port = options.remote_debugging_port || 0;
|
|
@@ -91,111 +88,75 @@ class GoLogin {
|
|
|
91
88
|
if (options.tmpdir) {
|
|
92
89
|
this.tmpdir = options.tmpdir;
|
|
93
90
|
if (!(0, _fs.existsSync)(this.tmpdir)) {
|
|
94
|
-
debug(
|
|
91
|
+
debug('making tmpdir', this.tmpdir);
|
|
95
92
|
(0, _fs.mkdirSync)(this.tmpdir, {
|
|
96
|
-
recursive: true
|
|
93
|
+
recursive: true
|
|
97
94
|
});
|
|
98
95
|
}
|
|
99
96
|
}
|
|
100
|
-
this.profile_zip_path = (0, _path.join)(
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
);
|
|
104
|
-
this.bookmarksFilePath = (0, _path.join)(
|
|
105
|
-
this.tmpdir,
|
|
106
|
-
`gologin_profile_${this.profile_id}`,
|
|
107
|
-
"Default",
|
|
108
|
-
"Bookmarks"
|
|
109
|
-
);
|
|
110
|
-
debug("INIT GOLOGIN", this.profile_id);
|
|
97
|
+
this.profile_zip_path = (0, _path.join)(this.tmpdir, `gologin_${this.profile_id}.zip`);
|
|
98
|
+
this.bookmarksFilePath = (0, _path.join)(this.tmpdir, `gologin_profile_${this.profile_id}`, 'Default', 'Bookmarks');
|
|
99
|
+
debug('INIT GOLOGIN', this.profile_id);
|
|
111
100
|
}
|
|
112
101
|
async checkBrowser() {
|
|
113
|
-
return this.browserChecker.checkBrowser(
|
|
114
|
-
this.autoUpdateBrowser,
|
|
115
|
-
this.checkBrowserUpdate
|
|
116
|
-
);
|
|
102
|
+
return this.browserChecker.checkBrowser(this.autoUpdateBrowser, this.checkBrowserUpdate);
|
|
117
103
|
}
|
|
118
104
|
async setProfileId(profile_id) {
|
|
119
105
|
this.profile_id = profile_id;
|
|
120
|
-
this.cookiesFilePath = await (0, _cookiesManager.getCookiesFilePath)(
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
);
|
|
124
|
-
this.profile_zip_path = (0, _path.join)(
|
|
125
|
-
this.tmpdir,
|
|
126
|
-
`gologin_${this.profile_id}.zip`
|
|
127
|
-
);
|
|
128
|
-
this.bookmarksFilePath = (0, _path.join)(
|
|
129
|
-
this.tmpdir,
|
|
130
|
-
`gologin_profile_${this.profile_id}`,
|
|
131
|
-
"Default",
|
|
132
|
-
"Bookmarks"
|
|
133
|
-
);
|
|
106
|
+
this.cookiesFilePath = await (0, _cookiesManager.getCookiesFilePath)(profile_id, this.tmpdir);
|
|
107
|
+
this.profile_zip_path = (0, _path.join)(this.tmpdir, `gologin_${this.profile_id}.zip`);
|
|
108
|
+
this.bookmarksFilePath = (0, _path.join)(this.tmpdir, `gologin_profile_${this.profile_id}`, 'Default', 'Bookmarks');
|
|
134
109
|
}
|
|
135
110
|
async getToken(username, password) {
|
|
136
|
-
const data = await _requestretry.default.post(
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
username,
|
|
141
|
-
password,
|
|
142
|
-
},
|
|
111
|
+
const data = await _requestretry.default.post(`${_common.API_URL}/user/login`, {
|
|
112
|
+
json: {
|
|
113
|
+
username,
|
|
114
|
+
password
|
|
143
115
|
}
|
|
144
|
-
);
|
|
145
|
-
if (!Reflect.has(data,
|
|
146
|
-
throw new Error(
|
|
147
|
-
`gologin auth failed with status code, ${
|
|
148
|
-
data.statusCode
|
|
149
|
-
} DATA ${JSON.stringify(data)}`
|
|
150
|
-
);
|
|
116
|
+
});
|
|
117
|
+
if (!Reflect.has(data, 'body.access_token')) {
|
|
118
|
+
throw new Error(`gologin auth failed with status code, ${data.statusCode} DATA ${JSON.stringify(data)}`);
|
|
151
119
|
}
|
|
152
120
|
}
|
|
153
121
|
async getNewFingerPrint(os) {
|
|
154
|
-
debug(
|
|
155
|
-
const fpResponse = await _requestretry.default.get(
|
|
156
|
-
|
|
157
|
-
{
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
Authorization: `Bearer ${this.access_token}`,
|
|
161
|
-
"User-Agent": "gologin-api",
|
|
162
|
-
},
|
|
122
|
+
debug('GETTING FINGERPRINT');
|
|
123
|
+
const fpResponse = await _requestretry.default.get(`${_common.API_URL}/browser/fingerprint?os=${os}`, {
|
|
124
|
+
json: true,
|
|
125
|
+
headers: {
|
|
126
|
+
'Authorization': `Bearer ${this.access_token}`,
|
|
127
|
+
'User-Agent': 'gologin-api'
|
|
163
128
|
}
|
|
164
|
-
);
|
|
129
|
+
});
|
|
165
130
|
return fpResponse?.body || {};
|
|
166
131
|
}
|
|
167
132
|
async profiles() {
|
|
168
|
-
const profilesResponse = await _requestretry.default.get(
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
Authorization: `Bearer ${this.access_token}`,
|
|
173
|
-
"User-Agent": "gologin-api",
|
|
174
|
-
},
|
|
133
|
+
const profilesResponse = await _requestretry.default.get(`${_common.API_URL}/browser/v2`, {
|
|
134
|
+
headers: {
|
|
135
|
+
'Authorization': `Bearer ${this.access_token}`,
|
|
136
|
+
'User-Agent': 'gologin-api'
|
|
175
137
|
}
|
|
176
|
-
);
|
|
138
|
+
});
|
|
177
139
|
if (profilesResponse.statusCode !== 200) {
|
|
178
|
-
throw new Error(
|
|
140
|
+
throw new Error('Gologin /browser response error');
|
|
179
141
|
}
|
|
180
142
|
return JSON.parse(profilesResponse.body);
|
|
181
143
|
}
|
|
182
144
|
async getProfile(profile_id) {
|
|
183
145
|
const id = profile_id || this.profile_id;
|
|
184
|
-
debug(
|
|
185
|
-
const profileResponse = await _requestretry.default.get(
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
Authorization: `Bearer ${this.access_token}`,
|
|
190
|
-
"User-Agent": "gologin-api",
|
|
191
|
-
},
|
|
146
|
+
debug('getProfile', this.access_token, id);
|
|
147
|
+
const profileResponse = await _requestretry.default.get(`${_common.API_URL}/browser/${id}`, {
|
|
148
|
+
headers: {
|
|
149
|
+
'Authorization': `Bearer ${this.access_token}`,
|
|
150
|
+
'User-Agent': 'gologin-api'
|
|
192
151
|
}
|
|
193
|
-
);
|
|
194
|
-
debug(
|
|
195
|
-
const {
|
|
196
|
-
|
|
152
|
+
});
|
|
153
|
+
debug('profileResponse', profileResponse.statusCode, profileResponse.body);
|
|
154
|
+
const {
|
|
155
|
+
body: errorBody = ''
|
|
156
|
+
} = profileResponse;
|
|
157
|
+
const backendErrorHeader = 'backend@error::';
|
|
197
158
|
if (errorBody.includes(backendErrorHeader)) {
|
|
198
|
-
const errorData = errorBody.replace(backendErrorHeader,
|
|
159
|
+
const errorData = errorBody.replace(backendErrorHeader, '').slice(1, -1);
|
|
199
160
|
throw new Error(errorData);
|
|
200
161
|
}
|
|
201
162
|
if (profileResponse.statusCode === 404) {
|
|
@@ -205,62 +166,49 @@ class GoLogin {
|
|
|
205
166
|
throw new Error(JSON.parse(profileResponse.body).message);
|
|
206
167
|
}
|
|
207
168
|
if (profileResponse.statusCode !== 200) {
|
|
208
|
-
throw new Error(
|
|
209
|
-
`Gologin /browser/${id} response error ${profileResponse.statusCode} INVALID TOKEN OR PROFILE NOT FOUND`
|
|
210
|
-
);
|
|
169
|
+
throw new Error(`Gologin /browser/${id} response error ${profileResponse.statusCode} INVALID TOKEN OR PROFILE NOT FOUND`);
|
|
211
170
|
}
|
|
212
171
|
if (profileResponse.statusCode === 401) {
|
|
213
|
-
throw new Error(
|
|
172
|
+
throw new Error('invalid token');
|
|
214
173
|
}
|
|
215
174
|
return JSON.parse(profileResponse.body);
|
|
216
175
|
}
|
|
217
176
|
async emptyProfile() {
|
|
218
|
-
return readFile(
|
|
219
|
-
(0, _path.resolve)(__dirname, "gologin_zeroprofile.b64")
|
|
220
|
-
).then((res) => res.toString());
|
|
177
|
+
return readFile((0, _path.resolve)(__dirname, 'gologin_zeroprofile.b64')).then(res => res.toString());
|
|
221
178
|
}
|
|
222
179
|
async getProfileS3(s3path) {
|
|
223
180
|
if (!s3path) {
|
|
224
|
-
throw new Error(
|
|
181
|
+
throw new Error('s3path not found');
|
|
225
182
|
}
|
|
226
183
|
const token = this.access_token;
|
|
227
|
-
debug(
|
|
228
|
-
"getProfileS3 token=",
|
|
229
|
-
token,
|
|
230
|
-
"profile=",
|
|
231
|
-
this.profile_id,
|
|
232
|
-
"s3path=",
|
|
233
|
-
s3path
|
|
234
|
-
);
|
|
184
|
+
debug('getProfileS3 token=', token, 'profile=', this.profile_id, 's3path=', s3path);
|
|
235
185
|
const downloadURL = `${_constants.STORAGE_GATEWAY_BASE_URL}/download`;
|
|
236
|
-
debug(
|
|
186
|
+
debug('loading profile from public s3 bucket, url=', downloadURL);
|
|
237
187
|
const profileResponse = await _requestretry.default.get(downloadURL, {
|
|
238
188
|
encoding: null,
|
|
239
189
|
headers: {
|
|
240
190
|
Authorization: `Bearer ${token}`,
|
|
241
|
-
browserId: this.profile_id
|
|
242
|
-
}
|
|
191
|
+
browserId: this.profile_id
|
|
192
|
+
}
|
|
243
193
|
});
|
|
244
194
|
if (profileResponse.statusCode !== 200) {
|
|
245
|
-
debug(
|
|
246
|
-
|
|
247
|
-
);
|
|
248
|
-
return "";
|
|
195
|
+
debug(`Gologin S3 BUCKET ${downloadURL} response error ${profileResponse.statusCode} - use empty`);
|
|
196
|
+
return '';
|
|
249
197
|
}
|
|
250
198
|
return Buffer.from(profileResponse.body);
|
|
251
199
|
}
|
|
252
200
|
async postFile(fileName, fileBuff) {
|
|
253
|
-
debug(
|
|
254
|
-
debug(
|
|
201
|
+
debug('POSTING FILE', fileBuff.length);
|
|
202
|
+
debug('Getting signed URL for S3');
|
|
255
203
|
const apiUrl = `${_constants.STORAGE_GATEWAY_BASE_URL}/upload`;
|
|
256
204
|
const bodyBufferBiteLength = Buffer.byteLength(fileBuff);
|
|
257
|
-
console.log(
|
|
205
|
+
console.log('BUFFER SIZE', bodyBufferBiteLength);
|
|
258
206
|
await _requestretry.default.put(apiUrl, {
|
|
259
207
|
headers: {
|
|
260
208
|
Authorization: `Bearer ${this.access_token}`,
|
|
261
209
|
browserId: this.profile_id,
|
|
262
|
-
|
|
263
|
-
|
|
210
|
+
'Content-Type': 'application/zip',
|
|
211
|
+
'Content-Length': bodyBufferBiteLength
|
|
264
212
|
},
|
|
265
213
|
body: fileBuff,
|
|
266
214
|
maxBodyLength: Infinity,
|
|
@@ -268,69 +216,43 @@ class GoLogin {
|
|
|
268
216
|
maxAttempts: 3,
|
|
269
217
|
retryDelay: 2000,
|
|
270
218
|
timeout: 30 * 1000,
|
|
271
|
-
fullResponse: false
|
|
219
|
+
fullResponse: false
|
|
272
220
|
});
|
|
273
|
-
console.log(
|
|
221
|
+
console.log('Profile has been uploaded to S3 successfully');
|
|
274
222
|
}
|
|
275
223
|
async emptyProfileFolder() {
|
|
276
|
-
debug(
|
|
224
|
+
debug('get emptyProfileFolder');
|
|
277
225
|
const currentDir = (0, _path.dirname)(__filename);
|
|
278
|
-
const zeroProfilePath = (0, _path.join)(
|
|
279
|
-
currentDir,
|
|
280
|
-
"..",
|
|
281
|
-
"zero_profile.zip"
|
|
282
|
-
);
|
|
226
|
+
const zeroProfilePath = (0, _path.join)(currentDir, '..', 'zero_profile.zip');
|
|
283
227
|
const profile = await readFile(zeroProfilePath);
|
|
284
|
-
debug(
|
|
228
|
+
debug('emptyProfileFolder LENGTH ::', profile.length);
|
|
285
229
|
return profile;
|
|
286
230
|
}
|
|
287
231
|
convertPreferences(preferences) {
|
|
288
|
-
if ((0, _utils2.get)(preferences,
|
|
289
|
-
preferences.userAgent = (0, _utils2.get)(
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
);
|
|
293
|
-
}
|
|
294
|
-
if ((0, _utils2.get)(preferences,
|
|
295
|
-
preferences.
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
);
|
|
299
|
-
}
|
|
300
|
-
if ((0, _utils2.get)(preferences,
|
|
301
|
-
preferences.
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
}
|
|
310
|
-
if ((0, _utils2.get)(preferences,
|
|
311
|
-
|
|
312
|
-
preferences,
|
|
313
|
-
"navigator.language"
|
|
314
|
-
);
|
|
315
|
-
preferences.languages = (0, _utils2.get)(
|
|
316
|
-
preferences,
|
|
317
|
-
"navigator.language"
|
|
318
|
-
).replace(/;|q=[\d\.]+/gim, "");
|
|
319
|
-
}
|
|
320
|
-
if ((0, _utils2.get)(preferences, "navigator.maxTouchPoints")) {
|
|
321
|
-
preferences.navigator.max_touch_points = (0, _utils2.get)(
|
|
322
|
-
preferences,
|
|
323
|
-
"navigator.maxTouchPoints"
|
|
324
|
-
);
|
|
325
|
-
}
|
|
326
|
-
if ((0, _utils2.get)(preferences, "isM1")) {
|
|
327
|
-
preferences.is_m1 = (0, _utils2.get)(preferences, "isM1");
|
|
328
|
-
}
|
|
329
|
-
if ((0, _utils2.get)(preferences, "os") == "android") {
|
|
330
|
-
const devicePixelRatio = (0, _utils2.get)(
|
|
331
|
-
preferences,
|
|
332
|
-
"devicePixelRatio"
|
|
333
|
-
);
|
|
232
|
+
if ((0, _utils2.get)(preferences, 'navigator.userAgent')) {
|
|
233
|
+
preferences.userAgent = (0, _utils2.get)(preferences, 'navigator.userAgent');
|
|
234
|
+
}
|
|
235
|
+
if ((0, _utils2.get)(preferences, 'navigator.doNotTrack')) {
|
|
236
|
+
preferences.doNotTrack = (0, _utils2.get)(preferences, 'navigator.doNotTrack');
|
|
237
|
+
}
|
|
238
|
+
if ((0, _utils2.get)(preferences, 'navigator.hardwareConcurrency')) {
|
|
239
|
+
preferences.hardwareConcurrency = (0, _utils2.get)(preferences, 'navigator.hardwareConcurrency');
|
|
240
|
+
}
|
|
241
|
+
if ((0, _utils2.get)(preferences, 'navigator.deviceMemory')) {
|
|
242
|
+
preferences.deviceMemory = (0, _utils2.get)(preferences, 'navigator.deviceMemory') * 1024;
|
|
243
|
+
}
|
|
244
|
+
if ((0, _utils2.get)(preferences, 'navigator.language')) {
|
|
245
|
+
preferences.langHeader = (0, _utils2.get)(preferences, 'navigator.language');
|
|
246
|
+
preferences.languages = (0, _utils2.get)(preferences, 'navigator.language').replace(/;|q=[\d\.]+/img, '');
|
|
247
|
+
}
|
|
248
|
+
if ((0, _utils2.get)(preferences, 'navigator.maxTouchPoints')) {
|
|
249
|
+
preferences.navigator.max_touch_points = (0, _utils2.get)(preferences, 'navigator.maxTouchPoints');
|
|
250
|
+
}
|
|
251
|
+
if ((0, _utils2.get)(preferences, 'isM1')) {
|
|
252
|
+
preferences.is_m1 = (0, _utils2.get)(preferences, 'isM1');
|
|
253
|
+
}
|
|
254
|
+
if ((0, _utils2.get)(preferences, 'os') == 'android') {
|
|
255
|
+
const devicePixelRatio = (0, _utils2.get)(preferences, 'devicePixelRatio');
|
|
334
256
|
const deviceScaleFactorCeil = Math.ceil(devicePixelRatio || 3.5);
|
|
335
257
|
let deviceScaleFactor = devicePixelRatio;
|
|
336
258
|
if (deviceScaleFactorCeil === devicePixelRatio) {
|
|
@@ -340,297 +262,225 @@ class GoLogin {
|
|
|
340
262
|
enable: true,
|
|
341
263
|
width: parseInt(this.resolution.width, 10),
|
|
342
264
|
height: parseInt(this.resolution.height, 10),
|
|
343
|
-
device_scale_factor: deviceScaleFactor
|
|
265
|
+
device_scale_factor: deviceScaleFactor
|
|
344
266
|
};
|
|
345
267
|
}
|
|
346
268
|
preferences.mediaDevices = {
|
|
347
269
|
enable: preferences.mediaDevices.enableMasking,
|
|
348
270
|
videoInputs: preferences.mediaDevices.videoInputs,
|
|
349
271
|
audioInputs: preferences.mediaDevices.audioInputs,
|
|
350
|
-
audioOutputs: preferences.mediaDevices.audioOutputs
|
|
272
|
+
audioOutputs: preferences.mediaDevices.audioOutputs
|
|
351
273
|
};
|
|
352
274
|
preferences.webRtc = {
|
|
353
275
|
...preferences.webRtc,
|
|
354
|
-
fill_based_on_ip: !!(0, _utils2.get)(preferences,
|
|
355
|
-
local_ip_masking: !!(0, _utils2.get)(
|
|
356
|
-
preferences,
|
|
357
|
-
"webRTC.local_ip_masking"
|
|
358
|
-
),
|
|
276
|
+
fill_based_on_ip: !!(0, _utils2.get)(preferences, 'webRTC.fillBasedOnIp'),
|
|
277
|
+
local_ip_masking: !!(0, _utils2.get)(preferences, 'webRTC.local_ip_masking')
|
|
359
278
|
};
|
|
360
279
|
return preferences;
|
|
361
280
|
}
|
|
362
281
|
async createBrowserExtension() {
|
|
363
282
|
const that = this;
|
|
364
|
-
debug(
|
|
283
|
+
debug('start createBrowserExtension');
|
|
365
284
|
await (0, _rimraf.default)(this.orbitaExtensionPath(), () => null);
|
|
366
285
|
const extPath = this.orbitaExtensionPath();
|
|
367
|
-
debug(
|
|
368
|
-
const extension_source = (0, _path.resolve)(
|
|
369
|
-
__dirname,
|
|
370
|
-
"gologin-browser-ext.zip"
|
|
371
|
-
);
|
|
286
|
+
debug('extension folder sanitized');
|
|
287
|
+
const extension_source = (0, _path.resolve)(__dirname, 'gologin-browser-ext.zip');
|
|
372
288
|
await (0, _decompress.default)(extension_source, extPath, {
|
|
373
289
|
plugins: [(0, _decompressUnzip.default)()],
|
|
374
|
-
filter:
|
|
375
|
-
})
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
null,
|
|
386
|
-
2
|
|
387
|
-
)
|
|
388
|
-
).then(() => extPath);
|
|
389
|
-
})
|
|
390
|
-
.catch(async (e) => {
|
|
391
|
-
debug("orbita extension error", e);
|
|
392
|
-
});
|
|
393
|
-
debug("createBrowserExtension done");
|
|
290
|
+
filter: file => !file.path.endsWith('/')
|
|
291
|
+
}).then(() => {
|
|
292
|
+
debug('extraction done');
|
|
293
|
+
debug('create uid.json');
|
|
294
|
+
return writeFile((0, _path.join)(extPath, 'uid.json'), JSON.stringify({
|
|
295
|
+
uid: that.profile_id
|
|
296
|
+
}, null, 2)).then(() => extPath);
|
|
297
|
+
}).catch(async e => {
|
|
298
|
+
debug('orbita extension error', e);
|
|
299
|
+
});
|
|
300
|
+
debug('createBrowserExtension done');
|
|
394
301
|
}
|
|
395
302
|
extractProfile(path, zipfile) {
|
|
396
303
|
debug(`extactProfile ${zipfile}, ${path}`);
|
|
397
304
|
return (0, _decompress.default)(zipfile, path, {
|
|
398
305
|
plugins: [(0, _decompressUnzip.default)()],
|
|
399
|
-
filter:
|
|
306
|
+
filter: file => !file.path.endsWith('/')
|
|
400
307
|
});
|
|
401
308
|
}
|
|
402
309
|
async createStartup(local = false) {
|
|
403
|
-
const profilePath = (0, _path.join)(
|
|
404
|
-
this.tmpdir,
|
|
405
|
-
`gologin_profile_${this.profile_id}`
|
|
406
|
-
);
|
|
310
|
+
const profilePath = (0, _path.join)(this.tmpdir, `gologin_profile_${this.profile_id}`);
|
|
407
311
|
let profile;
|
|
408
312
|
let profile_folder;
|
|
409
313
|
await (0, _rimraf.default)(profilePath, () => null);
|
|
410
|
-
debug(
|
|
314
|
+
debug('-', profilePath, 'dropped');
|
|
411
315
|
profile = await this.getProfile();
|
|
412
|
-
const {
|
|
316
|
+
const {
|
|
317
|
+
navigator = {},
|
|
318
|
+
fonts,
|
|
319
|
+
os: profileOs
|
|
320
|
+
} = profile;
|
|
413
321
|
this.fontsMasking = fonts?.enableMasking;
|
|
414
322
|
this.profileOs = profileOs;
|
|
415
|
-
this.differentOs =
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
const { resolution = "1920x1080", language = "en-US,en;q=0.9" } = navigator;
|
|
323
|
+
this.differentOs = profileOs !== 'android' && (OS_PLATFORM === 'win32' && profileOs !== 'win' || OS_PLATFORM === 'darwin' && profileOs !== 'mac' || OS_PLATFORM === 'linux' && profileOs !== 'lin');
|
|
324
|
+
const {
|
|
325
|
+
resolution = '1920x1080',
|
|
326
|
+
language = 'en-US,en;q=0.9'
|
|
327
|
+
} = navigator;
|
|
421
328
|
this.language = language;
|
|
422
|
-
const [screenWidth, screenHeight] = resolution.split(
|
|
329
|
+
const [screenWidth, screenHeight] = resolution.split('x');
|
|
423
330
|
this.resolution = {
|
|
424
331
|
width: parseInt(screenWidth, 10),
|
|
425
|
-
height: parseInt(screenHeight, 10)
|
|
332
|
+
height: parseInt(screenHeight, 10)
|
|
426
333
|
};
|
|
427
|
-
const profileZipExists = await access(this.profile_zip_path)
|
|
428
|
-
.then(() => true)
|
|
429
|
-
.catch(() => false);
|
|
334
|
+
const profileZipExists = await access(this.profile_zip_path).then(() => true).catch(() => false);
|
|
430
335
|
if (!(local && profileZipExists)) {
|
|
431
336
|
try {
|
|
432
|
-
profile_folder = await this.getProfileS3(
|
|
433
|
-
(0, _utils2.get)(profile, "s3Path", "")
|
|
434
|
-
);
|
|
337
|
+
profile_folder = await this.getProfileS3((0, _utils2.get)(profile, 's3Path', ''));
|
|
435
338
|
} catch (e) {
|
|
436
|
-
debug(
|
|
339
|
+
debug('Cannot get profile - using empty', e);
|
|
437
340
|
}
|
|
438
|
-
debug(
|
|
341
|
+
debug('FILE READY', this.profile_zip_path);
|
|
439
342
|
if (!profile_folder.length) {
|
|
440
343
|
profile_folder = await this.emptyProfileFolder();
|
|
441
344
|
}
|
|
442
345
|
await writeFile(this.profile_zip_path, profile_folder);
|
|
443
|
-
debug(
|
|
346
|
+
debug('PROFILE LENGTH', profile_folder.length);
|
|
444
347
|
} else {
|
|
445
|
-
debug(
|
|
348
|
+
debug('PROFILE LOCAL HAVING', this.profile_zip_path);
|
|
446
349
|
}
|
|
447
|
-
debug(
|
|
350
|
+
debug('Cleaning up..', profilePath);
|
|
448
351
|
try {
|
|
449
352
|
await this.extractProfile(profilePath, this.profile_zip_path);
|
|
450
|
-
debug(
|
|
353
|
+
debug('extraction done');
|
|
451
354
|
} catch (e) {
|
|
452
355
|
console.trace(e);
|
|
453
356
|
profile_folder = await this.emptyProfileFolder();
|
|
454
357
|
await writeFile(this.profile_zip_path, profile_folder);
|
|
455
358
|
await this.extractProfile(profilePath, this.profile_zip_path);
|
|
456
359
|
}
|
|
457
|
-
const singletonLockPath = (0, _path.join)(profilePath,
|
|
458
|
-
const singletonLockExists = await access(singletonLockPath)
|
|
459
|
-
.then(() => true)
|
|
460
|
-
.catch(() => false);
|
|
360
|
+
const singletonLockPath = (0, _path.join)(profilePath, 'SingletonLock');
|
|
361
|
+
const singletonLockExists = await access(singletonLockPath).then(() => true).catch(() => false);
|
|
461
362
|
if (singletonLockExists) {
|
|
462
|
-
debug(
|
|
363
|
+
debug('removing SingletonLock');
|
|
463
364
|
await unlink(singletonLockPath);
|
|
464
|
-
debug(
|
|
465
|
-
}
|
|
466
|
-
const pref_file_name = (0, _path.join)(
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
"Preferences"
|
|
470
|
-
);
|
|
471
|
-
debug("reading", pref_file_name);
|
|
472
|
-
const prefFileExists = await access(pref_file_name)
|
|
473
|
-
.then(() => true)
|
|
474
|
-
.catch(() => false);
|
|
365
|
+
debug('SingletonLock removed');
|
|
366
|
+
}
|
|
367
|
+
const pref_file_name = (0, _path.join)(profilePath, 'Default', 'Preferences');
|
|
368
|
+
debug('reading', pref_file_name);
|
|
369
|
+
const prefFileExists = await access(pref_file_name).then(() => true).catch(() => false);
|
|
475
370
|
if (!prefFileExists) {
|
|
476
|
-
debug(
|
|
477
|
-
"Preferences file not exists waiting",
|
|
478
|
-
pref_file_name,
|
|
479
|
-
". Using empty profile"
|
|
480
|
-
);
|
|
371
|
+
debug('Preferences file not exists waiting', pref_file_name, '. Using empty profile');
|
|
481
372
|
profile_folder = await this.emptyProfileFolder();
|
|
482
373
|
await writeFile(this.profile_zip_path, profile_folder);
|
|
483
374
|
await this.extractProfile(profilePath, this.profile_zip_path);
|
|
484
|
-
await writeFile(pref_file_name,
|
|
375
|
+
await writeFile(pref_file_name, '{}');
|
|
485
376
|
}
|
|
486
377
|
const preferences_raw = await readFile(pref_file_name);
|
|
487
378
|
const preferences = JSON.parse(preferences_raw.toString());
|
|
488
|
-
let proxy = (0, _utils2.get)(profile,
|
|
489
|
-
const name = (0, _utils2.get)(profile,
|
|
490
|
-
const chromeExtensions =
|
|
491
|
-
|
|
492
|
-
const userChromeExtensions =
|
|
493
|
-
(0, _utils2.get)(profile, "userChromeExtensions") || [];
|
|
379
|
+
let proxy = (0, _utils2.get)(profile, 'proxy');
|
|
380
|
+
const name = (0, _utils2.get)(profile, 'name');
|
|
381
|
+
const chromeExtensions = (0, _utils2.get)(profile, 'chromeExtensions') || [];
|
|
382
|
+
const userChromeExtensions = (0, _utils2.get)(profile, 'userChromeExtensions') || [];
|
|
494
383
|
const allExtensions = [...chromeExtensions, ...userChromeExtensions];
|
|
495
384
|
if (allExtensions.length) {
|
|
496
385
|
const ExtensionsManagerInst = new _extensionsManager.default();
|
|
497
386
|
ExtensionsManagerInst.apiUrl = _common.API_URL;
|
|
498
|
-
await ExtensionsManagerInst.init()
|
|
499
|
-
.then(() => ExtensionsManagerInst.updateExtensions())
|
|
500
|
-
.catch(() => {});
|
|
387
|
+
await ExtensionsManagerInst.init().then(() => ExtensionsManagerInst.updateExtensions()).catch(() => {});
|
|
501
388
|
ExtensionsManagerInst.accessToken = this.access_token;
|
|
502
389
|
await ExtensionsManagerInst.getExtensionsPolicies();
|
|
503
390
|
let profileExtensionsCheckRes = [];
|
|
504
391
|
if (ExtensionsManagerInst.useLocalExtStorage) {
|
|
505
|
-
const promises = [
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
this.profile_id
|
|
519
|
-
)
|
|
520
|
-
.then((res) => ({
|
|
521
|
-
profileUserExtensionsCheckRes: res,
|
|
522
|
-
}))
|
|
523
|
-
.catch((error) => {
|
|
524
|
-
console.log("checkUserChromeExtensions error: ", error);
|
|
525
|
-
return null;
|
|
526
|
-
}),
|
|
527
|
-
];
|
|
392
|
+
const promises = [ExtensionsManagerInst.checkChromeExtensions(allExtensions).then(res => ({
|
|
393
|
+
profileExtensionsCheckRes: res
|
|
394
|
+
})).catch(e => {
|
|
395
|
+
console.log('checkChromeExtensions error: ', e);
|
|
396
|
+
return {
|
|
397
|
+
profileExtensionsCheckRes: []
|
|
398
|
+
};
|
|
399
|
+
}), ExtensionsManagerInst.checkLocalUserChromeExtensions(userChromeExtensions, this.profile_id).then(res => ({
|
|
400
|
+
profileUserExtensionsCheckRes: res
|
|
401
|
+
})).catch(error => {
|
|
402
|
+
console.log('checkUserChromeExtensions error: ', error);
|
|
403
|
+
return null;
|
|
404
|
+
})];
|
|
528
405
|
const extensionsResult = await Promise.all(promises);
|
|
529
|
-
const profileExtensionPathRes =
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
const profileUserExtensionPathRes = extensionsResult.find(
|
|
533
|
-
(el) => "profileUserExtensionsCheckRes" in el
|
|
534
|
-
);
|
|
535
|
-
profileExtensionsCheckRes = (
|
|
536
|
-
profileExtensionPathRes?.profileExtensionsCheckRes || []
|
|
537
|
-
).concat(
|
|
538
|
-
profileUserExtensionPathRes?.profileUserExtensionsCheckRes || []
|
|
539
|
-
);
|
|
406
|
+
const profileExtensionPathRes = extensionsResult.find(el => 'profileExtensionsCheckRes' in el) || {};
|
|
407
|
+
const profileUserExtensionPathRes = extensionsResult.find(el => 'profileUserExtensionsCheckRes' in el);
|
|
408
|
+
profileExtensionsCheckRes = (profileExtensionPathRes?.profileExtensionsCheckRes || []).concat(profileUserExtensionPathRes?.profileUserExtensionsCheckRes || []);
|
|
540
409
|
}
|
|
541
410
|
let extSettings;
|
|
542
411
|
if (ExtensionsManagerInst.useLocalExtStorage) {
|
|
543
|
-
extSettings = await (0,
|
|
544
|
-
_browserUserDataManager.setExtPathsAndRemoveDeleted)(
|
|
545
|
-
preferences,
|
|
546
|
-
profileExtensionsCheckRes,
|
|
547
|
-
this.profile_id
|
|
548
|
-
);
|
|
412
|
+
extSettings = await (0, _browserUserDataManager.setExtPathsAndRemoveDeleted)(preferences, profileExtensionsCheckRes, this.profile_id);
|
|
549
413
|
} else {
|
|
550
|
-
const originalExtensionsFolder = (0, _path.join)(
|
|
551
|
-
|
|
552
|
-
"Default",
|
|
553
|
-
"Extensions"
|
|
554
|
-
);
|
|
555
|
-
extSettings = await (0, _browserUserDataManager.setOriginalExtPaths)(
|
|
556
|
-
preferences,
|
|
557
|
-
originalExtensionsFolder
|
|
558
|
-
);
|
|
414
|
+
const originalExtensionsFolder = (0, _path.join)(profilePath, 'Default', 'Extensions');
|
|
415
|
+
extSettings = await (0, _browserUserDataManager.setOriginalExtPaths)(preferences, originalExtensionsFolder);
|
|
559
416
|
}
|
|
560
|
-
this.extensionPathsToInstall =
|
|
561
|
-
ExtensionsManagerInst.getExtensionsToInstall(
|
|
562
|
-
extSettings,
|
|
563
|
-
profileExtensionsCheckRes
|
|
564
|
-
);
|
|
417
|
+
this.extensionPathsToInstall = ExtensionsManagerInst.getExtensionsToInstall(extSettings, profileExtensionsCheckRes);
|
|
565
418
|
if (extSettings) {
|
|
566
419
|
const currentExtSettings = preferences.extensions || {};
|
|
567
420
|
currentExtSettings.settings = extSettings;
|
|
568
421
|
preferences.extensions = currentExtSettings;
|
|
569
422
|
}
|
|
570
423
|
}
|
|
571
|
-
if (proxy.mode ===
|
|
572
|
-
const autoProxyServer = (0, _utils2.get)(profile,
|
|
573
|
-
const splittedAutoProxyServer = autoProxyServer.split(
|
|
574
|
-
const splittedProxyAddress = splittedAutoProxyServer[1].split(
|
|
424
|
+
if (proxy.mode === 'gologin' || proxy.mode === 'tor') {
|
|
425
|
+
const autoProxyServer = (0, _utils2.get)(profile, 'autoProxyServer');
|
|
426
|
+
const splittedAutoProxyServer = autoProxyServer.split('://');
|
|
427
|
+
const splittedProxyAddress = splittedAutoProxyServer[1].split(':');
|
|
575
428
|
const port = splittedProxyAddress[1];
|
|
576
429
|
proxy = {
|
|
577
|
-
mode: splittedAutoProxyServer[0],
|
|
578
|
-
host: splittedProxyAddress[0],
|
|
430
|
+
'mode': splittedAutoProxyServer[0],
|
|
431
|
+
'host': splittedProxyAddress[0],
|
|
579
432
|
port,
|
|
580
|
-
username: (0, _utils2.get)(profile,
|
|
581
|
-
password: (0, _utils2.get)(profile,
|
|
433
|
+
'username': (0, _utils2.get)(profile, 'autoProxyUsername'),
|
|
434
|
+
'password': (0, _utils2.get)(profile, 'autoProxyPassword')
|
|
582
435
|
};
|
|
583
|
-
profile.proxy.username = (0, _utils2.get)(profile,
|
|
584
|
-
profile.proxy.password = (0, _utils2.get)(profile,
|
|
436
|
+
profile.proxy.username = (0, _utils2.get)(profile, 'autoProxyUsername');
|
|
437
|
+
profile.proxy.password = (0, _utils2.get)(profile, 'autoProxyPassword');
|
|
585
438
|
}
|
|
586
|
-
if (proxy.mode ===
|
|
587
|
-
proxy.mode =
|
|
439
|
+
if (proxy.mode === 'geolocation') {
|
|
440
|
+
proxy.mode = 'http';
|
|
588
441
|
}
|
|
589
442
|
if (proxy.mode === PROXY_NONE) {
|
|
590
443
|
proxy = null;
|
|
591
444
|
}
|
|
592
445
|
this.proxy = proxy;
|
|
593
|
-
await this.getTimeZone(proxy).catch(
|
|
594
|
-
console.error(
|
|
446
|
+
await this.getTimeZone(proxy).catch(e => {
|
|
447
|
+
console.error('Proxy Error. Check it and try again.');
|
|
595
448
|
throw e;
|
|
596
449
|
});
|
|
597
450
|
const [latitude, longitude] = this._tz.ll;
|
|
598
|
-
const {
|
|
451
|
+
const {
|
|
452
|
+
accuracy
|
|
453
|
+
} = this._tz;
|
|
599
454
|
const profileGeolocation = profile.geolocation;
|
|
600
455
|
const tzGeoLocation = {
|
|
601
456
|
latitude,
|
|
602
457
|
longitude,
|
|
603
|
-
accuracy
|
|
458
|
+
accuracy
|
|
604
459
|
};
|
|
605
|
-
profile.geoLocation = this.getGeolocationParams(
|
|
606
|
-
profileGeolocation,
|
|
607
|
-
tzGeoLocation
|
|
608
|
-
);
|
|
460
|
+
profile.geoLocation = this.getGeolocationParams(profileGeolocation, tzGeoLocation);
|
|
609
461
|
profile.name = name;
|
|
610
|
-
profile.name_base64 = Buffer.from(name).toString(
|
|
462
|
+
profile.name_base64 = Buffer.from(name).toString('base64');
|
|
611
463
|
profile.profile_id = this.profile_id;
|
|
612
464
|
profile.webRtc = {
|
|
613
|
-
mode:
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
: (0, _utils2.get)(profile, "webRTC.mode"),
|
|
617
|
-
publicIP: (0, _utils2.get)(profile, "webRTC.fillBasedOnIp")
|
|
618
|
-
? this._tz.ip
|
|
619
|
-
: (0, _utils2.get)(profile, "webRTC.publicIp"),
|
|
620
|
-
localIps: (0, _utils2.get)(profile, "webRTC.localIps", []),
|
|
465
|
+
mode: (0, _utils2.get)(profile, 'webRTC.mode') === 'alerted' ? 'public' : (0, _utils2.get)(profile, 'webRTC.mode'),
|
|
466
|
+
publicIP: (0, _utils2.get)(profile, 'webRTC.fillBasedOnIp') ? this._tz.ip : (0, _utils2.get)(profile, 'webRTC.publicIp'),
|
|
467
|
+
localIps: (0, _utils2.get)(profile, 'webRTC.localIps', [])
|
|
621
468
|
};
|
|
622
|
-
debug(
|
|
623
|
-
debug(
|
|
624
|
-
debug(
|
|
469
|
+
debug('profile.webRtc=', profile.webRtc);
|
|
470
|
+
debug('profile.timezone=', profile.timezone);
|
|
471
|
+
debug('profile.mediaDevices=', profile.mediaDevices);
|
|
625
472
|
const audioContext = profile.audioContext || {};
|
|
626
|
-
const {
|
|
473
|
+
const {
|
|
474
|
+
mode: audioCtxMode = 'off',
|
|
475
|
+
noise: audioCtxNoise
|
|
476
|
+
} = audioContext;
|
|
627
477
|
if (profile.timezone.fillBasedOnIp === false) {
|
|
628
478
|
profile.timezone = {
|
|
629
|
-
id: profile.timezone.timezone
|
|
479
|
+
id: profile.timezone.timezone
|
|
630
480
|
};
|
|
631
481
|
} else {
|
|
632
482
|
profile.timezone = {
|
|
633
|
-
id: this._tz.timezone
|
|
483
|
+
id: this._tz.timezone
|
|
634
484
|
};
|
|
635
485
|
}
|
|
636
486
|
profile.webgl_noise_value = profile.webGL.noise;
|
|
@@ -638,102 +488,75 @@ class GoLogin {
|
|
|
638
488
|
profile.canvasMode = profile.canvas.mode;
|
|
639
489
|
profile.canvasNoise = profile.canvas.noise;
|
|
640
490
|
profile.audioContext = {
|
|
641
|
-
enable: audioCtxMode !==
|
|
642
|
-
noiseValue: audioCtxNoise
|
|
491
|
+
enable: audioCtxMode !== 'off',
|
|
492
|
+
noiseValue: audioCtxNoise
|
|
643
493
|
};
|
|
644
494
|
profile.webgl = {
|
|
645
495
|
metadata: {
|
|
646
|
-
vendor: (0, _utils2.get)(profile,
|
|
647
|
-
renderer: (0, _utils2.get)(profile,
|
|
648
|
-
mode: (0, _utils2.get)(profile,
|
|
649
|
-
}
|
|
496
|
+
vendor: (0, _utils2.get)(profile, 'webGLMetadata.vendor'),
|
|
497
|
+
renderer: (0, _utils2.get)(profile, 'webGLMetadata.renderer'),
|
|
498
|
+
mode: (0, _utils2.get)(profile, 'webGLMetadata.mode') === 'mask'
|
|
499
|
+
}
|
|
650
500
|
};
|
|
651
501
|
profile.custom_fonts = {
|
|
652
|
-
enable: !!fonts?.enableMasking
|
|
502
|
+
enable: !!fonts?.enableMasking
|
|
653
503
|
};
|
|
654
504
|
const gologin = this.convertPreferences(profile);
|
|
655
|
-
debug(
|
|
656
|
-
`Writing profile for screenWidth ${profilePath}`,
|
|
657
|
-
JSON.stringify(gologin)
|
|
658
|
-
);
|
|
505
|
+
debug(`Writing profile for screenWidth ${profilePath}`, JSON.stringify(gologin));
|
|
659
506
|
gologin.screenWidth = this.resolution.width;
|
|
660
507
|
gologin.screenHeight = this.resolution.height;
|
|
661
|
-
debug(
|
|
662
|
-
this.cookiesFilePath = await (0, _cookiesManager.getCookiesFilePath)(
|
|
663
|
-
this.profile_id,
|
|
664
|
-
this.tmpdir
|
|
665
|
-
);
|
|
508
|
+
debug('writeCookiesFromServer', this.writeCookiesFromServer);
|
|
509
|
+
this.cookiesFilePath = await (0, _cookiesManager.getCookiesFilePath)(this.profile_id, this.tmpdir);
|
|
666
510
|
if (this.writeCookiesFromServer) {
|
|
667
511
|
await this.writeCookiesToFile();
|
|
668
512
|
}
|
|
669
513
|
if (this.fontsMasking) {
|
|
670
514
|
const families = fonts?.families || [];
|
|
671
515
|
if (!families.length) {
|
|
672
|
-
throw new Error(
|
|
516
|
+
throw new Error('No fonts list provided');
|
|
673
517
|
}
|
|
674
518
|
try {
|
|
675
|
-
await (0, _browserUserDataManager.composeFonts)(
|
|
676
|
-
families,
|
|
677
|
-
profilePath,
|
|
678
|
-
this.differentOs
|
|
679
|
-
);
|
|
519
|
+
await (0, _browserUserDataManager.composeFonts)(families, profilePath, this.differentOs);
|
|
680
520
|
} catch (e) {
|
|
681
521
|
console.trace(e);
|
|
682
522
|
}
|
|
683
523
|
}
|
|
684
|
-
const languages = this.language.replace(/;|q=[\d\.]+/
|
|
524
|
+
const languages = this.language.replace(/;|q=[\d\.]+/img, '');
|
|
685
525
|
if (preferences.gologin == null) {
|
|
686
526
|
preferences.gologin = {};
|
|
687
527
|
}
|
|
688
528
|
preferences.gologin.langHeader = gologin.navigator.language;
|
|
689
529
|
preferences.gologin.language = languages;
|
|
690
|
-
const [splittedLangs] = gologin.navigator.language.split(
|
|
691
|
-
const [browserLang] = splittedLangs.split(
|
|
530
|
+
const [splittedLangs] = gologin.navigator.language.split(';');
|
|
531
|
+
const [browserLang] = splittedLangs.split(',');
|
|
692
532
|
gologin.browserLang = browserLang;
|
|
693
|
-
const isMAC = OS_PLATFORM ===
|
|
533
|
+
const isMAC = OS_PLATFORM === 'darwin';
|
|
694
534
|
const checkAutoLangResult = (0, _browser.checkAutoLang)(gologin, this._tz);
|
|
695
|
-
this.browserLang = isMAC ?
|
|
696
|
-
await writeFile(
|
|
697
|
-
|
|
698
|
-
|
|
699
|
-
|
|
700
|
-
gologin,
|
|
701
|
-
})
|
|
702
|
-
)
|
|
703
|
-
);
|
|
704
|
-
const bookmarksParsedData = await (0, _utils.getCurrentProfileBookmarks)(
|
|
705
|
-
this.bookmarksFilePath
|
|
706
|
-
);
|
|
535
|
+
this.browserLang = isMAC ? 'en-US' : checkAutoLangResult;
|
|
536
|
+
await writeFile((0, _path.join)(profilePath, 'Default', 'Preferences'), JSON.stringify(Object.assign(preferences, {
|
|
537
|
+
gologin
|
|
538
|
+
})));
|
|
539
|
+
const bookmarksParsedData = await (0, _utils.getCurrentProfileBookmarks)(this.bookmarksFilePath);
|
|
707
540
|
const bookmarksFromDb = profile.bookmarks?.bookmark_bar;
|
|
708
|
-
bookmarksParsedData.roots = bookmarksFromDb
|
|
709
|
-
|
|
710
|
-
|
|
711
|
-
await writeFile(
|
|
712
|
-
this.bookmarksFilePath,
|
|
713
|
-
JSON.stringify(bookmarksParsedData)
|
|
714
|
-
);
|
|
715
|
-
debug(
|
|
716
|
-
"Profile ready. Path: ",
|
|
717
|
-
profilePath,
|
|
718
|
-
"PROXY",
|
|
719
|
-
JSON.stringify((0, _utils2.get)(preferences, "gologin.proxy"))
|
|
720
|
-
);
|
|
541
|
+
bookmarksParsedData.roots = bookmarksFromDb ? profile.bookmarks : bookmarksParsedData.roots;
|
|
542
|
+
await writeFile(this.bookmarksFilePath, JSON.stringify(bookmarksParsedData));
|
|
543
|
+
debug('Profile ready. Path: ', profilePath, 'PROXY', JSON.stringify((0, _utils2.get)(preferences, 'gologin.proxy')));
|
|
721
544
|
return profilePath;
|
|
722
545
|
}
|
|
723
546
|
async commitProfile() {
|
|
724
547
|
const dataBuff = await this.getProfileDataToUpdate();
|
|
725
|
-
debug(
|
|
548
|
+
debug('begin updating', dataBuff.length);
|
|
726
549
|
if (!dataBuff.length) {
|
|
727
|
-
debug(
|
|
550
|
+
debug('WARN: profile zip data empty - SKIPPING PROFILE COMMIT');
|
|
728
551
|
return;
|
|
729
552
|
}
|
|
730
553
|
try {
|
|
731
|
-
debug(
|
|
732
|
-
await this.postFile(
|
|
554
|
+
debug('Patching profile');
|
|
555
|
+
await this.postFile('profile', dataBuff);
|
|
733
556
|
} catch (e) {
|
|
734
|
-
debug(
|
|
557
|
+
debug('CANNOT COMMIT PROFILE', e);
|
|
735
558
|
}
|
|
736
|
-
debug(
|
|
559
|
+
debug('COMMIT COMPLETED');
|
|
737
560
|
}
|
|
738
561
|
profilePath() {
|
|
739
562
|
return (0, _path.join)(this.tmpdir, `gologin_profile_${this.profile_id}`);
|
|
@@ -747,10 +570,10 @@ class GoLogin {
|
|
|
747
570
|
return Math.floor(Math.random() * (max - min + 1)) + min;
|
|
748
571
|
}
|
|
749
572
|
async checkPortAvailable(port) {
|
|
750
|
-
debug(
|
|
573
|
+
debug('CHECKING PORT AVAILABLE', port);
|
|
751
574
|
try {
|
|
752
575
|
const portAvailable = await (0, _utils2.isPortReachable)(port, {
|
|
753
|
-
host:
|
|
576
|
+
host: 'localhost'
|
|
754
577
|
});
|
|
755
578
|
if (portAvailable) {
|
|
756
579
|
debug(`PORT ${port} IS OPEN`);
|
|
@@ -771,142 +594,120 @@ class GoLogin {
|
|
|
771
594
|
}
|
|
772
595
|
return port;
|
|
773
596
|
}
|
|
774
|
-
randomPoint(koordinat) {
|
|
775
|
-
var latsplit = koordinat.latitude.toString().split(".");
|
|
776
|
-
var longsplit = koordinat.longitude.toString().split(".");
|
|
777
|
-
var randomLength = this.getRandomInRange(12, 16, 0);
|
|
778
|
-
var newlat = latsplit[0] + "." + latsplit[1].substring(0, randomLength);
|
|
779
|
-
var newlong = longsplit[0] + "." + longsplit[1].substring(0, randomLength);
|
|
780
|
-
return {
|
|
781
|
-
latitude: parseFloat(newlat),
|
|
782
|
-
longitude: parseFloat(newlong),
|
|
783
|
-
};
|
|
784
|
-
}
|
|
785
|
-
|
|
786
|
-
getRandomInRange(t, e, i) {
|
|
787
|
-
return 1 * (Math.random() * (e - t) + t).toFixed(i);
|
|
788
|
-
}
|
|
789
|
-
|
|
790
|
-
randomGeo(t, e, i) {
|
|
791
|
-
var n = Math.random(),
|
|
792
|
-
o = Math.random(),
|
|
793
|
-
s = (i / 111300) * Math.sqrt(n),
|
|
794
|
-
r = 2 * Math.PI * o,
|
|
795
|
-
a = s * Math.cos(r);
|
|
796
|
-
var koordinat = {
|
|
797
|
-
latitude: s * Math.sin(r) + t,
|
|
798
|
-
longitude: a + e,
|
|
799
|
-
};
|
|
800
|
-
return this.randomPoint(koordinat);
|
|
801
|
-
}
|
|
802
597
|
async getTimeZone(proxy) {
|
|
803
|
-
debug(
|
|
598
|
+
debug('getting timeZone proxy=', proxy);
|
|
804
599
|
if (this.timezone) {
|
|
805
|
-
debug(
|
|
600
|
+
debug('getTimeZone from options', this.timezone);
|
|
806
601
|
this._tz = this.timezone;
|
|
807
602
|
return this._tz.timezone;
|
|
808
603
|
}
|
|
809
604
|
let data = null;
|
|
810
605
|
if (proxy && proxy.mode !== PROXY_NONE) {
|
|
811
|
-
if (proxy.mode.includes(
|
|
606
|
+
if (proxy.mode.includes('socks')) {
|
|
812
607
|
for (let i = 0; i < 5; i++) {
|
|
813
608
|
try {
|
|
814
|
-
debug(
|
|
609
|
+
debug('getting timeZone socks try', i + 1);
|
|
815
610
|
return this.getTimezoneWithSocks(proxy);
|
|
816
611
|
} catch (e) {
|
|
817
612
|
console.log(e.message);
|
|
818
613
|
}
|
|
819
614
|
}
|
|
820
|
-
throw new Error(
|
|
615
|
+
throw new Error('Socks proxy connection timed out');
|
|
821
616
|
}
|
|
822
617
|
const proxyUrl = `${proxy.mode}://${proxy.username}:${proxy.password}@${proxy.host}:${proxy.port}`;
|
|
823
618
|
debug(`getTimeZone start ${TIMEZONE_URL}`, proxyUrl);
|
|
824
619
|
data = await _requestretry.default.get(TIMEZONE_URL, {
|
|
825
620
|
proxy: proxyUrl,
|
|
826
621
|
timeout: 20 * 1000,
|
|
827
|
-
maxAttempts: 5
|
|
622
|
+
maxAttempts: 5
|
|
828
623
|
});
|
|
829
624
|
} else {
|
|
830
|
-
|
|
831
|
-
|
|
832
|
-
|
|
833
|
-
|
|
834
|
-
|
|
835
|
-
|
|
836
|
-
|
|
837
|
-
|
|
838
|
-
|
|
839
|
-
|
|
840
|
-
|
|
841
|
-
|
|
625
|
+
try {
|
|
626
|
+
data = await _requestretry.default.get(TIMEZONE_URL, {
|
|
627
|
+
timeout: 20 * 1000,
|
|
628
|
+
maxAttempts: 2
|
|
629
|
+
});
|
|
630
|
+
} catch {
|
|
631
|
+
data = {
|
|
632
|
+
body: JSON.stringify({
|
|
633
|
+
country: "ID",
|
|
634
|
+
stateProv: "Jakarta",
|
|
635
|
+
city: "Jakarta",
|
|
636
|
+
timezone: "Asia/Jakarta",
|
|
637
|
+
ll: [
|
|
638
|
+
"-6.21140",
|
|
639
|
+
"106.84460"
|
|
640
|
+
],
|
|
641
|
+
languages: "id",
|
|
642
|
+
accuracy: 100
|
|
643
|
+
})
|
|
644
|
+
}
|
|
645
|
+
}
|
|
842
646
|
}
|
|
843
|
-
debug(
|
|
647
|
+
debug('getTimeZone finish', data.body);
|
|
844
648
|
this._tz = JSON.parse(data.body);
|
|
845
649
|
return this._tz.timezone;
|
|
846
650
|
}
|
|
847
651
|
async getTimezoneWithSocks(params) {
|
|
848
|
-
const {
|
|
652
|
+
const {
|
|
653
|
+
host,
|
|
654
|
+
port,
|
|
655
|
+
username = '',
|
|
656
|
+
password = ''
|
|
657
|
+
} = params;
|
|
849
658
|
let body;
|
|
850
|
-
let proxy =
|
|
659
|
+
let proxy = 'socks://';
|
|
851
660
|
if (username) {
|
|
852
|
-
const resultPassword = password ?
|
|
661
|
+
const resultPassword = password ? ':' + password + '@' : '@';
|
|
853
662
|
proxy += username + resultPassword;
|
|
854
663
|
}
|
|
855
|
-
proxy += host +
|
|
664
|
+
proxy += host + ':' + port;
|
|
856
665
|
const agent = new _socksProxyAgent.SocksProxyAgent(proxy);
|
|
857
666
|
const checkData = await new Promise((resolve, reject) => {
|
|
858
|
-
(0, _https.get)(
|
|
859
|
-
|
|
860
|
-
|
|
861
|
-
|
|
862
|
-
|
|
863
|
-
|
|
864
|
-
(
|
|
865
|
-
let
|
|
866
|
-
|
|
867
|
-
|
|
868
|
-
|
|
869
|
-
|
|
870
|
-
|
|
871
|
-
|
|
872
|
-
|
|
873
|
-
|
|
874
|
-
resolve({
|
|
875
|
-
...res,
|
|
876
|
-
body: parsedData,
|
|
877
|
-
});
|
|
667
|
+
(0, _https.get)(TIMEZONE_URL, {
|
|
668
|
+
agent,
|
|
669
|
+
timeout: 10000
|
|
670
|
+
}, res => {
|
|
671
|
+
let resultResponse = '';
|
|
672
|
+
res.on('data', data => resultResponse += data);
|
|
673
|
+
res.on('end', () => {
|
|
674
|
+
let parsedData;
|
|
675
|
+
try {
|
|
676
|
+
parsedData = JSON.parse(resultResponse);
|
|
677
|
+
} catch (e) {
|
|
678
|
+
reject(e);
|
|
679
|
+
}
|
|
680
|
+
resolve({
|
|
681
|
+
...res,
|
|
682
|
+
body: parsedData
|
|
878
683
|
});
|
|
879
|
-
}
|
|
880
|
-
).on(
|
|
684
|
+
});
|
|
685
|
+
}).on('error', err => reject(err));
|
|
881
686
|
});
|
|
882
687
|
body = checkData.body || {};
|
|
883
|
-
if (!body.ip && checkData.statusCode.toString().startsWith(
|
|
688
|
+
if (!body.ip && checkData.statusCode.toString().startsWith('4')) {
|
|
884
689
|
throw checkData;
|
|
885
690
|
}
|
|
886
|
-
debug(
|
|
691
|
+
debug('getTimeZone finish', body.body);
|
|
887
692
|
this._tz = body;
|
|
888
693
|
return this._tz.timezone;
|
|
889
694
|
}
|
|
890
695
|
async spawnArguments() {
|
|
891
696
|
const profile_path = this.profilePath();
|
|
892
|
-
let {
|
|
697
|
+
let {
|
|
698
|
+
proxy
|
|
699
|
+
} = this;
|
|
893
700
|
proxy = `${proxy.mode}://${proxy.host}:${proxy.port}`;
|
|
894
701
|
const env = {};
|
|
895
|
-
Object.keys(process.env).forEach(
|
|
702
|
+
Object.keys(process.env).forEach(key => {
|
|
896
703
|
env[key] = process.env[key];
|
|
897
704
|
});
|
|
898
|
-
const tz = await this.getTimeZone(this.proxy).catch(
|
|
899
|
-
console.error(
|
|
705
|
+
const tz = await this.getTimeZone(this.proxy).catch(e => {
|
|
706
|
+
console.error('Proxy Error. Check it and try again.');
|
|
900
707
|
throw e;
|
|
901
708
|
});
|
|
902
709
|
env.TZ = tz;
|
|
903
|
-
let params = [
|
|
904
|
-
`--proxy-server=${proxy}`,
|
|
905
|
-
`--user-data-dir=${profile_path}`,
|
|
906
|
-
"--password-store=basic",
|
|
907
|
-
`--tz=${tz}`,
|
|
908
|
-
"--lang=en",
|
|
909
|
-
];
|
|
710
|
+
let params = [`--proxy-server=${proxy}`, `--user-data-dir=${profile_path}`, '--password-store=basic', `--tz=${tz}`, '--lang=en'];
|
|
910
711
|
if (Array.isArray(this.extra_params) && this.extra_params.length) {
|
|
911
712
|
params = params.concat(this.extra_params);
|
|
912
713
|
}
|
|
@@ -916,89 +717,63 @@ class GoLogin {
|
|
|
916
717
|
return params;
|
|
917
718
|
}
|
|
918
719
|
async spawnBrowser() {
|
|
919
|
-
let {
|
|
720
|
+
let {
|
|
721
|
+
remote_debugging_port,
|
|
722
|
+
customArgs
|
|
723
|
+
} = this;
|
|
920
724
|
if (!remote_debugging_port) {
|
|
921
725
|
remote_debugging_port = await this.getRandomPort();
|
|
922
726
|
}
|
|
923
727
|
const profile_path = this.profilePath();
|
|
924
|
-
let {
|
|
925
|
-
|
|
728
|
+
let {
|
|
729
|
+
proxy
|
|
730
|
+
} = this;
|
|
731
|
+
let proxy_host = '';
|
|
926
732
|
if (proxy) {
|
|
927
733
|
proxy_host = this.proxy.host;
|
|
928
734
|
proxy = `${proxy.mode}://${proxy.host}:${proxy.port}`;
|
|
929
735
|
}
|
|
930
736
|
this.port = remote_debugging_port;
|
|
931
|
-
const ORBITA_BROWSER =
|
|
932
|
-
this.executablePath || this.browserChecker.getOrbitaPath;
|
|
737
|
+
const ORBITA_BROWSER = this.executablePath || this.browserChecker.getOrbitaPath;
|
|
933
738
|
debug(`ORBITA_BROWSER=${ORBITA_BROWSER}`);
|
|
934
739
|
const env = {};
|
|
935
|
-
Object.keys(process.env).forEach(
|
|
740
|
+
Object.keys(process.env).forEach(key => {
|
|
936
741
|
env[key] = process.env[key];
|
|
937
742
|
});
|
|
938
|
-
const tz = await this.getTimeZone(this.proxy).catch(
|
|
939
|
-
console.error(
|
|
743
|
+
const tz = await this.getTimeZone(this.proxy).catch(e => {
|
|
744
|
+
console.error('Proxy Error. Check it and try again.');
|
|
940
745
|
throw e;
|
|
941
746
|
});
|
|
942
747
|
env.TZ = tz;
|
|
943
748
|
if (this.vnc_port) {
|
|
944
|
-
const script_path = (0, _path.resolve)(__dirname,
|
|
945
|
-
debug(
|
|
946
|
-
|
|
947
|
-
|
|
948
|
-
|
|
949
|
-
remote_debugging_port,
|
|
950
|
-
proxy,
|
|
951
|
-
profile_path,
|
|
952
|
-
this.vnc_port
|
|
953
|
-
);
|
|
954
|
-
(0, _child_process.execFile)(
|
|
955
|
-
script_path,
|
|
956
|
-
[
|
|
957
|
-
ORBITA_BROWSER,
|
|
958
|
-
remote_debugging_port,
|
|
959
|
-
proxy,
|
|
960
|
-
profile_path,
|
|
961
|
-
this.vnc_port,
|
|
962
|
-
tz,
|
|
963
|
-
],
|
|
964
|
-
{
|
|
965
|
-
env,
|
|
966
|
-
}
|
|
967
|
-
);
|
|
749
|
+
const script_path = (0, _path.resolve)(__dirname, './run.sh');
|
|
750
|
+
debug('RUNNING', script_path, ORBITA_BROWSER, remote_debugging_port, proxy, profile_path, this.vnc_port);
|
|
751
|
+
(0, _child_process.execFile)(script_path, [ORBITA_BROWSER, remote_debugging_port, proxy, profile_path, this.vnc_port, tz], {
|
|
752
|
+
env
|
|
753
|
+
});
|
|
968
754
|
} else {
|
|
969
|
-
let params = [
|
|
970
|
-
`--remote-debugging-port=${remote_debugging_port}`,
|
|
971
|
-
`--user-data-dir=${profile_path}`,
|
|
972
|
-
"--password-store=basic",
|
|
973
|
-
`--tz=${tz}`,
|
|
974
|
-
`--lang=${this.browserLang}`,
|
|
975
|
-
];
|
|
755
|
+
let params = [`--remote-debugging-port=${remote_debugging_port}`, `--user-data-dir=${profile_path}`, '--password-store=basic', `--tz=${tz}`, `--lang=${this.browserLang}`];
|
|
976
756
|
if (this.extensionPathsToInstall.length) {
|
|
977
757
|
if (Array.isArray(this.extra_params) && this.extra_params.length) {
|
|
978
758
|
this.extra_params.forEach((param, index) => {
|
|
979
|
-
if (!param.includes(
|
|
759
|
+
if (!param.includes('--load-extension=')) {
|
|
980
760
|
return;
|
|
981
761
|
}
|
|
982
|
-
const [_, extPathsString] = param.split(
|
|
983
|
-
const extPathsArray = extPathsString.split(
|
|
984
|
-
this.extensionPathsToInstall = [
|
|
985
|
-
...this.extensionPathsToInstall,
|
|
986
|
-
...extPathsArray,
|
|
987
|
-
];
|
|
762
|
+
const [_, extPathsString] = param.split('=');
|
|
763
|
+
const extPathsArray = extPathsString.split(',');
|
|
764
|
+
this.extensionPathsToInstall = [...this.extensionPathsToInstall, ...extPathsArray];
|
|
988
765
|
this.extra_params.splice(index, 1);
|
|
989
766
|
});
|
|
990
767
|
}
|
|
991
|
-
params.push(
|
|
992
|
-
`--load-extension=${this.extensionPathsToInstall.join(",")}`
|
|
993
|
-
);
|
|
768
|
+
params.push(`--load-extension=${this.extensionPathsToInstall.join(',')}`);
|
|
994
769
|
}
|
|
995
770
|
if (this.fontsMasking) {
|
|
996
|
-
let arg =
|
|
771
|
+
let arg = '--font-masking-mode=2';
|
|
997
772
|
if (this.differentOs) {
|
|
998
|
-
arg =
|
|
773
|
+
arg = '--font-masking-mode=3';
|
|
999
774
|
}
|
|
1000
|
-
if (this.profileOs ===
|
|
1001
|
-
arg =
|
|
775
|
+
if (this.profileOs === 'android') {
|
|
776
|
+
arg = '--font-masking-mode=1';
|
|
1002
777
|
}
|
|
1003
778
|
params.push(arg);
|
|
1004
779
|
}
|
|
@@ -1011,55 +786,44 @@ class GoLogin {
|
|
|
1011
786
|
params = params.concat(this.extra_params);
|
|
1012
787
|
}
|
|
1013
788
|
if (this.restoreLastSession) {
|
|
1014
|
-
params.push(
|
|
789
|
+
params.push('--restore-last-session');
|
|
1015
790
|
}
|
|
1016
791
|
params.push(...new Set(customArgs));
|
|
1017
792
|
console.log(params);
|
|
1018
793
|
const child = (0, _child_process.execFile)(ORBITA_BROWSER, params, {
|
|
1019
|
-
env
|
|
794
|
+
env
|
|
1020
795
|
});
|
|
1021
796
|
this.processSpawned = child;
|
|
1022
797
|
// const child = spawn(ORBITA_BROWSER, params, { env, shell: true });
|
|
1023
|
-
child.stdout.on(
|
|
1024
|
-
debug(
|
|
798
|
+
child.stdout.on('data', data => debug(data.toString()));
|
|
799
|
+
debug('SPAWN CMD', ORBITA_BROWSER, params.join(' '));
|
|
1025
800
|
}
|
|
1026
801
|
if (this.waitWebsocket) {
|
|
1027
|
-
debug(
|
|
1028
|
-
const data = await _requestretry.default.get(
|
|
1029
|
-
|
|
1030
|
-
|
|
1031
|
-
|
|
1032
|
-
}
|
|
1033
|
-
);
|
|
1034
|
-
debug("WS IS", (0, _utils2.get)(data, "body.webSocketDebuggerUrl", ""));
|
|
802
|
+
debug('GETTING WS URL FROM BROWSER');
|
|
803
|
+
const data = await _requestretry.default.get(`http://127.0.0.1:${remote_debugging_port}/json/version`, {
|
|
804
|
+
json: true
|
|
805
|
+
});
|
|
806
|
+
debug('WS IS', (0, _utils2.get)(data, 'body.webSocketDebuggerUrl', ''));
|
|
1035
807
|
this.is_active = true;
|
|
1036
|
-
return (0, _utils2.get)(data,
|
|
808
|
+
return (0, _utils2.get)(data, 'body.webSocketDebuggerUrl', '');
|
|
1037
809
|
}
|
|
1038
|
-
return
|
|
810
|
+
return '';
|
|
1039
811
|
}
|
|
1040
812
|
async createStartupAndSpawnBrowser() {
|
|
1041
813
|
await this.createStartup();
|
|
1042
814
|
return this.spawnBrowser();
|
|
1043
815
|
}
|
|
1044
816
|
async clearProfileFiles() {
|
|
1045
|
-
await (0, _rimraf.default)(
|
|
1046
|
-
|
|
1047
|
-
() => null
|
|
1048
|
-
);
|
|
1049
|
-
await (0, _rimraf.default)(
|
|
1050
|
-
(0, _path.join)(this.tmpdir, `gologin_${this.profile_id}_upload.zip`),
|
|
1051
|
-
() => null
|
|
1052
|
-
);
|
|
817
|
+
await (0, _rimraf.default)((0, _path.join)(this.tmpdir, `gologin_profile_${this.profile_id}`), () => null);
|
|
818
|
+
await (0, _rimraf.default)((0, _path.join)(this.tmpdir, `gologin_${this.profile_id}_upload.zip`), () => null);
|
|
1053
819
|
}
|
|
1054
820
|
async stopAndCommit(options, local = false) {
|
|
1055
821
|
if (this.is_stopping) {
|
|
1056
822
|
return true;
|
|
1057
823
|
}
|
|
1058
|
-
const is_posting =
|
|
1059
|
-
|
|
1060
|
-
|
|
1061
|
-
// backward compability
|
|
1062
|
-
false;
|
|
824
|
+
const is_posting = options.posting || options.postings ||
|
|
825
|
+
// backward compability
|
|
826
|
+
false;
|
|
1063
827
|
if (this.uploadCookiesToServer) {
|
|
1064
828
|
await this.uploadProfileCookiesToServer();
|
|
1065
829
|
}
|
|
@@ -1074,26 +838,19 @@ class GoLogin {
|
|
|
1074
838
|
await delay(3000);
|
|
1075
839
|
await this.clearProfileFiles();
|
|
1076
840
|
if (!local) {
|
|
1077
|
-
await (0, _rimraf.default)(
|
|
1078
|
-
(0, _path.join)(this.tmpdir, `gologin_${this.profile_id}.zip`),
|
|
1079
|
-
() => null
|
|
1080
|
-
);
|
|
841
|
+
await (0, _rimraf.default)((0, _path.join)(this.tmpdir, `gologin_${this.profile_id}.zip`), () => null);
|
|
1081
842
|
}
|
|
1082
843
|
debug(`PROFILE ${this.profile_id} STOPPED AND CLEAR`);
|
|
1083
844
|
return false;
|
|
1084
845
|
}
|
|
1085
846
|
async stopBrowser() {
|
|
1086
847
|
if (!this.port) {
|
|
1087
|
-
throw new Error(
|
|
848
|
+
throw new Error('Empty GoLogin port');
|
|
1088
849
|
}
|
|
1089
|
-
const ls = await (0, _child_process.spawn)(
|
|
1090
|
-
|
|
1091
|
-
|
|
1092
|
-
|
|
1093
|
-
shell: true,
|
|
1094
|
-
}
|
|
1095
|
-
);
|
|
1096
|
-
debug("browser killed");
|
|
850
|
+
const ls = await (0, _child_process.spawn)('fuser', ['-k TERM', `-n tcp ${this.port}`], {
|
|
851
|
+
shell: true
|
|
852
|
+
});
|
|
853
|
+
debug('browser killed');
|
|
1097
854
|
}
|
|
1098
855
|
killBrowser() {
|
|
1099
856
|
if (!this.processSpawned.pid) {
|
|
@@ -1101,7 +858,7 @@ class GoLogin {
|
|
|
1101
858
|
}
|
|
1102
859
|
try {
|
|
1103
860
|
this.processSpawned.kill();
|
|
1104
|
-
debug(
|
|
861
|
+
debug('browser killed');
|
|
1105
862
|
} catch (error) {
|
|
1106
863
|
console.error(error);
|
|
1107
864
|
}
|
|
@@ -1112,255 +869,199 @@ class GoLogin {
|
|
|
1112
869
|
await this.stopAndCommit(options, local).catch(console.error);
|
|
1113
870
|
}
|
|
1114
871
|
async sanitizeProfile() {
|
|
1115
|
-
const remove_dirs = [
|
|
1116
|
-
`${SEPARATOR}Default${SEPARATOR}Cache`,
|
|
1117
|
-
`${SEPARATOR}Default${SEPARATOR}Service Worker`,
|
|
1118
|
-
`${SEPARATOR}Default${SEPARATOR}Code Cache`,
|
|
1119
|
-
`${SEPARATOR}Default${SEPARATOR}GPUCache`,
|
|
1120
|
-
`${SEPARATOR}Default${SEPARATOR}Extensions`,
|
|
1121
|
-
`${SEPARATOR}Default${SEPARATOR}IndexedDB`,
|
|
1122
|
-
`${SEPARATOR}Default${SEPARATOR}GPUCache`,
|
|
1123
|
-
`${SEPARATOR}Default${SEPARATOR}DawnCache`,
|
|
1124
|
-
`${SEPARATOR}Default${SEPARATOR}fonts_config`,
|
|
1125
|
-
`${SEPARATOR}GrShaderCache`,
|
|
1126
|
-
`${SEPARATOR}ShaderCache`,
|
|
1127
|
-
`${SEPARATOR}biahpgbdmdkfgndcmfiipgcebobojjkp`,
|
|
1128
|
-
`${SEPARATOR}afalakplffnnnlkncjhbmahjfjhmlkal`,
|
|
1129
|
-
`${SEPARATOR}cffkpbalmllkdoenhmdmpbkajipdjfam`,
|
|
1130
|
-
`${SEPARATOR}Dictionaries`,
|
|
1131
|
-
`${SEPARATOR}enkheaiicpeffbfgjiklngbpkilnbkoi`,
|
|
1132
|
-
`${SEPARATOR}oofiananboodjbbmdelgdommihjbkfag`,
|
|
1133
|
-
`${SEPARATOR}SafetyTips`,
|
|
1134
|
-
`${SEPARATOR}fonts`,
|
|
1135
|
-
`${SEPARATOR}BrowserMetrics`,
|
|
1136
|
-
`${SEPARATOR}BrowserMetrics-spare.pma`,
|
|
1137
|
-
];
|
|
872
|
+
const remove_dirs = [`${SEPARATOR}Default${SEPARATOR}Cache`, `${SEPARATOR}Default${SEPARATOR}Service Worker`, `${SEPARATOR}Default${SEPARATOR}Code Cache`, `${SEPARATOR}Default${SEPARATOR}GPUCache`, `${SEPARATOR}Default${SEPARATOR}Extensions`, `${SEPARATOR}Default${SEPARATOR}IndexedDB`, `${SEPARATOR}Default${SEPARATOR}GPUCache`, `${SEPARATOR}Default${SEPARATOR}DawnCache`, `${SEPARATOR}Default${SEPARATOR}fonts_config`, `${SEPARATOR}GrShaderCache`, `${SEPARATOR}ShaderCache`, `${SEPARATOR}biahpgbdmdkfgndcmfiipgcebobojjkp`, `${SEPARATOR}afalakplffnnnlkncjhbmahjfjhmlkal`, `${SEPARATOR}cffkpbalmllkdoenhmdmpbkajipdjfam`, `${SEPARATOR}Dictionaries`, `${SEPARATOR}enkheaiicpeffbfgjiklngbpkilnbkoi`, `${SEPARATOR}oofiananboodjbbmdelgdommihjbkfag`, `${SEPARATOR}SafetyTips`, `${SEPARATOR}fonts`, `${SEPARATOR}BrowserMetrics`, `${SEPARATOR}BrowserMetrics-spare.pma`];
|
|
1138
873
|
const that = this;
|
|
1139
|
-
await Promise.all(
|
|
1140
|
-
|
|
1141
|
-
|
|
1142
|
-
|
|
1143
|
-
|
|
1144
|
-
|
|
1145
|
-
|
|
1146
|
-
|
|
1147
|
-
|
|
1148
|
-
},
|
|
1149
|
-
(e) => {
|
|
1150
|
-
// debug('DROPPING RESULT', e);
|
|
1151
|
-
resolve();
|
|
1152
|
-
}
|
|
1153
|
-
);
|
|
874
|
+
await Promise.all(remove_dirs.map(d => {
|
|
875
|
+
const path_to_remove = `${that.profilePath()}${d}`;
|
|
876
|
+
return new Promise(resolve => {
|
|
877
|
+
debug('DROPPING', path_to_remove);
|
|
878
|
+
(0, _rimraf.default)(path_to_remove, {
|
|
879
|
+
maxBusyTries: 100
|
|
880
|
+
}, e => {
|
|
881
|
+
// debug('DROPPING RESULT', e);
|
|
882
|
+
resolve();
|
|
1154
883
|
});
|
|
1155
|
-
})
|
|
1156
|
-
);
|
|
884
|
+
});
|
|
885
|
+
}));
|
|
1157
886
|
}
|
|
1158
887
|
async getProfileDataToUpdate() {
|
|
1159
|
-
const zipPath = (0, _path.join)(
|
|
1160
|
-
|
|
1161
|
-
`gologin_${this.profile_id}_upload.zip`
|
|
1162
|
-
);
|
|
1163
|
-
const zipExists = await access(zipPath)
|
|
1164
|
-
.then(() => true)
|
|
1165
|
-
.catch(() => false);
|
|
888
|
+
const zipPath = (0, _path.join)(this.tmpdir, `gologin_${this.profile_id}_upload.zip`);
|
|
889
|
+
const zipExists = await access(zipPath).then(() => true).catch(() => false);
|
|
1166
890
|
if (zipExists) {
|
|
1167
891
|
await unlink(zipPath);
|
|
1168
892
|
}
|
|
1169
893
|
await this.sanitizeProfile();
|
|
1170
|
-
debug(
|
|
894
|
+
debug('profile sanitized');
|
|
1171
895
|
const profilePath = this.profilePath();
|
|
1172
896
|
const fileBuff = await (0, _profileArchiver.archiveProfile)(profilePath);
|
|
1173
|
-
debug(
|
|
897
|
+
debug('PROFILE ZIP CREATED', profilePath, zipPath);
|
|
1174
898
|
return fileBuff;
|
|
1175
899
|
}
|
|
1176
900
|
async profileExists() {
|
|
1177
|
-
const profileResponse = await _requestretry.default.post(
|
|
1178
|
-
|
|
1179
|
-
|
|
1180
|
-
|
|
1181
|
-
|
|
1182
|
-
|
|
1183
|
-
|
|
1184
|
-
json: {},
|
|
1185
|
-
}
|
|
1186
|
-
);
|
|
901
|
+
const profileResponse = await _requestretry.default.post(`${_common.API_URL}/browser`, {
|
|
902
|
+
headers: {
|
|
903
|
+
'Authorization': `Bearer ${this.access_token}`,
|
|
904
|
+
'User-Agent': 'gologin-api'
|
|
905
|
+
},
|
|
906
|
+
json: {}
|
|
907
|
+
});
|
|
1187
908
|
if (profileResponse.statusCode !== 200) {
|
|
1188
909
|
return false;
|
|
1189
910
|
}
|
|
1190
|
-
debug(
|
|
911
|
+
debug('profile is', profileResponse.body);
|
|
1191
912
|
return true;
|
|
1192
913
|
}
|
|
1193
914
|
async getRandomFingerprint(options) {
|
|
1194
|
-
let os =
|
|
915
|
+
let os = 'lin';
|
|
1195
916
|
if (options.os) {
|
|
1196
917
|
os = options.os;
|
|
1197
918
|
}
|
|
1198
919
|
let url = `${_common.API_URL}/browser/fingerprint?os=${os}`;
|
|
1199
920
|
if (options.isM1) {
|
|
1200
|
-
url +=
|
|
921
|
+
url += '&isM1=true';
|
|
1201
922
|
}
|
|
1202
923
|
const fingerprint = await _requestretry.default.get(url, {
|
|
1203
924
|
headers: {
|
|
1204
|
-
Authorization: `Bearer ${this.access_token}`,
|
|
1205
|
-
|
|
1206
|
-
}
|
|
925
|
+
'Authorization': `Bearer ${this.access_token}`,
|
|
926
|
+
'User-Agent': 'gologin-api'
|
|
927
|
+
}
|
|
1207
928
|
});
|
|
1208
929
|
return JSON.parse(fingerprint.body);
|
|
1209
930
|
}
|
|
1210
931
|
async create(options) {
|
|
1211
|
-
debug(
|
|
932
|
+
debug('createProfile', options);
|
|
1212
933
|
const fingerprint = await this.getRandomFingerprint(options);
|
|
1213
|
-
debug(
|
|
934
|
+
debug('fingerprint=', fingerprint);
|
|
1214
935
|
if (fingerprint.statusCode === 500) {
|
|
1215
|
-
throw new Error(
|
|
936
|
+
throw new Error('no valid random fingerprint check os param');
|
|
1216
937
|
}
|
|
1217
938
|
if (fingerprint.statusCode === 401) {
|
|
1218
|
-
throw new Error(
|
|
939
|
+
throw new Error('invalid token');
|
|
1219
940
|
}
|
|
1220
|
-
const {
|
|
941
|
+
const {
|
|
942
|
+
navigator,
|
|
943
|
+
fonts,
|
|
944
|
+
webGLMetadata,
|
|
945
|
+
webRTC
|
|
946
|
+
} = fingerprint;
|
|
1221
947
|
let deviceMemory = navigator.deviceMemory || 2;
|
|
1222
948
|
if (deviceMemory < 1) {
|
|
1223
949
|
deviceMemory = 1;
|
|
1224
950
|
}
|
|
1225
951
|
navigator.deviceMemory = deviceMemory * 1024;
|
|
1226
|
-
webGLMetadata.mode = webGLMetadata.mode ===
|
|
952
|
+
webGLMetadata.mode = webGLMetadata.mode === 'noise' ? 'mask' : 'off';
|
|
1227
953
|
const json = {
|
|
1228
954
|
...fingerprint,
|
|
1229
955
|
navigator,
|
|
1230
956
|
webGLMetadata,
|
|
1231
|
-
browserType:
|
|
1232
|
-
name:
|
|
1233
|
-
notes:
|
|
957
|
+
browserType: 'chrome',
|
|
958
|
+
name: 'default_name',
|
|
959
|
+
notes: 'auto generated',
|
|
1234
960
|
fonts: {
|
|
1235
|
-
families: fonts
|
|
961
|
+
families: fonts
|
|
1236
962
|
},
|
|
1237
963
|
webRTC: {
|
|
1238
964
|
...webRTC,
|
|
1239
|
-
mode:
|
|
1240
|
-
}
|
|
965
|
+
mode: 'alerted'
|
|
966
|
+
}
|
|
1241
967
|
};
|
|
1242
968
|
const user_agent = options.navigator?.userAgent;
|
|
1243
969
|
const orig_user_agent = json.navigator.userAgent;
|
|
1244
|
-
Object.keys(options).forEach(
|
|
1245
|
-
if (typeof json[key] ===
|
|
970
|
+
Object.keys(options).forEach(key => {
|
|
971
|
+
if (typeof json[key] === 'object') {
|
|
1246
972
|
json[key] = {
|
|
1247
973
|
...json[key],
|
|
1248
|
-
...options[key]
|
|
974
|
+
...options[key]
|
|
1249
975
|
};
|
|
1250
976
|
return;
|
|
1251
977
|
}
|
|
1252
978
|
json[key] = options[key];
|
|
1253
979
|
});
|
|
1254
|
-
if (user_agent ===
|
|
980
|
+
if (user_agent === 'random') {
|
|
1255
981
|
json.navigator.userAgent = orig_user_agent;
|
|
1256
982
|
}
|
|
1257
|
-
const response = await _requestretry.default.post(
|
|
1258
|
-
|
|
1259
|
-
|
|
1260
|
-
|
|
1261
|
-
|
|
1262
|
-
|
|
1263
|
-
|
|
1264
|
-
json,
|
|
1265
|
-
}
|
|
1266
|
-
);
|
|
983
|
+
const response = await _requestretry.default.post(`${_common.API_URL}/browser`, {
|
|
984
|
+
headers: {
|
|
985
|
+
'Authorization': `Bearer ${this.access_token}`,
|
|
986
|
+
'User-Agent': 'gologin-api'
|
|
987
|
+
},
|
|
988
|
+
json
|
|
989
|
+
});
|
|
1267
990
|
if (response.statusCode === 400) {
|
|
1268
|
-
throw new Error(
|
|
1269
|
-
`gologin failed account creation with status code, ${
|
|
1270
|
-
response.statusCode
|
|
1271
|
-
} DATA ${JSON.stringify(response.body.message)}`
|
|
1272
|
-
);
|
|
991
|
+
throw new Error(`gologin failed account creation with status code, ${response.statusCode} DATA ${JSON.stringify(response.body.message)}`);
|
|
1273
992
|
}
|
|
1274
993
|
if (response.statusCode === 500) {
|
|
1275
|
-
throw new Error(
|
|
1276
|
-
`gologin failed account creation with status code, ${response.statusCode}`
|
|
1277
|
-
);
|
|
994
|
+
throw new Error(`gologin failed account creation with status code, ${response.statusCode}`);
|
|
1278
995
|
}
|
|
1279
996
|
debug(JSON.stringify(response.body));
|
|
1280
997
|
return response.body.id;
|
|
1281
998
|
}
|
|
1282
999
|
async createCustom(options) {
|
|
1283
|
-
debug(
|
|
1284
|
-
const response = await _requestretry.default.post(
|
|
1285
|
-
|
|
1286
|
-
|
|
1287
|
-
|
|
1288
|
-
|
|
1289
|
-
|
|
1290
|
-
|
|
1291
|
-
json: options,
|
|
1292
|
-
}
|
|
1293
|
-
);
|
|
1000
|
+
debug('createCustomProfile', options);
|
|
1001
|
+
const response = await _requestretry.default.post(`${_common.API_URL}/browser/custom`, {
|
|
1002
|
+
headers: {
|
|
1003
|
+
'Authorization': `Bearer ${this.access_token}`,
|
|
1004
|
+
'User-Agent': 'gologin-api'
|
|
1005
|
+
},
|
|
1006
|
+
json: options
|
|
1007
|
+
});
|
|
1294
1008
|
if (response.statusCode === 400) {
|
|
1295
|
-
throw new Error(
|
|
1296
|
-
`gologin failed account creation with status code, ${
|
|
1297
|
-
response.statusCode
|
|
1298
|
-
} DATA ${JSON.stringify(response.body.message)}`
|
|
1299
|
-
);
|
|
1009
|
+
throw new Error(`gologin failed account creation with status code, ${response.statusCode} DATA ${JSON.stringify(response.body.message)}`);
|
|
1300
1010
|
}
|
|
1301
1011
|
if (response.statusCode === 500) {
|
|
1302
|
-
throw new Error(
|
|
1303
|
-
`gologin failed account creation with status code, ${response.statusCode}`
|
|
1304
|
-
);
|
|
1012
|
+
throw new Error(`gologin failed account creation with status code, ${response.statusCode}`);
|
|
1305
1013
|
}
|
|
1306
1014
|
debug(JSON.stringify(response));
|
|
1307
1015
|
return response.body.id;
|
|
1308
1016
|
}
|
|
1309
|
-
async quickCreateProfile(name =
|
|
1017
|
+
async quickCreateProfile(name = '') {
|
|
1310
1018
|
const osInfo = await (0, _common.getOsAdvanced)();
|
|
1311
|
-
const {
|
|
1312
|
-
|
|
1313
|
-
|
|
1314
|
-
|
|
1315
|
-
|
|
1316
|
-
|
|
1317
|
-
|
|
1318
|
-
}
|
|
1319
|
-
|
|
1320
|
-
|
|
1321
|
-
|
|
1322
|
-
|
|
1323
|
-
|
|
1324
|
-
|
|
1325
|
-
|
|
1019
|
+
const {
|
|
1020
|
+
os,
|
|
1021
|
+
osSpec
|
|
1022
|
+
} = osInfo;
|
|
1023
|
+
const resultName = name || 'api-generated';
|
|
1024
|
+
return _requestretry.default.post(`${_common.API_URL}/browser/quick`, {
|
|
1025
|
+
headers: {
|
|
1026
|
+
'Authorization': `Bearer ${this.access_token}`,
|
|
1027
|
+
'User-Agent': 'gologin-api'
|
|
1028
|
+
},
|
|
1029
|
+
json: {
|
|
1030
|
+
os,
|
|
1031
|
+
osSpec,
|
|
1032
|
+
name: resultName
|
|
1033
|
+
}
|
|
1034
|
+
}).then(res => res.body);
|
|
1326
1035
|
}
|
|
1327
1036
|
async delete(pid) {
|
|
1328
1037
|
const profile_id = pid || this.profile_id;
|
|
1329
|
-
await _requestretry.default.delete(
|
|
1330
|
-
|
|
1331
|
-
|
|
1332
|
-
|
|
1333
|
-
Authorization: `Bearer ${this.access_token}`,
|
|
1334
|
-
"User-Agent": "gologin-api",
|
|
1335
|
-
},
|
|
1038
|
+
await _requestretry.default.delete(`${_common.API_URL}/browser/${profile_id}`, {
|
|
1039
|
+
headers: {
|
|
1040
|
+
'Authorization': `Bearer ${this.access_token}`,
|
|
1041
|
+
'User-Agent': 'gologin-api'
|
|
1336
1042
|
}
|
|
1337
|
-
);
|
|
1043
|
+
});
|
|
1338
1044
|
}
|
|
1339
1045
|
async update(options) {
|
|
1340
1046
|
this.profile_id = options.id;
|
|
1341
1047
|
const profile = await this.getProfile();
|
|
1342
1048
|
if (options.navigator) {
|
|
1343
|
-
Object.keys(options.navigator).map(
|
|
1049
|
+
Object.keys(options.navigator).map(e => {
|
|
1344
1050
|
profile.navigator[e] = options.navigator[e];
|
|
1345
1051
|
});
|
|
1346
1052
|
}
|
|
1347
|
-
Object.keys(options)
|
|
1348
|
-
|
|
1349
|
-
|
|
1350
|
-
|
|
1351
|
-
|
|
1352
|
-
|
|
1353
|
-
|
|
1354
|
-
|
|
1355
|
-
|
|
1356
|
-
json: profile,
|
|
1357
|
-
headers: {
|
|
1358
|
-
Authorization: `Bearer ${this.access_token}`,
|
|
1359
|
-
"User-Agent": "gologin-api",
|
|
1360
|
-
},
|
|
1053
|
+
Object.keys(options).filter(el => el !== 'navigator').forEach(el => {
|
|
1054
|
+
profile[el] = options[el];
|
|
1055
|
+
});
|
|
1056
|
+
debug('update profile', profile);
|
|
1057
|
+
const response = await _requestretry.default.put(`${_common.API_URL}/browser/${options.id}`, {
|
|
1058
|
+
json: profile,
|
|
1059
|
+
headers: {
|
|
1060
|
+
'Authorization': `Bearer ${this.access_token}`,
|
|
1061
|
+
'User-Agent': 'gologin-api'
|
|
1361
1062
|
}
|
|
1362
|
-
);
|
|
1363
|
-
debug(
|
|
1063
|
+
});
|
|
1064
|
+
debug('response', JSON.stringify(response.body));
|
|
1364
1065
|
return response.body;
|
|
1365
1066
|
}
|
|
1366
1067
|
setActive(is_active) {
|
|
@@ -1372,29 +1073,25 @@ class GoLogin {
|
|
|
1372
1073
|
mode: profileGeolocationParams.mode,
|
|
1373
1074
|
latitude: Number(tzGeolocationParams.latitude),
|
|
1374
1075
|
longitude: Number(tzGeolocationParams.longitude),
|
|
1375
|
-
accuracy: Number(tzGeolocationParams.accuracy)
|
|
1076
|
+
accuracy: Number(tzGeolocationParams.accuracy)
|
|
1376
1077
|
};
|
|
1377
1078
|
}
|
|
1378
1079
|
return {
|
|
1379
1080
|
mode: profileGeolocationParams.mode,
|
|
1380
1081
|
latitude: profileGeolocationParams.latitude,
|
|
1381
1082
|
longitude: profileGeolocationParams.longitude,
|
|
1382
|
-
accuracy: profileGeolocationParams.accuracy
|
|
1083
|
+
accuracy: profileGeolocationParams.accuracy
|
|
1383
1084
|
};
|
|
1384
1085
|
}
|
|
1385
1086
|
getViewPort() {
|
|
1386
1087
|
return {
|
|
1387
|
-
...this.resolution
|
|
1088
|
+
...this.resolution
|
|
1388
1089
|
};
|
|
1389
1090
|
}
|
|
1390
1091
|
async postCookies(profileId, cookies) {
|
|
1391
|
-
const formattedCookies = cookies.map(
|
|
1392
|
-
if (
|
|
1393
|
-
|
|
1394
|
-
cookie.sameSite
|
|
1395
|
-
)
|
|
1396
|
-
) {
|
|
1397
|
-
cookie.sameSite = "unspecified";
|
|
1092
|
+
const formattedCookies = cookies.map(cookie => {
|
|
1093
|
+
if (!['no_restriction', 'lax', 'strict', 'unspecified'].includes(cookie.sameSite)) {
|
|
1094
|
+
cookie.sameSite = 'unspecified';
|
|
1398
1095
|
}
|
|
1399
1096
|
return cookie;
|
|
1400
1097
|
});
|
|
@@ -1402,45 +1099,43 @@ class GoLogin {
|
|
|
1402
1099
|
profileId,
|
|
1403
1100
|
cookies: formattedCookies,
|
|
1404
1101
|
API_BASE_URL: _common.API_URL,
|
|
1405
|
-
ACCESS_TOKEN: this.access_token
|
|
1102
|
+
ACCESS_TOKEN: this.access_token
|
|
1406
1103
|
});
|
|
1407
1104
|
if (response.statusCode === 200) {
|
|
1408
1105
|
return response.body;
|
|
1409
1106
|
}
|
|
1410
1107
|
return {
|
|
1411
|
-
status:
|
|
1108
|
+
status: 'failure',
|
|
1412
1109
|
status_code: response.statusCode,
|
|
1413
|
-
body: response.body
|
|
1110
|
+
body: response.body
|
|
1414
1111
|
};
|
|
1415
1112
|
}
|
|
1416
1113
|
async getCookies(profileId) {
|
|
1417
1114
|
const response = await (0, _browserUserDataManager.downloadCookies)({
|
|
1418
1115
|
profileId,
|
|
1419
1116
|
API_BASE_URL: _common.API_URL,
|
|
1420
|
-
ACCESS_TOKEN: this.access_token
|
|
1117
|
+
ACCESS_TOKEN: this.access_token
|
|
1421
1118
|
});
|
|
1422
1119
|
return response.body;
|
|
1423
1120
|
}
|
|
1424
1121
|
async writeCookiesToFile() {
|
|
1425
1122
|
const cookies = await this.getCookies(this.profile_id);
|
|
1426
|
-
const resultCookies = cookies.map(
|
|
1123
|
+
const resultCookies = cookies.map(el => ({
|
|
1427
1124
|
...el,
|
|
1428
|
-
value: Buffer.from(el.value)
|
|
1125
|
+
value: Buffer.from(el.value)
|
|
1429
1126
|
}));
|
|
1430
1127
|
let db;
|
|
1431
1128
|
try {
|
|
1432
1129
|
db = await (0, _cookiesManager.getDB)(this.cookiesFilePath, false);
|
|
1433
1130
|
if (resultCookies.length) {
|
|
1434
|
-
const chunckInsertValues = (0, _cookiesManager.getChunckedInsertValues)(
|
|
1435
|
-
resultCookies
|
|
1436
|
-
);
|
|
1131
|
+
const chunckInsertValues = (0, _cookiesManager.getChunckedInsertValues)(resultCookies);
|
|
1437
1132
|
for (const [query, queryParams] of chunckInsertValues) {
|
|
1438
1133
|
const insertStmt = await db.prepare(query);
|
|
1439
1134
|
await insertStmt.run(queryParams);
|
|
1440
1135
|
await insertStmt.finalize();
|
|
1441
1136
|
}
|
|
1442
1137
|
} else {
|
|
1443
|
-
const query =
|
|
1138
|
+
const query = 'delete from cookies';
|
|
1444
1139
|
const insertStmt = await db.prepare(query);
|
|
1445
1140
|
await insertStmt.run();
|
|
1446
1141
|
await insertStmt.finalize();
|
|
@@ -1452,24 +1147,16 @@ class GoLogin {
|
|
|
1452
1147
|
}
|
|
1453
1148
|
}
|
|
1454
1149
|
async uploadProfileCookiesToServer() {
|
|
1455
|
-
const cookies = await (0, _cookiesManager.loadCookiesFromFile)(
|
|
1456
|
-
this.cookiesFilePath
|
|
1457
|
-
);
|
|
1150
|
+
const cookies = await (0, _cookiesManager.loadCookiesFromFile)(this.cookiesFilePath);
|
|
1458
1151
|
if (!cookies.length) {
|
|
1459
1152
|
return;
|
|
1460
1153
|
}
|
|
1461
1154
|
return this.postCookies(this.profile_id, cookies);
|
|
1462
1155
|
}
|
|
1463
1156
|
async saveBookmarksToDb() {
|
|
1464
|
-
const bookmarksData = await (0, _utils.getCurrentProfileBookmarks)(
|
|
1465
|
-
this.bookmarksFilePath
|
|
1466
|
-
);
|
|
1157
|
+
const bookmarksData = await (0, _utils.getCurrentProfileBookmarks)(this.bookmarksFilePath);
|
|
1467
1158
|
const bookmarks = bookmarksData.roots || {};
|
|
1468
|
-
await (0, _browserApi.updateProfileBookmarks)(
|
|
1469
|
-
[this.profile_id],
|
|
1470
|
-
this.access_token,
|
|
1471
|
-
bookmarks
|
|
1472
|
-
);
|
|
1159
|
+
await (0, _browserApi.updateProfileBookmarks)([this.profile_id], this.access_token, bookmarks);
|
|
1473
1160
|
}
|
|
1474
1161
|
async start() {
|
|
1475
1162
|
if (this.is_remote) {
|
|
@@ -1478,23 +1165,18 @@ class GoLogin {
|
|
|
1478
1165
|
if (!this.executablePath) {
|
|
1479
1166
|
await this.checkBrowser();
|
|
1480
1167
|
}
|
|
1481
|
-
const ORBITA_BROWSER =
|
|
1482
|
-
|
|
1483
|
-
const orbitaBrowserExists = await access(ORBITA_BROWSER)
|
|
1484
|
-
.then(() => true)
|
|
1485
|
-
.catch(() => false);
|
|
1168
|
+
const ORBITA_BROWSER = this.executablePath || this.browserChecker.getOrbitaPath;
|
|
1169
|
+
const orbitaBrowserExists = await access(ORBITA_BROWSER).then(() => true).catch(() => false);
|
|
1486
1170
|
if (!orbitaBrowserExists) {
|
|
1487
|
-
throw new Error(
|
|
1488
|
-
`Orbita browser is not exists on path ${ORBITA_BROWSER}, check executablePath param`
|
|
1489
|
-
);
|
|
1171
|
+
throw new Error(`Orbita browser is not exists on path ${ORBITA_BROWSER}, check executablePath param`);
|
|
1490
1172
|
}
|
|
1491
1173
|
await this.createStartup();
|
|
1492
1174
|
// await this.createBrowserExtension();
|
|
1493
1175
|
const wsUrl = await this.spawnBrowser();
|
|
1494
1176
|
this.setActive(true);
|
|
1495
1177
|
return {
|
|
1496
|
-
status:
|
|
1497
|
-
wsUrl
|
|
1178
|
+
status: 'success',
|
|
1179
|
+
wsUrl
|
|
1498
1180
|
};
|
|
1499
1181
|
}
|
|
1500
1182
|
async startLocal() {
|
|
@@ -1503,35 +1185,32 @@ class GoLogin {
|
|
|
1503
1185
|
const wsUrl = await this.spawnBrowser();
|
|
1504
1186
|
this.setActive(true);
|
|
1505
1187
|
return {
|
|
1506
|
-
status:
|
|
1507
|
-
wsUrl
|
|
1188
|
+
status: 'success',
|
|
1189
|
+
wsUrl
|
|
1508
1190
|
};
|
|
1509
1191
|
}
|
|
1510
1192
|
async stop() {
|
|
1511
|
-
await new Promise(
|
|
1193
|
+
await new Promise(resolve => setTimeout(resolve, 500));
|
|
1512
1194
|
if (this.is_remote) {
|
|
1513
1195
|
return this.stopRemote();
|
|
1514
1196
|
}
|
|
1515
|
-
await this.stopAndCommit(
|
|
1516
|
-
|
|
1517
|
-
|
|
1518
|
-
},
|
|
1519
|
-
false
|
|
1520
|
-
);
|
|
1197
|
+
await this.stopAndCommit({
|
|
1198
|
+
posting: true
|
|
1199
|
+
}, false);
|
|
1521
1200
|
}
|
|
1522
1201
|
async stopLocal(options) {
|
|
1523
1202
|
const opts = options || {
|
|
1524
|
-
posting: false
|
|
1203
|
+
posting: false
|
|
1525
1204
|
};
|
|
1526
1205
|
await this.stopAndCommit(opts, true);
|
|
1527
1206
|
}
|
|
1528
1207
|
async waitDebuggingUrl(delay_ms, try_count = 0, remoteOrbitaUrl) {
|
|
1529
1208
|
await delay(delay_ms);
|
|
1530
1209
|
const url = `${remoteOrbitaUrl}/json/version`;
|
|
1531
|
-
console.log(
|
|
1210
|
+
console.log('try_count=', try_count, 'url=', url);
|
|
1532
1211
|
const response = await _requestretry.default.get(url);
|
|
1533
|
-
let wsUrl =
|
|
1534
|
-
console.log(
|
|
1212
|
+
let wsUrl = '';
|
|
1213
|
+
console.log('response', response.body);
|
|
1535
1214
|
if (!response.body) {
|
|
1536
1215
|
return wsUrl;
|
|
1537
1216
|
}
|
|
@@ -1543,19 +1222,14 @@ class GoLogin {
|
|
|
1543
1222
|
return this.waitDebuggingUrl(delay_ms, try_count + 1, remoteOrbitaUrl);
|
|
1544
1223
|
}
|
|
1545
1224
|
return {
|
|
1546
|
-
status:
|
|
1225
|
+
status: 'failure',
|
|
1547
1226
|
wsUrl,
|
|
1548
|
-
message:
|
|
1549
|
-
profile_id: this.profile_id
|
|
1227
|
+
message: 'Check proxy settings',
|
|
1228
|
+
'profile_id': this.profile_id
|
|
1550
1229
|
};
|
|
1551
1230
|
}
|
|
1552
|
-
const remoteOrbitaUrlWithoutProtocol = remoteOrbitaUrl.replace(
|
|
1553
|
-
|
|
1554
|
-
""
|
|
1555
|
-
);
|
|
1556
|
-
wsUrl = wsUrl
|
|
1557
|
-
.replace("ws://", "wss://")
|
|
1558
|
-
.replace("127.0.0.1", remoteOrbitaUrlWithoutProtocol);
|
|
1231
|
+
const remoteOrbitaUrlWithoutProtocol = remoteOrbitaUrl.replace('https://', '');
|
|
1232
|
+
wsUrl = wsUrl.replace('ws://', 'wss://').replace('127.0.0.1', remoteOrbitaUrlWithoutProtocol);
|
|
1559
1233
|
return wsUrl;
|
|
1560
1234
|
}
|
|
1561
1235
|
async startRemote(delay_ms = 10000) {
|
|
@@ -1568,108 +1242,95 @@ class GoLogin {
|
|
|
1568
1242
|
*/
|
|
1569
1243
|
|
|
1570
1244
|
const profile = await this.getProfile();
|
|
1571
|
-
const profileResponse = await _requestretry.default
|
|
1572
|
-
|
|
1573
|
-
|
|
1574
|
-
|
|
1575
|
-
|
|
1576
|
-
|
|
1577
|
-
|
|
1578
|
-
|
|
1579
|
-
|
|
1580
|
-
|
|
1581
|
-
})
|
|
1582
|
-
.catch(() => null);
|
|
1245
|
+
const profileResponse = await _requestretry.default.post(`${_common.API_URL}/browser/${this.profile_id}/web`, {
|
|
1246
|
+
headers: {
|
|
1247
|
+
'Authorization': `Bearer ${this.access_token}`,
|
|
1248
|
+
'User-Agent': 'gologin-api'
|
|
1249
|
+
},
|
|
1250
|
+
json: {
|
|
1251
|
+
isNewCloudBrowser: this.isNewCloudBrowser,
|
|
1252
|
+
isHeadless: this.isCloudHeadless
|
|
1253
|
+
}
|
|
1254
|
+
}).catch(() => null);
|
|
1583
1255
|
if (!profileResponse) {
|
|
1584
|
-
throw new Error(
|
|
1256
|
+
throw new Error('invalid request');
|
|
1585
1257
|
}
|
|
1586
|
-
const {
|
|
1587
|
-
|
|
1258
|
+
const {
|
|
1259
|
+
body,
|
|
1260
|
+
statusCode
|
|
1261
|
+
} = profileResponse;
|
|
1262
|
+
debug('profileResponse', statusCode, body);
|
|
1588
1263
|
if (profileResponse.statusCode === 401) {
|
|
1589
|
-
throw new Error(
|
|
1264
|
+
throw new Error('invalid token');
|
|
1590
1265
|
}
|
|
1591
|
-
if (body.status ===
|
|
1266
|
+
if (body.status === 'profileStatuses.pending') {
|
|
1592
1267
|
return {
|
|
1593
|
-
status:
|
|
1594
|
-
message:
|
|
1268
|
+
status: 'pending',
|
|
1269
|
+
message: 'remote browser is being prepared, please try in 1 minute.'
|
|
1595
1270
|
};
|
|
1596
1271
|
}
|
|
1597
1272
|
let remoteOrbitaUrl = `https://${this.profile_id}.orbita.gologin.com`;
|
|
1598
1273
|
if (this.isNewCloudBrowser) {
|
|
1599
1274
|
if (!profileResponse.body.remoteOrbitaUrl) {
|
|
1600
|
-
throw new Error(
|
|
1275
|
+
throw new Error('Couldn\' start the remote browser');
|
|
1601
1276
|
}
|
|
1602
1277
|
remoteOrbitaUrl = profileResponse.body.remoteOrbitaUrl;
|
|
1603
1278
|
}
|
|
1604
|
-
const {
|
|
1279
|
+
const {
|
|
1280
|
+
navigator = {},
|
|
1281
|
+
fonts,
|
|
1282
|
+
os: profileOs
|
|
1283
|
+
} = profile;
|
|
1605
1284
|
this.fontsMasking = fonts?.enableMasking;
|
|
1606
1285
|
this.profileOs = profileOs;
|
|
1607
|
-
this.differentOs =
|
|
1608
|
-
|
|
1609
|
-
|
|
1610
|
-
|
|
1611
|
-
|
|
1612
|
-
const { resolution = "1920x1080", language = "en-US,en;q=0.9" } = navigator;
|
|
1286
|
+
this.differentOs = profileOs !== 'android' && (OS_PLATFORM === 'win32' && profileOs !== 'win' || OS_PLATFORM === 'darwin' && profileOs !== 'mac' || OS_PLATFORM === 'linux' && profileOs !== 'lin');
|
|
1287
|
+
const {
|
|
1288
|
+
resolution = '1920x1080',
|
|
1289
|
+
language = 'en-US,en;q=0.9'
|
|
1290
|
+
} = navigator;
|
|
1613
1291
|
this.language = language;
|
|
1614
|
-
const [screenWidth, screenHeight] = resolution.split(
|
|
1292
|
+
const [screenWidth, screenHeight] = resolution.split('x');
|
|
1615
1293
|
this.resolution = {
|
|
1616
1294
|
width: parseInt(screenWidth, 10),
|
|
1617
|
-
height: parseInt(screenHeight, 10)
|
|
1295
|
+
height: parseInt(screenHeight, 10)
|
|
1618
1296
|
};
|
|
1619
1297
|
const wsUrl = await this.waitDebuggingUrl(delay_ms, 0, remoteOrbitaUrl);
|
|
1620
|
-
if (wsUrl !==
|
|
1298
|
+
if (wsUrl !== '') {
|
|
1621
1299
|
return {
|
|
1622
|
-
status:
|
|
1623
|
-
wsUrl
|
|
1300
|
+
status: 'success',
|
|
1301
|
+
wsUrl
|
|
1624
1302
|
};
|
|
1625
1303
|
}
|
|
1626
1304
|
return {
|
|
1627
|
-
status:
|
|
1628
|
-
message: body
|
|
1305
|
+
status: 'failure',
|
|
1306
|
+
message: body
|
|
1629
1307
|
};
|
|
1630
1308
|
}
|
|
1631
1309
|
async stopRemote() {
|
|
1632
1310
|
debug(`stopRemote ${this.profile_id}`);
|
|
1633
|
-
const profileResponse = await _requestretry.default.delete(
|
|
1634
|
-
|
|
1635
|
-
|
|
1636
|
-
|
|
1637
|
-
Authorization: `Bearer ${this.access_token}`,
|
|
1638
|
-
"User-Agent": "gologin-api",
|
|
1639
|
-
},
|
|
1311
|
+
const profileResponse = await _requestretry.default.delete(`${_common.API_URL}/browser/${this.profile_id}/web?isNewCloudBrowser=${this.isNewCloudBrowser}`, {
|
|
1312
|
+
headers: {
|
|
1313
|
+
'Authorization': `Bearer ${this.access_token}`,
|
|
1314
|
+
'User-Agent': 'gologin-api'
|
|
1640
1315
|
}
|
|
1641
|
-
);
|
|
1316
|
+
});
|
|
1642
1317
|
console.log(`stopRemote ${profileResponse.body}`);
|
|
1643
1318
|
if (profileResponse.body) {
|
|
1644
1319
|
return JSON.parse(profileResponse.body);
|
|
1645
1320
|
}
|
|
1646
1321
|
}
|
|
1647
1322
|
getAvailableFonts() {
|
|
1648
|
-
return _fonts.fontsCollection
|
|
1649
|
-
.filter((elem) => elem.fileNames)
|
|
1650
|
-
.map((elem) => elem.name);
|
|
1323
|
+
return _fonts.fontsCollection.filter(elem => elem.fileNames).map(elem => elem.name);
|
|
1651
1324
|
}
|
|
1652
1325
|
async changeProfileResolution(resolution) {
|
|
1653
|
-
return (0, _browserApi.updateProfileResolution)(
|
|
1654
|
-
this.profile_id,
|
|
1655
|
-
this.access_token,
|
|
1656
|
-
resolution
|
|
1657
|
-
);
|
|
1326
|
+
return (0, _browserApi.updateProfileResolution)(this.profile_id, this.access_token, resolution);
|
|
1658
1327
|
}
|
|
1659
1328
|
async changeProfileUserAgent(userAgent) {
|
|
1660
|
-
return (0, _browserApi.updateProfileUserAgent)(
|
|
1661
|
-
this.profile_id,
|
|
1662
|
-
this.access_token,
|
|
1663
|
-
userAgent
|
|
1664
|
-
);
|
|
1329
|
+
return (0, _browserApi.updateProfileUserAgent)(this.profile_id, this.access_token, userAgent);
|
|
1665
1330
|
}
|
|
1666
1331
|
async changeProfileProxy(proxyData) {
|
|
1667
|
-
return (0, _browserApi.updateProfileProxy)(
|
|
1668
|
-
this.profile_id,
|
|
1669
|
-
this.access_token,
|
|
1670
|
-
proxyData
|
|
1671
|
-
);
|
|
1332
|
+
return (0, _browserApi.updateProfileProxy)(this.profile_id, this.access_token, proxyData);
|
|
1672
1333
|
}
|
|
1673
1334
|
}
|
|
1674
1335
|
module.exports = GoLogin;
|
|
1675
|
-
var _default =
|
|
1336
|
+
var _default = exports.default = GoLogin;
|