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