@lvce-editor/main-process 6.28.0 → 6.29.0
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/mainProcessMain.js +131 -499
- package/package.json +2 -3
package/dist/mainProcessMain.js
CHANGED
|
@@ -10,9 +10,8 @@ import * as NodePath from 'node:path';
|
|
|
10
10
|
import { dirname as dirname$1, join as join$1, isAbsolute } from 'node:path';
|
|
11
11
|
import { homedir, tmpdir } from 'node:os';
|
|
12
12
|
import { readFile } from 'node:fs/promises';
|
|
13
|
-
import { pbkdf2Sync, createDecipheriv, createHash } from 'node:crypto';
|
|
14
|
-
import { DatabaseSync } from 'node:sqlite';
|
|
15
13
|
import { MessageChannel } from 'node:worker_threads';
|
|
14
|
+
import { DatabaseSync } from 'node:sqlite';
|
|
16
15
|
|
|
17
16
|
const scheme = 'lvce-oss';
|
|
18
17
|
const applicationName = 'lvce-oss';
|
|
@@ -5038,501 +5037,6 @@ const beep$1 = () => {
|
|
|
5038
5037
|
shell.beep();
|
|
5039
5038
|
};
|
|
5040
5039
|
|
|
5041
|
-
const chromeV10Prefix = Buffer.from('v10');
|
|
5042
|
-
const chromeV11Prefix = Buffer.from('v11');
|
|
5043
|
-
const chromeV10Key = pbkdf2Sync('peanuts', 'saltysalt', 1, 16, 'sha1');
|
|
5044
|
-
const chromeV10Iv = Buffer.alloc(16, 0x20);
|
|
5045
|
-
const domainHashLength = 32;
|
|
5046
|
-
class UnsupportedChromeCookieEncryptionError extends Error {
|
|
5047
|
-
constructor() {
|
|
5048
|
-
super('Unsupported Chrome cookie encryption format');
|
|
5049
|
-
this.name = 'UnsupportedChromeCookieEncryptionError';
|
|
5050
|
-
}
|
|
5051
|
-
}
|
|
5052
|
-
const isV11 = encryptedValue => {
|
|
5053
|
-
return Buffer.from(encryptedValue).subarray(0, chromeV11Prefix.length).equals(chromeV11Prefix);
|
|
5054
|
-
};
|
|
5055
|
-
const decrypt$1 = (hostKey, encryptedValue, databaseVersion, chromeSafeStoragePassword) => {
|
|
5056
|
-
const buffer = Buffer.from(encryptedValue);
|
|
5057
|
-
if (buffer.length <= chromeV10Prefix.length) {
|
|
5058
|
-
throw new UnsupportedChromeCookieEncryptionError();
|
|
5059
|
-
}
|
|
5060
|
-
const prefix = buffer.subarray(0, chromeV10Prefix.length);
|
|
5061
|
-
let key;
|
|
5062
|
-
if (prefix.equals(chromeV10Prefix)) {
|
|
5063
|
-
key = chromeV10Key;
|
|
5064
|
-
} else if (prefix.equals(chromeV11Prefix) && chromeSafeStoragePassword !== undefined) {
|
|
5065
|
-
key = pbkdf2Sync(chromeSafeStoragePassword, 'saltysalt', 1, 16, 'sha1');
|
|
5066
|
-
} else {
|
|
5067
|
-
throw new UnsupportedChromeCookieEncryptionError();
|
|
5068
|
-
}
|
|
5069
|
-
const decipher = createDecipheriv('aes-128-cbc', key, chromeV10Iv);
|
|
5070
|
-
const plaintext = Buffer.concat([decipher.update(buffer.subarray(prefix.length)), decipher.final()]);
|
|
5071
|
-
if (databaseVersion < 24) {
|
|
5072
|
-
return plaintext.toString('utf8');
|
|
5073
|
-
}
|
|
5074
|
-
if (plaintext.length < domainHashLength) {
|
|
5075
|
-
throw new Error('Chrome cookie domain integrity check failed');
|
|
5076
|
-
}
|
|
5077
|
-
const expectedDomainHash = createHash('sha256').update(hostKey).digest();
|
|
5078
|
-
const actualDomainHash = plaintext.subarray(0, domainHashLength);
|
|
5079
|
-
if (!actualDomainHash.equals(expectedDomainHash)) {
|
|
5080
|
-
throw new Error('Chrome cookie domain integrity check failed');
|
|
5081
|
-
}
|
|
5082
|
-
return plaintext.subarray(domainHashLength).toString('utf8');
|
|
5083
|
-
};
|
|
5084
|
-
|
|
5085
|
-
const chromeEpochOffsetMicroseconds = 11_644_473_600_000_000n;
|
|
5086
|
-
const microsecondsPerSecond = 1_000_000n;
|
|
5087
|
-
const getSameSite$1 = sameSite => {
|
|
5088
|
-
switch (sameSite) {
|
|
5089
|
-
case 0:
|
|
5090
|
-
return 'no_restriction';
|
|
5091
|
-
case 1:
|
|
5092
|
-
return 'lax';
|
|
5093
|
-
case 2:
|
|
5094
|
-
return 'strict';
|
|
5095
|
-
default:
|
|
5096
|
-
return 'unspecified';
|
|
5097
|
-
}
|
|
5098
|
-
};
|
|
5099
|
-
const getExpirationDate = expiresUtc => {
|
|
5100
|
-
const chromeMicroseconds = BigInt(expiresUtc);
|
|
5101
|
-
return Number(chromeMicroseconds - chromeEpochOffsetMicroseconds) / Number(microsecondsPerSecond);
|
|
5102
|
-
};
|
|
5103
|
-
const getValue = (row, databaseVersion, chromeSafeStoragePassword) => {
|
|
5104
|
-
if (row.value) {
|
|
5105
|
-
return row.value;
|
|
5106
|
-
}
|
|
5107
|
-
return decrypt$1(row.hostKey, row.encryptedValue, databaseVersion, chromeSafeStoragePassword);
|
|
5108
|
-
};
|
|
5109
|
-
const convert$1 = (row, databaseVersion, chromeSafeStoragePassword, now = Date.now() / 1000) => {
|
|
5110
|
-
if (!row.hostKey || row.topFrameSiteKey) {
|
|
5111
|
-
return undefined;
|
|
5112
|
-
}
|
|
5113
|
-
const host = row.hostKey.startsWith('.') ? row.hostKey.slice(1) : row.hostKey;
|
|
5114
|
-
if (!host) {
|
|
5115
|
-
return undefined;
|
|
5116
|
-
}
|
|
5117
|
-
const secure = Boolean(row.isSecure);
|
|
5118
|
-
const details = {
|
|
5119
|
-
httpOnly: Boolean(row.isHttpOnly),
|
|
5120
|
-
name: row.name,
|
|
5121
|
-
path: row.path || '/',
|
|
5122
|
-
sameSite: getSameSite$1(row.sameSite),
|
|
5123
|
-
secure,
|
|
5124
|
-
url: `${secure ? 'https' : 'http'}://${host}/`,
|
|
5125
|
-
value: getValue(row, databaseVersion, chromeSafeStoragePassword)
|
|
5126
|
-
};
|
|
5127
|
-
if (row.hostKey.startsWith('.')) {
|
|
5128
|
-
details.domain = row.hostKey;
|
|
5129
|
-
}
|
|
5130
|
-
if (row.hasExpires) {
|
|
5131
|
-
const expirationDate = getExpirationDate(row.expiresUtc);
|
|
5132
|
-
if (!Number.isFinite(expirationDate) || expirationDate <= now) {
|
|
5133
|
-
return undefined;
|
|
5134
|
-
}
|
|
5135
|
-
details.expirationDate = expirationDate;
|
|
5136
|
-
}
|
|
5137
|
-
return details;
|
|
5138
|
-
};
|
|
5139
|
-
|
|
5140
|
-
/* eslint-disable n/no-unsupported-features/node-builtins -- Electron 43 provides the node:sqlite API used by the main process */
|
|
5141
|
-
const getDatabaseError$1 = error => {
|
|
5142
|
-
const message = error instanceof Error ? error.message : String(error);
|
|
5143
|
-
if (message.toLowerCase().includes('locked') || message.toLowerCase().includes('busy')) {
|
|
5144
|
-
return new Error('Chrome cookie database is busy. Close Chrome and try again.');
|
|
5145
|
-
}
|
|
5146
|
-
return new Error('Failed to read the Chrome cookie database');
|
|
5147
|
-
};
|
|
5148
|
-
const withDatabase$1 = (path, fn) => {
|
|
5149
|
-
let database;
|
|
5150
|
-
try {
|
|
5151
|
-
database = new DatabaseSync(path, {
|
|
5152
|
-
readOnly: true
|
|
5153
|
-
});
|
|
5154
|
-
database.exec('PRAGMA busy_timeout = 1000');
|
|
5155
|
-
return fn(database);
|
|
5156
|
-
} catch (error) {
|
|
5157
|
-
if (error instanceof Error && error.message.startsWith('Unsupported Chrome cookie database version')) {
|
|
5158
|
-
throw error;
|
|
5159
|
-
}
|
|
5160
|
-
throw getDatabaseError$1(error);
|
|
5161
|
-
} finally {
|
|
5162
|
-
database?.close();
|
|
5163
|
-
}
|
|
5164
|
-
};
|
|
5165
|
-
const getVersion$1 = database => {
|
|
5166
|
-
const row = database.prepare(`SELECT value FROM meta WHERE key = 'version'`).get();
|
|
5167
|
-
const version = Number(row?.value);
|
|
5168
|
-
if (version !== 24) {
|
|
5169
|
-
throw new Error(`Unsupported Chrome cookie database version ${Number.isFinite(version) ? version : 'unknown'}`);
|
|
5170
|
-
}
|
|
5171
|
-
return version;
|
|
5172
|
-
};
|
|
5173
|
-
const getCookieCount$1 = path => {
|
|
5174
|
-
return withDatabase$1(path, database => {
|
|
5175
|
-
getVersion$1(database);
|
|
5176
|
-
const row = database.prepare('SELECT COUNT(*) AS count FROM cookies').get();
|
|
5177
|
-
return row.count;
|
|
5178
|
-
});
|
|
5179
|
-
};
|
|
5180
|
-
const readCookies$1 = path => {
|
|
5181
|
-
return withDatabase$1(path, database => {
|
|
5182
|
-
const version = getVersion$1(database);
|
|
5183
|
-
const rows = database.prepare(`
|
|
5184
|
-
SELECT
|
|
5185
|
-
encrypted_value AS encryptedValue,
|
|
5186
|
-
CAST(expires_utc AS TEXT) AS expiresUtc,
|
|
5187
|
-
has_expires AS hasExpires,
|
|
5188
|
-
host_key AS hostKey,
|
|
5189
|
-
is_httponly AS isHttpOnly,
|
|
5190
|
-
is_secure AS isSecure,
|
|
5191
|
-
name,
|
|
5192
|
-
path,
|
|
5193
|
-
samesite AS sameSite,
|
|
5194
|
-
top_frame_site_key AS topFrameSiteKey,
|
|
5195
|
-
value
|
|
5196
|
-
FROM cookies
|
|
5197
|
-
`).all();
|
|
5198
|
-
return {
|
|
5199
|
-
rows,
|
|
5200
|
-
version
|
|
5201
|
-
};
|
|
5202
|
-
});
|
|
5203
|
-
};
|
|
5204
|
-
|
|
5205
|
-
const secretServiceName = 'org.freedesktop.secrets';
|
|
5206
|
-
const secretServicePath = '/org/freedesktop/secrets';
|
|
5207
|
-
const secretServiceInterface = 'org.freedesktop.Secret.Service';
|
|
5208
|
-
const secretCollectionInterface = 'org.freedesktop.Secret.Collection';
|
|
5209
|
-
const secretItemInterface = 'org.freedesktop.Secret.Item';
|
|
5210
|
-
const propertiesInterface = 'org.freedesktop.DBus.Properties';
|
|
5211
|
-
const defaultCollectionPath = '/org/freedesktop/secrets/aliases/default';
|
|
5212
|
-
const chromeSafeStorageLabel = 'Chrome Safe Storage';
|
|
5213
|
-
const getProperties = async (bus, path) => {
|
|
5214
|
-
return bus.getService(secretServiceName).getInterface(path, propertiesInterface);
|
|
5215
|
-
};
|
|
5216
|
-
const findChromeSafeStorageItem = async (bus, service) => {
|
|
5217
|
-
const [unlocked, locked] = await service.SearchItems({
|
|
5218
|
-
application: 'chrome'
|
|
5219
|
-
});
|
|
5220
|
-
const matchingItems = [...unlocked, ...locked];
|
|
5221
|
-
if (matchingItems.length > 0) {
|
|
5222
|
-
return matchingItems[0];
|
|
5223
|
-
}
|
|
5224
|
-
const collectionProperties = await getProperties(bus, defaultCollectionPath);
|
|
5225
|
-
const items = await collectionProperties.Get(secretCollectionInterface, 'Items');
|
|
5226
|
-
for (const item of items) {
|
|
5227
|
-
const itemProperties = await getProperties(bus, item);
|
|
5228
|
-
const label = await itemProperties.Get(secretItemInterface, 'Label');
|
|
5229
|
-
if (label === chromeSafeStorageLabel) {
|
|
5230
|
-
return item;
|
|
5231
|
-
}
|
|
5232
|
-
}
|
|
5233
|
-
throw new Error('Chrome Safe Storage password was not found in the Linux keyring');
|
|
5234
|
-
};
|
|
5235
|
-
const unlockItem = async (service, item) => {
|
|
5236
|
-
const [unlocked, prompt] = await service.Unlock([item]);
|
|
5237
|
-
if (unlocked.includes(item)) {
|
|
5238
|
-
return;
|
|
5239
|
-
}
|
|
5240
|
-
if (prompt !== '/') {
|
|
5241
|
-
throw new Error('Chrome Safe Storage is locked; unlock the desktop keyring and try again');
|
|
5242
|
-
}
|
|
5243
|
-
throw new Error('Chrome Safe Storage could not be unlocked');
|
|
5244
|
-
};
|
|
5245
|
-
const readPassword = async (bus, sessionInput) => {
|
|
5246
|
-
const service = await bus.getService(secretServiceName).getInterface(secretServicePath, secretServiceInterface);
|
|
5247
|
-
const [, sessionPath] = await service.OpenSession('plain', sessionInput);
|
|
5248
|
-
const item = await findChromeSafeStorageItem(bus, service);
|
|
5249
|
-
let secrets;
|
|
5250
|
-
try {
|
|
5251
|
-
secrets = await service.GetSecrets([item], sessionPath);
|
|
5252
|
-
} catch {
|
|
5253
|
-
await unlockItem(service, item);
|
|
5254
|
-
secrets = await service.GetSecrets([item], sessionPath);
|
|
5255
|
-
}
|
|
5256
|
-
const secret = secrets[item];
|
|
5257
|
-
if (!secret) {
|
|
5258
|
-
throw new Error('Chrome Safe Storage password was not returned by the Linux keyring');
|
|
5259
|
-
}
|
|
5260
|
-
return Buffer.from(secret[2]).toString('utf8');
|
|
5261
|
-
};
|
|
5262
|
-
const getErrorMessage = error => {
|
|
5263
|
-
return error instanceof Error ? error.message : String(error);
|
|
5264
|
-
};
|
|
5265
|
-
const getChromeSafeStoragePassword = async () => {
|
|
5266
|
-
const {
|
|
5267
|
-
default: dbus,
|
|
5268
|
-
Variant
|
|
5269
|
-
} = await import('dbus-native');
|
|
5270
|
-
const bus = dbus.sessionBus({
|
|
5271
|
-
timeout: 5000
|
|
5272
|
-
});
|
|
5273
|
-
try {
|
|
5274
|
-
return await readPassword(bus, new Variant('s', ''));
|
|
5275
|
-
} catch (error) {
|
|
5276
|
-
throw new Error(`Failed to read Chrome Safe Storage password: ${getErrorMessage(error)}`);
|
|
5277
|
-
} finally {
|
|
5278
|
-
await bus.close();
|
|
5279
|
-
}
|
|
5280
|
-
};
|
|
5281
|
-
|
|
5282
|
-
const isValidProfileDirectory = value => {
|
|
5283
|
-
return value !== '' && value !== '.' && value !== '..' && !value.includes('/') && !value.includes('\\');
|
|
5284
|
-
};
|
|
5285
|
-
const getCookieDatabasePath = (chromeDataDirectory, profileDirectory) => {
|
|
5286
|
-
const profilePath = join$1(chromeDataDirectory, profileDirectory);
|
|
5287
|
-
const candidates = [join$1(profilePath, 'Cookies'), join$1(profilePath, 'Network', 'Cookies')];
|
|
5288
|
-
for (const candidate of candidates) {
|
|
5289
|
-
if (existsSync(candidate)) {
|
|
5290
|
-
return candidate;
|
|
5291
|
-
}
|
|
5292
|
-
}
|
|
5293
|
-
throw new Error(`Chrome cookie database was not found for profile ${profileDirectory}`);
|
|
5294
|
-
};
|
|
5295
|
-
const getMostRecentlyActiveProfile = infoCache => {
|
|
5296
|
-
let selected;
|
|
5297
|
-
let selectedActiveTime = -Infinity;
|
|
5298
|
-
for (const [directory, info] of Object.entries(infoCache)) {
|
|
5299
|
-
if (!isValidProfileDirectory(directory)) {
|
|
5300
|
-
continue;
|
|
5301
|
-
}
|
|
5302
|
-
const activeTime = typeof info.active_time === 'number' && Number.isFinite(info.active_time) ? info.active_time : -Infinity;
|
|
5303
|
-
if (selected === undefined || activeTime > selectedActiveTime) {
|
|
5304
|
-
selected = directory;
|
|
5305
|
-
selectedActiveTime = activeTime;
|
|
5306
|
-
}
|
|
5307
|
-
}
|
|
5308
|
-
return selected;
|
|
5309
|
-
};
|
|
5310
|
-
const getChromeDataDirectory = () => {
|
|
5311
|
-
const configDirectory = process.env.XDG_CONFIG_HOME || join$1(homedir(), '.config');
|
|
5312
|
-
return join$1(configDirectory, 'google-chrome');
|
|
5313
|
-
};
|
|
5314
|
-
const getActiveProfile$1 = chromeDataDirectory => {
|
|
5315
|
-
const localStatePath = join$1(chromeDataDirectory, 'Local State');
|
|
5316
|
-
if (!existsSync(localStatePath)) {
|
|
5317
|
-
throw new Error(`Google Chrome profile data was not found at ${chromeDataDirectory}`);
|
|
5318
|
-
}
|
|
5319
|
-
let localState;
|
|
5320
|
-
try {
|
|
5321
|
-
localState = JSON.parse(readFileSync(localStatePath, 'utf8'));
|
|
5322
|
-
} catch {
|
|
5323
|
-
throw new Error('Google Chrome profile metadata is invalid');
|
|
5324
|
-
}
|
|
5325
|
-
const infoCache = localState.profile?.info_cache || {};
|
|
5326
|
-
const orderedProfile = localState.profile?.profiles_order?.find(isValidProfileDirectory);
|
|
5327
|
-
const directory = getMostRecentlyActiveProfile(infoCache) || orderedProfile || 'Default';
|
|
5328
|
-
const name = infoCache[directory]?.name || directory;
|
|
5329
|
-
const cookieDatabasePath = getCookieDatabasePath(chromeDataDirectory, directory);
|
|
5330
|
-
return {
|
|
5331
|
-
cookieDatabasePath,
|
|
5332
|
-
directory,
|
|
5333
|
-
name
|
|
5334
|
-
};
|
|
5335
|
-
};
|
|
5336
|
-
|
|
5337
|
-
const MainFrame = 'mainFrame';
|
|
5338
|
-
const Script = 'script';
|
|
5339
|
-
const Xhr = 'xhr';
|
|
5340
|
-
|
|
5341
|
-
const Get = 'GET';
|
|
5342
|
-
const Head = 'HEAD';
|
|
5343
|
-
const Options = 'OPTIONS';
|
|
5344
|
-
const Post = 'POST';
|
|
5345
|
-
|
|
5346
|
-
// @ts-ignore
|
|
5347
|
-
|
|
5348
|
-
const getBeforeRequestResponseMainFrame = (method, url) => {
|
|
5349
|
-
return {};
|
|
5350
|
-
};
|
|
5351
|
-
const cancelIfStartsWith = (url, canceledUrls) => {
|
|
5352
|
-
for (const canceledUrl of canceledUrls) {
|
|
5353
|
-
if (url.startsWith(canceledUrl)) {
|
|
5354
|
-
return {
|
|
5355
|
-
cancel: true
|
|
5356
|
-
};
|
|
5357
|
-
}
|
|
5358
|
-
}
|
|
5359
|
-
return {};
|
|
5360
|
-
};
|
|
5361
|
-
const getBeforeRequestResponseXhrPost = url => {
|
|
5362
|
-
const canceledUrls = ['https://www.youtube.com/api/stats/qoe', 'https://www.youtube.com/youtubei/v1/log_event', 'https://play.google.com/log'];
|
|
5363
|
-
return cancelIfStartsWith(url, canceledUrls);
|
|
5364
|
-
};
|
|
5365
|
-
const getBeforeRequestResponseXhrGet = url => {
|
|
5366
|
-
const canceledUrls = ['https://www.youtube.com/pagead/', 'https://www.youtube.com/api/stats/qoe', 'https://www.youtube.com/api/stats/ads', 'https://www.youtube.com/api/stats/delayplay', 'https://www.youtube.com/ptracking', 'https://www.youtube.com/api/timedtext', 'https://www.youtube.com/pcs/activeview', 'https://googleads.g.doubleclick.net/pagead/id'];
|
|
5367
|
-
return cancelIfStartsWith(url, canceledUrls);
|
|
5368
|
-
};
|
|
5369
|
-
const getBeforeRequestResponseXhrOptions = url => {
|
|
5370
|
-
const canceledUrls = ['https://play.google.com/log'];
|
|
5371
|
-
return cancelIfStartsWith(url, canceledUrls);
|
|
5372
|
-
};
|
|
5373
|
-
const getBeforeRequestResponseXhrHead = url => {
|
|
5374
|
-
const canceledUrls = ['https://www.youtube.com/generate_204'];
|
|
5375
|
-
return cancelIfStartsWith(url, canceledUrls);
|
|
5376
|
-
};
|
|
5377
|
-
const getBeforeRequestResponseXhr = (method, url) => {
|
|
5378
|
-
switch (method) {
|
|
5379
|
-
case Get:
|
|
5380
|
-
return getBeforeRequestResponseXhrGet(url);
|
|
5381
|
-
case Head:
|
|
5382
|
-
return getBeforeRequestResponseXhrHead(url);
|
|
5383
|
-
case Options:
|
|
5384
|
-
return getBeforeRequestResponseXhrOptions(url);
|
|
5385
|
-
case Post:
|
|
5386
|
-
return getBeforeRequestResponseXhrPost(url);
|
|
5387
|
-
default:
|
|
5388
|
-
return {};
|
|
5389
|
-
}
|
|
5390
|
-
};
|
|
5391
|
-
const getBeforeRequestResponseDefault = (method, url) => {
|
|
5392
|
-
return {};
|
|
5393
|
-
};
|
|
5394
|
-
const getBeforeRequestResponseScript = (method, url) => {
|
|
5395
|
-
const canceledUrls = ['https://static.doubleclick.net'];
|
|
5396
|
-
return cancelIfStartsWith(url, canceledUrls);
|
|
5397
|
-
};
|
|
5398
|
-
const getBeforeRequestResponse = details => {
|
|
5399
|
-
const {
|
|
5400
|
-
method,
|
|
5401
|
-
resourceType,
|
|
5402
|
-
url
|
|
5403
|
-
} = details;
|
|
5404
|
-
switch (resourceType) {
|
|
5405
|
-
case MainFrame:
|
|
5406
|
-
return getBeforeRequestResponseMainFrame();
|
|
5407
|
-
case Script:
|
|
5408
|
-
return getBeforeRequestResponseScript(method, url);
|
|
5409
|
-
case Xhr:
|
|
5410
|
-
return getBeforeRequestResponseXhr(method, url);
|
|
5411
|
-
default:
|
|
5412
|
-
return getBeforeRequestResponseDefault();
|
|
5413
|
-
}
|
|
5414
|
-
};
|
|
5415
|
-
|
|
5416
|
-
/**
|
|
5417
|
-
*
|
|
5418
|
-
* @param {Electron.OnBeforeRequestListenerDetails } details
|
|
5419
|
-
* @param {(response: globalThis.Electron.CallbackResponse) => void} callback
|
|
5420
|
-
*/
|
|
5421
|
-
const handleBeforeRequest = (details, callback) => {
|
|
5422
|
-
const response = getBeforeRequestResponse(details);
|
|
5423
|
-
callback(response);
|
|
5424
|
-
};
|
|
5425
|
-
const filter = {
|
|
5426
|
-
// urls: ['https://*.youtube.com/*'],
|
|
5427
|
-
urls: ['<all_urls>']
|
|
5428
|
-
};
|
|
5429
|
-
|
|
5430
|
-
const state = {
|
|
5431
|
-
session: undefined
|
|
5432
|
-
};
|
|
5433
|
-
const isAllowedPermission = permission => {
|
|
5434
|
-
switch (permission) {
|
|
5435
|
-
case ClipBoardRead:
|
|
5436
|
-
case ClipBoardSanitizedWrite:
|
|
5437
|
-
case FullScreen:
|
|
5438
|
-
case GeoLocation:
|
|
5439
|
-
case WindowPlacement:
|
|
5440
|
-
return true;
|
|
5441
|
-
default:
|
|
5442
|
-
return false;
|
|
5443
|
-
}
|
|
5444
|
-
};
|
|
5445
|
-
const handlePermissionRequest = (webContents, permission, callback, details) => {
|
|
5446
|
-
callback(isAllowedPermission(permission));
|
|
5447
|
-
};
|
|
5448
|
-
const handlePermissionCheck = (webContents, permission, origin, details) => {
|
|
5449
|
-
return isAllowedPermission(permission);
|
|
5450
|
-
};
|
|
5451
|
-
const createSession = () => {
|
|
5452
|
-
const sessionId = `persist:browserView`;
|
|
5453
|
-
const session = Electron.session.fromPartition(sessionId, {
|
|
5454
|
-
cache: true
|
|
5455
|
-
});
|
|
5456
|
-
session.setPermissionRequestHandler(handlePermissionRequest);
|
|
5457
|
-
session.setPermissionCheckHandler(handlePermissionCheck);
|
|
5458
|
-
session.webRequest.onBeforeRequest(filter, handleBeforeRequest);
|
|
5459
|
-
// session.webRequest.addSessionChromeExtensions(session)
|
|
5460
|
-
return session;
|
|
5461
|
-
};
|
|
5462
|
-
const getSession = () => {
|
|
5463
|
-
state.session ||= createSession();
|
|
5464
|
-
return state.session;
|
|
5465
|
-
};
|
|
5466
|
-
|
|
5467
|
-
const assertLinux = () => {
|
|
5468
|
-
if (process.platform !== 'linux') {
|
|
5469
|
-
throw new Error('Importing Chrome cookies is only supported on Linux');
|
|
5470
|
-
}
|
|
5471
|
-
};
|
|
5472
|
-
const getInfoFromDirectory$1 = chromeDataDirectory => {
|
|
5473
|
-
const profile = getActiveProfile$1(chromeDataDirectory);
|
|
5474
|
-
const cookieCount = getCookieCount$1(profile.cookieDatabasePath);
|
|
5475
|
-
return {
|
|
5476
|
-
cookieCount,
|
|
5477
|
-
profileDirectory: profile.directory,
|
|
5478
|
-
profileName: profile.name
|
|
5479
|
-
};
|
|
5480
|
-
};
|
|
5481
|
-
const getInfo$1 = () => {
|
|
5482
|
-
assertLinux();
|
|
5483
|
-
return getInfoFromDirectory$1(getChromeDataDirectory());
|
|
5484
|
-
};
|
|
5485
|
-
const importFromDirectory$1 = async (chromeDataDirectory, session) => {
|
|
5486
|
-
const profile = getActiveProfile$1(chromeDataDirectory);
|
|
5487
|
-
const {
|
|
5488
|
-
rows,
|
|
5489
|
-
version
|
|
5490
|
-
} = readCookies$1(profile.cookieDatabasePath);
|
|
5491
|
-
const requiresChromeSafeStoragePassword = rows.some(row => !row.value && isV11(row.encryptedValue));
|
|
5492
|
-
const chromeSafeStoragePassword = requiresChromeSafeStoragePassword ? await getChromeSafeStoragePassword() : undefined;
|
|
5493
|
-
const cookies = [];
|
|
5494
|
-
let skipped = 0;
|
|
5495
|
-
let unsupportedEncryption = 0;
|
|
5496
|
-
for (const row of rows) {
|
|
5497
|
-
try {
|
|
5498
|
-
const cookie = convert$1(row, version, chromeSafeStoragePassword);
|
|
5499
|
-
if (cookie) {
|
|
5500
|
-
cookies.push(cookie);
|
|
5501
|
-
} else {
|
|
5502
|
-
skipped++;
|
|
5503
|
-
}
|
|
5504
|
-
} catch (error) {
|
|
5505
|
-
skipped++;
|
|
5506
|
-
if (error instanceof UnsupportedChromeCookieEncryptionError) {
|
|
5507
|
-
unsupportedEncryption++;
|
|
5508
|
-
}
|
|
5509
|
-
}
|
|
5510
|
-
}
|
|
5511
|
-
if (cookies.length === 0 && unsupportedEncryption > 0) {
|
|
5512
|
-
throw new Error('Unsupported Chrome cookie encryption format');
|
|
5513
|
-
}
|
|
5514
|
-
let imported = 0;
|
|
5515
|
-
let failed = 0;
|
|
5516
|
-
for (const cookie of cookies) {
|
|
5517
|
-
try {
|
|
5518
|
-
await session.cookies.set(cookie);
|
|
5519
|
-
imported++;
|
|
5520
|
-
} catch {
|
|
5521
|
-
failed++;
|
|
5522
|
-
}
|
|
5523
|
-
}
|
|
5524
|
-
await session.cookies.flushStore();
|
|
5525
|
-
return {
|
|
5526
|
-
failed,
|
|
5527
|
-
imported,
|
|
5528
|
-
skipped
|
|
5529
|
-
};
|
|
5530
|
-
};
|
|
5531
|
-
const importCookies$1 = async () => {
|
|
5532
|
-
assertLinux();
|
|
5533
|
-
return importFromDirectory$1(getChromeDataDirectory(), getSession());
|
|
5534
|
-
};
|
|
5535
|
-
|
|
5536
5040
|
const handleTimeout = () => {
|
|
5537
5041
|
throw new Error('oops');
|
|
5538
5042
|
};
|
|
@@ -6976,6 +6480,136 @@ const ElectronBrowserViewEventListeners = {
|
|
|
6976
6480
|
windowOpen: ElectronBrowserViewEventListenerWindowOpen
|
|
6977
6481
|
};
|
|
6978
6482
|
|
|
6483
|
+
const MainFrame = 'mainFrame';
|
|
6484
|
+
const Script = 'script';
|
|
6485
|
+
const Xhr = 'xhr';
|
|
6486
|
+
|
|
6487
|
+
const Get = 'GET';
|
|
6488
|
+
const Head = 'HEAD';
|
|
6489
|
+
const Options = 'OPTIONS';
|
|
6490
|
+
const Post = 'POST';
|
|
6491
|
+
|
|
6492
|
+
// @ts-ignore
|
|
6493
|
+
|
|
6494
|
+
const getBeforeRequestResponseMainFrame = (method, url) => {
|
|
6495
|
+
return {};
|
|
6496
|
+
};
|
|
6497
|
+
const cancelIfStartsWith = (url, canceledUrls) => {
|
|
6498
|
+
for (const canceledUrl of canceledUrls) {
|
|
6499
|
+
if (url.startsWith(canceledUrl)) {
|
|
6500
|
+
return {
|
|
6501
|
+
cancel: true
|
|
6502
|
+
};
|
|
6503
|
+
}
|
|
6504
|
+
}
|
|
6505
|
+
return {};
|
|
6506
|
+
};
|
|
6507
|
+
const getBeforeRequestResponseXhrPost = url => {
|
|
6508
|
+
const canceledUrls = ['https://www.youtube.com/api/stats/qoe', 'https://www.youtube.com/youtubei/v1/log_event', 'https://play.google.com/log'];
|
|
6509
|
+
return cancelIfStartsWith(url, canceledUrls);
|
|
6510
|
+
};
|
|
6511
|
+
const getBeforeRequestResponseXhrGet = url => {
|
|
6512
|
+
const canceledUrls = ['https://www.youtube.com/pagead/', 'https://www.youtube.com/api/stats/qoe', 'https://www.youtube.com/api/stats/ads', 'https://www.youtube.com/api/stats/delayplay', 'https://www.youtube.com/ptracking', 'https://www.youtube.com/api/timedtext', 'https://www.youtube.com/pcs/activeview', 'https://googleads.g.doubleclick.net/pagead/id'];
|
|
6513
|
+
return cancelIfStartsWith(url, canceledUrls);
|
|
6514
|
+
};
|
|
6515
|
+
const getBeforeRequestResponseXhrOptions = url => {
|
|
6516
|
+
const canceledUrls = ['https://play.google.com/log'];
|
|
6517
|
+
return cancelIfStartsWith(url, canceledUrls);
|
|
6518
|
+
};
|
|
6519
|
+
const getBeforeRequestResponseXhrHead = url => {
|
|
6520
|
+
const canceledUrls = ['https://www.youtube.com/generate_204'];
|
|
6521
|
+
return cancelIfStartsWith(url, canceledUrls);
|
|
6522
|
+
};
|
|
6523
|
+
const getBeforeRequestResponseXhr = (method, url) => {
|
|
6524
|
+
switch (method) {
|
|
6525
|
+
case Get:
|
|
6526
|
+
return getBeforeRequestResponseXhrGet(url);
|
|
6527
|
+
case Head:
|
|
6528
|
+
return getBeforeRequestResponseXhrHead(url);
|
|
6529
|
+
case Options:
|
|
6530
|
+
return getBeforeRequestResponseXhrOptions(url);
|
|
6531
|
+
case Post:
|
|
6532
|
+
return getBeforeRequestResponseXhrPost(url);
|
|
6533
|
+
default:
|
|
6534
|
+
return {};
|
|
6535
|
+
}
|
|
6536
|
+
};
|
|
6537
|
+
const getBeforeRequestResponseDefault = (method, url) => {
|
|
6538
|
+
return {};
|
|
6539
|
+
};
|
|
6540
|
+
const getBeforeRequestResponseScript = (method, url) => {
|
|
6541
|
+
const canceledUrls = ['https://static.doubleclick.net'];
|
|
6542
|
+
return cancelIfStartsWith(url, canceledUrls);
|
|
6543
|
+
};
|
|
6544
|
+
const getBeforeRequestResponse = details => {
|
|
6545
|
+
const {
|
|
6546
|
+
method,
|
|
6547
|
+
resourceType,
|
|
6548
|
+
url
|
|
6549
|
+
} = details;
|
|
6550
|
+
switch (resourceType) {
|
|
6551
|
+
case MainFrame:
|
|
6552
|
+
return getBeforeRequestResponseMainFrame();
|
|
6553
|
+
case Script:
|
|
6554
|
+
return getBeforeRequestResponseScript(method, url);
|
|
6555
|
+
case Xhr:
|
|
6556
|
+
return getBeforeRequestResponseXhr(method, url);
|
|
6557
|
+
default:
|
|
6558
|
+
return getBeforeRequestResponseDefault();
|
|
6559
|
+
}
|
|
6560
|
+
};
|
|
6561
|
+
|
|
6562
|
+
/**
|
|
6563
|
+
*
|
|
6564
|
+
* @param {Electron.OnBeforeRequestListenerDetails } details
|
|
6565
|
+
* @param {(response: globalThis.Electron.CallbackResponse) => void} callback
|
|
6566
|
+
*/
|
|
6567
|
+
const handleBeforeRequest = (details, callback) => {
|
|
6568
|
+
const response = getBeforeRequestResponse(details);
|
|
6569
|
+
callback(response);
|
|
6570
|
+
};
|
|
6571
|
+
const filter = {
|
|
6572
|
+
// urls: ['https://*.youtube.com/*'],
|
|
6573
|
+
urls: ['<all_urls>']
|
|
6574
|
+
};
|
|
6575
|
+
|
|
6576
|
+
const state = {
|
|
6577
|
+
session: undefined
|
|
6578
|
+
};
|
|
6579
|
+
const isAllowedPermission = permission => {
|
|
6580
|
+
switch (permission) {
|
|
6581
|
+
case ClipBoardRead:
|
|
6582
|
+
case ClipBoardSanitizedWrite:
|
|
6583
|
+
case FullScreen:
|
|
6584
|
+
case GeoLocation:
|
|
6585
|
+
case WindowPlacement:
|
|
6586
|
+
return true;
|
|
6587
|
+
default:
|
|
6588
|
+
return false;
|
|
6589
|
+
}
|
|
6590
|
+
};
|
|
6591
|
+
const handlePermissionRequest = (webContents, permission, callback, details) => {
|
|
6592
|
+
callback(isAllowedPermission(permission));
|
|
6593
|
+
};
|
|
6594
|
+
const handlePermissionCheck = (webContents, permission, origin, details) => {
|
|
6595
|
+
return isAllowedPermission(permission);
|
|
6596
|
+
};
|
|
6597
|
+
const createSession = () => {
|
|
6598
|
+
const sessionId = `persist:browserView`;
|
|
6599
|
+
const session = Electron.session.fromPartition(sessionId, {
|
|
6600
|
+
cache: true
|
|
6601
|
+
});
|
|
6602
|
+
session.setPermissionRequestHandler(handlePermissionRequest);
|
|
6603
|
+
session.setPermissionCheckHandler(handlePermissionCheck);
|
|
6604
|
+
session.webRequest.onBeforeRequest(filter, handleBeforeRequest);
|
|
6605
|
+
// session.webRequest.addSessionChromeExtensions(session)
|
|
6606
|
+
return session;
|
|
6607
|
+
};
|
|
6608
|
+
const getSession = () => {
|
|
6609
|
+
state.session ||= createSession();
|
|
6610
|
+
return state.session;
|
|
6611
|
+
};
|
|
6612
|
+
|
|
6979
6613
|
const attach = (webContents, parentWebContents) => {
|
|
6980
6614
|
let shouldRestoreParentFocus = false;
|
|
6981
6615
|
webContents.on(DidStartNavigation, (_event, _url, _isInPlace, isMainFrame) => {
|
|
@@ -7843,8 +7477,6 @@ const trash = async path => {
|
|
|
7843
7477
|
const commandMap = {
|
|
7844
7478
|
'AppWindow.createAppWindow': createAppWindow,
|
|
7845
7479
|
'Beep.beep': beep$1,
|
|
7846
|
-
'ChromeCookieImport.getInfo': getInfo$1,
|
|
7847
|
-
'ChromeCookieImport.importCookies': importCookies$1,
|
|
7848
7480
|
'Crash.crashMainProcess': crashMainProcess$1,
|
|
7849
7481
|
'CreateMessagePort.createMessagePort': createMessagePort,
|
|
7850
7482
|
'CreatePidMap.createPidMap': createPidMap,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@lvce-editor/main-process",
|
|
3
|
-
"version": "6.
|
|
3
|
+
"version": "6.29.0",
|
|
4
4
|
"keywords": [
|
|
5
5
|
"lvce-editor",
|
|
6
6
|
"electron"
|
|
@@ -14,8 +14,7 @@
|
|
|
14
14
|
"type": "module",
|
|
15
15
|
"main": "dist/mainProcessMain.js",
|
|
16
16
|
"dependencies": {
|
|
17
|
-
"
|
|
18
|
-
"electron": "43.4.0"
|
|
17
|
+
"electron": "43.4.1"
|
|
19
18
|
},
|
|
20
19
|
"engines": {
|
|
21
20
|
"node": ">=22"
|