@lvce-editor/main-process 6.14.0 → 6.15.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 +409 -163
- package/package.json +2 -2
package/dist/mainProcessMain.js
CHANGED
|
@@ -9,6 +9,8 @@ import { mkdirSync, createWriteStream, readFileSync, openAsBlob, existsSync, wri
|
|
|
9
9
|
import * as NodePath from 'node:path';
|
|
10
10
|
import { dirname, join as join$1 } from 'node:path';
|
|
11
11
|
import { homedir, tmpdir } from 'node:os';
|
|
12
|
+
import { pbkdf2Sync, createDecipheriv, createHash } from 'node:crypto';
|
|
13
|
+
import { DatabaseSync } from 'node:sqlite';
|
|
12
14
|
import { MessageChannel } from 'node:worker_threads';
|
|
13
15
|
|
|
14
16
|
const scheme = 'lvce-oss';
|
|
@@ -4066,7 +4068,6 @@ const PageTitleUpdated = 'page-title-updated';
|
|
|
4066
4068
|
const Destroyed = 'destroyed';
|
|
4067
4069
|
const BeforeInputEvent = 'before-input-event';
|
|
4068
4070
|
|
|
4069
|
-
const Allow = 'allow';
|
|
4070
4071
|
const Deny = 'deny';
|
|
4071
4072
|
|
|
4072
4073
|
const shouldOpenExternal = url => {
|
|
@@ -4604,6 +4605,409 @@ const beep$1 = () => {
|
|
|
4604
4605
|
shell.beep();
|
|
4605
4606
|
};
|
|
4606
4607
|
|
|
4608
|
+
const chromeV10Prefix = Buffer.from('v10');
|
|
4609
|
+
const chromeV10Key = pbkdf2Sync('peanuts', 'saltysalt', 1, 16, 'sha1');
|
|
4610
|
+
const chromeV10Iv = Buffer.alloc(16, 0x20);
|
|
4611
|
+
const domainHashLength = 32;
|
|
4612
|
+
class UnsupportedChromeCookieEncryptionError extends Error {
|
|
4613
|
+
constructor() {
|
|
4614
|
+
super('Unsupported Chrome cookie encryption format');
|
|
4615
|
+
this.name = 'UnsupportedChromeCookieEncryptionError';
|
|
4616
|
+
}
|
|
4617
|
+
}
|
|
4618
|
+
const decrypt$1 = (hostKey, encryptedValue, databaseVersion) => {
|
|
4619
|
+
const buffer = Buffer.from(encryptedValue);
|
|
4620
|
+
if (buffer.length <= chromeV10Prefix.length || !buffer.subarray(0, chromeV10Prefix.length).equals(chromeV10Prefix)) {
|
|
4621
|
+
throw new UnsupportedChromeCookieEncryptionError();
|
|
4622
|
+
}
|
|
4623
|
+
const decipher = createDecipheriv('aes-128-cbc', chromeV10Key, chromeV10Iv);
|
|
4624
|
+
const plaintext = Buffer.concat([decipher.update(buffer.subarray(chromeV10Prefix.length)), decipher.final()]);
|
|
4625
|
+
if (databaseVersion < 24) {
|
|
4626
|
+
return plaintext.toString('utf8');
|
|
4627
|
+
}
|
|
4628
|
+
if (plaintext.length < domainHashLength) {
|
|
4629
|
+
throw new Error('Chrome cookie domain integrity check failed');
|
|
4630
|
+
}
|
|
4631
|
+
const expectedDomainHash = createHash('sha256').update(hostKey).digest();
|
|
4632
|
+
const actualDomainHash = plaintext.subarray(0, domainHashLength);
|
|
4633
|
+
if (!actualDomainHash.equals(expectedDomainHash)) {
|
|
4634
|
+
throw new Error('Chrome cookie domain integrity check failed');
|
|
4635
|
+
}
|
|
4636
|
+
return plaintext.subarray(domainHashLength).toString('utf8');
|
|
4637
|
+
};
|
|
4638
|
+
|
|
4639
|
+
const chromeEpochOffsetMicroseconds = 11_644_473_600_000_000n;
|
|
4640
|
+
const microsecondsPerSecond = 1_000_000n;
|
|
4641
|
+
const getSameSite = sameSite => {
|
|
4642
|
+
switch (sameSite) {
|
|
4643
|
+
case 0:
|
|
4644
|
+
return 'no_restriction';
|
|
4645
|
+
case 1:
|
|
4646
|
+
return 'lax';
|
|
4647
|
+
case 2:
|
|
4648
|
+
return 'strict';
|
|
4649
|
+
default:
|
|
4650
|
+
return 'unspecified';
|
|
4651
|
+
}
|
|
4652
|
+
};
|
|
4653
|
+
const getExpirationDate = expiresUtc => {
|
|
4654
|
+
const chromeMicroseconds = BigInt(expiresUtc);
|
|
4655
|
+
return Number(chromeMicroseconds - chromeEpochOffsetMicroseconds) / Number(microsecondsPerSecond);
|
|
4656
|
+
};
|
|
4657
|
+
const getValue = (row, databaseVersion) => {
|
|
4658
|
+
if (row.value) {
|
|
4659
|
+
return row.value;
|
|
4660
|
+
}
|
|
4661
|
+
return decrypt$1(row.hostKey, row.encryptedValue, databaseVersion);
|
|
4662
|
+
};
|
|
4663
|
+
const convert = (row, databaseVersion, now = Date.now() / 1000) => {
|
|
4664
|
+
if (!row.hostKey || row.topFrameSiteKey) {
|
|
4665
|
+
return undefined;
|
|
4666
|
+
}
|
|
4667
|
+
const host = row.hostKey.startsWith('.') ? row.hostKey.slice(1) : row.hostKey;
|
|
4668
|
+
if (!host) {
|
|
4669
|
+
return undefined;
|
|
4670
|
+
}
|
|
4671
|
+
const secure = Boolean(row.isSecure);
|
|
4672
|
+
const details = {
|
|
4673
|
+
httpOnly: Boolean(row.isHttpOnly),
|
|
4674
|
+
name: row.name,
|
|
4675
|
+
path: row.path || '/',
|
|
4676
|
+
sameSite: getSameSite(row.sameSite),
|
|
4677
|
+
secure,
|
|
4678
|
+
url: `${secure ? 'https' : 'http'}://${host}/`,
|
|
4679
|
+
value: getValue(row, databaseVersion)
|
|
4680
|
+
};
|
|
4681
|
+
if (row.hostKey.startsWith('.')) {
|
|
4682
|
+
details.domain = row.hostKey;
|
|
4683
|
+
}
|
|
4684
|
+
if (row.hasExpires) {
|
|
4685
|
+
const expirationDate = getExpirationDate(row.expiresUtc);
|
|
4686
|
+
if (!Number.isFinite(expirationDate) || expirationDate <= now) {
|
|
4687
|
+
return undefined;
|
|
4688
|
+
}
|
|
4689
|
+
details.expirationDate = expirationDate;
|
|
4690
|
+
}
|
|
4691
|
+
return details;
|
|
4692
|
+
};
|
|
4693
|
+
|
|
4694
|
+
/* eslint-disable n/no-unsupported-features/node-builtins -- Electron 43 provides the node:sqlite API used by the main process */
|
|
4695
|
+
const getDatabaseError = error => {
|
|
4696
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
4697
|
+
if (message.toLowerCase().includes('locked') || message.toLowerCase().includes('busy')) {
|
|
4698
|
+
return new Error('Chrome cookie database is busy. Close Chrome and try again.');
|
|
4699
|
+
}
|
|
4700
|
+
return new Error('Failed to read the Chrome cookie database');
|
|
4701
|
+
};
|
|
4702
|
+
const withDatabase = (path, fn) => {
|
|
4703
|
+
let database;
|
|
4704
|
+
try {
|
|
4705
|
+
database = new DatabaseSync(path, {
|
|
4706
|
+
readOnly: true
|
|
4707
|
+
});
|
|
4708
|
+
database.exec('PRAGMA busy_timeout = 1000');
|
|
4709
|
+
return fn(database);
|
|
4710
|
+
} catch (error) {
|
|
4711
|
+
if (error instanceof Error && error.message.startsWith('Unsupported Chrome cookie database version')) {
|
|
4712
|
+
throw error;
|
|
4713
|
+
}
|
|
4714
|
+
throw getDatabaseError(error);
|
|
4715
|
+
} finally {
|
|
4716
|
+
database?.close();
|
|
4717
|
+
}
|
|
4718
|
+
};
|
|
4719
|
+
const getVersion = database => {
|
|
4720
|
+
const row = database.prepare(`SELECT value FROM meta WHERE key = 'version'`).get();
|
|
4721
|
+
const version = Number(row?.value);
|
|
4722
|
+
if (version !== 24) {
|
|
4723
|
+
throw new Error(`Unsupported Chrome cookie database version ${Number.isFinite(version) ? version : 'unknown'}`);
|
|
4724
|
+
}
|
|
4725
|
+
return version;
|
|
4726
|
+
};
|
|
4727
|
+
const getCookieCount = path => {
|
|
4728
|
+
return withDatabase(path, database => {
|
|
4729
|
+
getVersion(database);
|
|
4730
|
+
const row = database.prepare('SELECT COUNT(*) AS count FROM cookies').get();
|
|
4731
|
+
return row.count;
|
|
4732
|
+
});
|
|
4733
|
+
};
|
|
4734
|
+
const readCookies = path => {
|
|
4735
|
+
return withDatabase(path, database => {
|
|
4736
|
+
const version = getVersion(database);
|
|
4737
|
+
const rows = database.prepare(`
|
|
4738
|
+
SELECT
|
|
4739
|
+
encrypted_value AS encryptedValue,
|
|
4740
|
+
CAST(expires_utc AS TEXT) AS expiresUtc,
|
|
4741
|
+
has_expires AS hasExpires,
|
|
4742
|
+
host_key AS hostKey,
|
|
4743
|
+
is_httponly AS isHttpOnly,
|
|
4744
|
+
is_secure AS isSecure,
|
|
4745
|
+
name,
|
|
4746
|
+
path,
|
|
4747
|
+
samesite AS sameSite,
|
|
4748
|
+
top_frame_site_key AS topFrameSiteKey,
|
|
4749
|
+
value
|
|
4750
|
+
FROM cookies
|
|
4751
|
+
`).all();
|
|
4752
|
+
return {
|
|
4753
|
+
rows,
|
|
4754
|
+
version
|
|
4755
|
+
};
|
|
4756
|
+
});
|
|
4757
|
+
};
|
|
4758
|
+
|
|
4759
|
+
const isValidProfileDirectory = value => {
|
|
4760
|
+
return value !== '' && value !== '.' && value !== '..' && !value.includes('/') && !value.includes('\\');
|
|
4761
|
+
};
|
|
4762
|
+
const getCookieDatabasePath = (chromeDataDirectory, profileDirectory) => {
|
|
4763
|
+
const profilePath = join$1(chromeDataDirectory, profileDirectory);
|
|
4764
|
+
const candidates = [join$1(profilePath, 'Cookies'), join$1(profilePath, 'Network', 'Cookies')];
|
|
4765
|
+
for (const candidate of candidates) {
|
|
4766
|
+
if (existsSync(candidate)) {
|
|
4767
|
+
return candidate;
|
|
4768
|
+
}
|
|
4769
|
+
}
|
|
4770
|
+
throw new Error(`Chrome cookie database was not found for profile ${profileDirectory}`);
|
|
4771
|
+
};
|
|
4772
|
+
const getMostRecentlyActiveProfile = infoCache => {
|
|
4773
|
+
let selected;
|
|
4774
|
+
let selectedActiveTime = -Infinity;
|
|
4775
|
+
for (const [directory, info] of Object.entries(infoCache)) {
|
|
4776
|
+
if (!isValidProfileDirectory(directory)) {
|
|
4777
|
+
continue;
|
|
4778
|
+
}
|
|
4779
|
+
const activeTime = typeof info.active_time === 'number' && Number.isFinite(info.active_time) ? info.active_time : -Infinity;
|
|
4780
|
+
if (selected === undefined || activeTime > selectedActiveTime) {
|
|
4781
|
+
selected = directory;
|
|
4782
|
+
selectedActiveTime = activeTime;
|
|
4783
|
+
}
|
|
4784
|
+
}
|
|
4785
|
+
return selected;
|
|
4786
|
+
};
|
|
4787
|
+
const getChromeDataDirectory = () => {
|
|
4788
|
+
const configDirectory = process.env.XDG_CONFIG_HOME || join$1(homedir(), '.config');
|
|
4789
|
+
return join$1(configDirectory, 'google-chrome');
|
|
4790
|
+
};
|
|
4791
|
+
const getActiveProfile = chromeDataDirectory => {
|
|
4792
|
+
const localStatePath = join$1(chromeDataDirectory, 'Local State');
|
|
4793
|
+
if (!existsSync(localStatePath)) {
|
|
4794
|
+
throw new Error(`Google Chrome profile data was not found at ${chromeDataDirectory}`);
|
|
4795
|
+
}
|
|
4796
|
+
let localState;
|
|
4797
|
+
try {
|
|
4798
|
+
localState = JSON.parse(readFileSync(localStatePath, 'utf8'));
|
|
4799
|
+
} catch {
|
|
4800
|
+
throw new Error('Google Chrome profile metadata is invalid');
|
|
4801
|
+
}
|
|
4802
|
+
const infoCache = localState.profile?.info_cache || {};
|
|
4803
|
+
const orderedProfile = localState.profile?.profiles_order?.find(isValidProfileDirectory);
|
|
4804
|
+
const directory = getMostRecentlyActiveProfile(infoCache) || orderedProfile || 'Default';
|
|
4805
|
+
const name = infoCache[directory]?.name || directory;
|
|
4806
|
+
const cookieDatabasePath = getCookieDatabasePath(chromeDataDirectory, directory);
|
|
4807
|
+
return {
|
|
4808
|
+
cookieDatabasePath,
|
|
4809
|
+
directory,
|
|
4810
|
+
name
|
|
4811
|
+
};
|
|
4812
|
+
};
|
|
4813
|
+
|
|
4814
|
+
const MainFrame = 'mainFrame';
|
|
4815
|
+
const Script = 'script';
|
|
4816
|
+
const Xhr = 'xhr';
|
|
4817
|
+
|
|
4818
|
+
const Get = 'GET';
|
|
4819
|
+
const Head = 'HEAD';
|
|
4820
|
+
const Options = 'OPTIONS';
|
|
4821
|
+
const Post = 'POST';
|
|
4822
|
+
|
|
4823
|
+
// @ts-ignore
|
|
4824
|
+
|
|
4825
|
+
const getBeforeRequestResponseMainFrame = (method, url) => {
|
|
4826
|
+
return {};
|
|
4827
|
+
};
|
|
4828
|
+
const cancelIfStartsWith = (url, canceledUrls) => {
|
|
4829
|
+
for (const canceledUrl of canceledUrls) {
|
|
4830
|
+
if (url.startsWith(canceledUrl)) {
|
|
4831
|
+
return {
|
|
4832
|
+
cancel: true
|
|
4833
|
+
};
|
|
4834
|
+
}
|
|
4835
|
+
}
|
|
4836
|
+
return {};
|
|
4837
|
+
};
|
|
4838
|
+
const getBeforeRequestResponseXhrPost = url => {
|
|
4839
|
+
const canceledUrls = ['https://www.youtube.com/api/stats/qoe', 'https://www.youtube.com/youtubei/v1/log_event', 'https://play.google.com/log'];
|
|
4840
|
+
return cancelIfStartsWith(url, canceledUrls);
|
|
4841
|
+
};
|
|
4842
|
+
const getBeforeRequestResponseXhrGet = url => {
|
|
4843
|
+
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'];
|
|
4844
|
+
return cancelIfStartsWith(url, canceledUrls);
|
|
4845
|
+
};
|
|
4846
|
+
const getBeforeRequestResponseXhrOptions = url => {
|
|
4847
|
+
const canceledUrls = ['https://play.google.com/log'];
|
|
4848
|
+
return cancelIfStartsWith(url, canceledUrls);
|
|
4849
|
+
};
|
|
4850
|
+
const getBeforeRequestResponseXhrHead = url => {
|
|
4851
|
+
const canceledUrls = ['https://www.youtube.com/generate_204'];
|
|
4852
|
+
return cancelIfStartsWith(url, canceledUrls);
|
|
4853
|
+
};
|
|
4854
|
+
const getBeforeRequestResponseXhr = (method, url) => {
|
|
4855
|
+
switch (method) {
|
|
4856
|
+
case Get:
|
|
4857
|
+
return getBeforeRequestResponseXhrGet(url);
|
|
4858
|
+
case Head:
|
|
4859
|
+
return getBeforeRequestResponseXhrHead(url);
|
|
4860
|
+
case Options:
|
|
4861
|
+
return getBeforeRequestResponseXhrOptions(url);
|
|
4862
|
+
case Post:
|
|
4863
|
+
return getBeforeRequestResponseXhrPost(url);
|
|
4864
|
+
default:
|
|
4865
|
+
return {};
|
|
4866
|
+
}
|
|
4867
|
+
};
|
|
4868
|
+
const getBeforeRequestResponseDefault = (method, url) => {
|
|
4869
|
+
return {};
|
|
4870
|
+
};
|
|
4871
|
+
const getBeforeRequestResponseScript = (method, url) => {
|
|
4872
|
+
const canceledUrls = ['https://static.doubleclick.net'];
|
|
4873
|
+
return cancelIfStartsWith(url, canceledUrls);
|
|
4874
|
+
};
|
|
4875
|
+
const getBeforeRequestResponse = details => {
|
|
4876
|
+
const {
|
|
4877
|
+
method,
|
|
4878
|
+
resourceType,
|
|
4879
|
+
url
|
|
4880
|
+
} = details;
|
|
4881
|
+
switch (resourceType) {
|
|
4882
|
+
case MainFrame:
|
|
4883
|
+
return getBeforeRequestResponseMainFrame();
|
|
4884
|
+
case Script:
|
|
4885
|
+
return getBeforeRequestResponseScript(method, url);
|
|
4886
|
+
case Xhr:
|
|
4887
|
+
return getBeforeRequestResponseXhr(method, url);
|
|
4888
|
+
default:
|
|
4889
|
+
return getBeforeRequestResponseDefault();
|
|
4890
|
+
}
|
|
4891
|
+
};
|
|
4892
|
+
|
|
4893
|
+
/**
|
|
4894
|
+
*
|
|
4895
|
+
* @param {Electron.OnBeforeRequestListenerDetails } details
|
|
4896
|
+
* @param {(response: globalThis.Electron.CallbackResponse) => void} callback
|
|
4897
|
+
*/
|
|
4898
|
+
const handleBeforeRequest = (details, callback) => {
|
|
4899
|
+
const response = getBeforeRequestResponse(details);
|
|
4900
|
+
callback(response);
|
|
4901
|
+
};
|
|
4902
|
+
const filter = {
|
|
4903
|
+
// urls: ['https://*.youtube.com/*'],
|
|
4904
|
+
urls: ['<all_urls>']
|
|
4905
|
+
};
|
|
4906
|
+
|
|
4907
|
+
const state = {
|
|
4908
|
+
session: undefined
|
|
4909
|
+
};
|
|
4910
|
+
const isAllowedPermission = permission => {
|
|
4911
|
+
switch (permission) {
|
|
4912
|
+
case ClipBoardRead:
|
|
4913
|
+
case ClipBoardSanitizedWrite:
|
|
4914
|
+
case FullScreen:
|
|
4915
|
+
case GeoLocation:
|
|
4916
|
+
case WindowPlacement:
|
|
4917
|
+
return true;
|
|
4918
|
+
default:
|
|
4919
|
+
return false;
|
|
4920
|
+
}
|
|
4921
|
+
};
|
|
4922
|
+
const handlePermissionRequest = (webContents, permission, callback, details) => {
|
|
4923
|
+
callback(isAllowedPermission(permission));
|
|
4924
|
+
};
|
|
4925
|
+
const handlePermissionCheck = (webContents, permission, origin, details) => {
|
|
4926
|
+
return isAllowedPermission(permission);
|
|
4927
|
+
};
|
|
4928
|
+
const createSession = () => {
|
|
4929
|
+
const sessionId = `persist:browserView`;
|
|
4930
|
+
const session = Electron.session.fromPartition(sessionId, {
|
|
4931
|
+
cache: true
|
|
4932
|
+
});
|
|
4933
|
+
session.setPermissionRequestHandler(handlePermissionRequest);
|
|
4934
|
+
session.setPermissionCheckHandler(handlePermissionCheck);
|
|
4935
|
+
session.webRequest.onBeforeRequest(filter, handleBeforeRequest);
|
|
4936
|
+
// session.webRequest.addSessionChromeExtensions(session)
|
|
4937
|
+
return session;
|
|
4938
|
+
};
|
|
4939
|
+
const getSession = () => {
|
|
4940
|
+
state.session ||= createSession();
|
|
4941
|
+
return state.session;
|
|
4942
|
+
};
|
|
4943
|
+
|
|
4944
|
+
const assertLinux = () => {
|
|
4945
|
+
if (process.platform !== 'linux') {
|
|
4946
|
+
throw new Error('Importing Chrome cookies is only supported on Linux');
|
|
4947
|
+
}
|
|
4948
|
+
};
|
|
4949
|
+
const getInfoFromDirectory = chromeDataDirectory => {
|
|
4950
|
+
const profile = getActiveProfile(chromeDataDirectory);
|
|
4951
|
+
const cookieCount = getCookieCount(profile.cookieDatabasePath);
|
|
4952
|
+
return {
|
|
4953
|
+
cookieCount,
|
|
4954
|
+
profileDirectory: profile.directory,
|
|
4955
|
+
profileName: profile.name
|
|
4956
|
+
};
|
|
4957
|
+
};
|
|
4958
|
+
const getInfo = () => {
|
|
4959
|
+
assertLinux();
|
|
4960
|
+
return getInfoFromDirectory(getChromeDataDirectory());
|
|
4961
|
+
};
|
|
4962
|
+
const importFromDirectory = async (chromeDataDirectory, session) => {
|
|
4963
|
+
const profile = getActiveProfile(chromeDataDirectory);
|
|
4964
|
+
const {
|
|
4965
|
+
rows,
|
|
4966
|
+
version
|
|
4967
|
+
} = readCookies(profile.cookieDatabasePath);
|
|
4968
|
+
const cookies = [];
|
|
4969
|
+
let skipped = 0;
|
|
4970
|
+
let unsupportedEncryption = 0;
|
|
4971
|
+
for (const row of rows) {
|
|
4972
|
+
try {
|
|
4973
|
+
const cookie = convert(row, version);
|
|
4974
|
+
if (cookie) {
|
|
4975
|
+
cookies.push(cookie);
|
|
4976
|
+
} else {
|
|
4977
|
+
skipped++;
|
|
4978
|
+
}
|
|
4979
|
+
} catch (error) {
|
|
4980
|
+
skipped++;
|
|
4981
|
+
if (error instanceof UnsupportedChromeCookieEncryptionError) {
|
|
4982
|
+
unsupportedEncryption++;
|
|
4983
|
+
}
|
|
4984
|
+
}
|
|
4985
|
+
}
|
|
4986
|
+
if (cookies.length === 0 && unsupportedEncryption > 0) {
|
|
4987
|
+
throw new Error('Unsupported Chrome cookie encryption format');
|
|
4988
|
+
}
|
|
4989
|
+
let imported = 0;
|
|
4990
|
+
let failed = 0;
|
|
4991
|
+
for (const cookie of cookies) {
|
|
4992
|
+
try {
|
|
4993
|
+
await session.cookies.set(cookie);
|
|
4994
|
+
imported++;
|
|
4995
|
+
} catch {
|
|
4996
|
+
failed++;
|
|
4997
|
+
}
|
|
4998
|
+
}
|
|
4999
|
+
await session.cookies.flushStore();
|
|
5000
|
+
return {
|
|
5001
|
+
failed,
|
|
5002
|
+
imported,
|
|
5003
|
+
skipped
|
|
5004
|
+
};
|
|
5005
|
+
};
|
|
5006
|
+
const importCookies = async () => {
|
|
5007
|
+
assertLinux();
|
|
5008
|
+
return importFromDirectory(getChromeDataDirectory(), getSession());
|
|
5009
|
+
};
|
|
5010
|
+
|
|
4607
5011
|
const handleTimeout = () => {
|
|
4608
5012
|
throw new Error('oops');
|
|
4609
5013
|
};
|
|
@@ -5900,9 +6304,6 @@ const ElectronBrowserViewEventListenerWillNavigate = {
|
|
|
5900
6304
|
key: key$1
|
|
5901
6305
|
};
|
|
5902
6306
|
|
|
5903
|
-
const BackgroundTab = 'background-tab';
|
|
5904
|
-
const NewWindow = 'new-window';
|
|
5905
|
-
|
|
5906
6307
|
const key = 'window-open';
|
|
5907
6308
|
const attach = (webContents, listener) => {
|
|
5908
6309
|
webContents.setWindowOpenHandler(listener);
|
|
@@ -5911,38 +6312,11 @@ const detach = (webContents, listener) => {
|
|
|
5911
6312
|
webContents.setWindowOpenHandler(null);
|
|
5912
6313
|
};
|
|
5913
6314
|
const handler = ({
|
|
5914
|
-
disposition,
|
|
5915
|
-
features,
|
|
5916
|
-
frameName,
|
|
5917
|
-
postBody,
|
|
5918
|
-
referrer,
|
|
5919
6315
|
url
|
|
5920
6316
|
}) => {
|
|
5921
|
-
if (url
|
|
5922
|
-
|
|
5923
|
-
messages: [],
|
|
5924
|
-
result: {
|
|
5925
|
-
action: Allow
|
|
5926
|
-
}
|
|
5927
|
-
};
|
|
5928
|
-
}
|
|
5929
|
-
if (disposition === BackgroundTab) {
|
|
5930
|
-
return {
|
|
5931
|
-
messages: [['handleWindowOpen', url]],
|
|
5932
|
-
result: {
|
|
5933
|
-
action: Deny
|
|
5934
|
-
}
|
|
5935
|
-
};
|
|
5936
|
-
}
|
|
5937
|
-
if (disposition === NewWindow) {
|
|
5938
|
-
return {
|
|
5939
|
-
messages: [],
|
|
5940
|
-
result: {
|
|
5941
|
-
action: Allow
|
|
5942
|
-
}
|
|
5943
|
-
};
|
|
6317
|
+
if (shouldOpenExternal(url)) {
|
|
6318
|
+
void openExternal(url);
|
|
5944
6319
|
}
|
|
5945
|
-
info(`[main-process] blocked popup for ${url}`);
|
|
5946
6320
|
return {
|
|
5947
6321
|
messages: [],
|
|
5948
6322
|
result: {
|
|
@@ -5970,136 +6344,6 @@ const ElectronBrowserViewEventListeners = {
|
|
|
5970
6344
|
windowOpen: ElectronBrowserViewEventListenerWindowOpen
|
|
5971
6345
|
};
|
|
5972
6346
|
|
|
5973
|
-
const MainFrame = 'mainFrame';
|
|
5974
|
-
const Script = 'script';
|
|
5975
|
-
const Xhr = 'xhr';
|
|
5976
|
-
|
|
5977
|
-
const Get = 'GET';
|
|
5978
|
-
const Head = 'HEAD';
|
|
5979
|
-
const Options = 'OPTIONS';
|
|
5980
|
-
const Post = 'POST';
|
|
5981
|
-
|
|
5982
|
-
// @ts-ignore
|
|
5983
|
-
|
|
5984
|
-
const getBeforeRequestResponseMainFrame = (method, url) => {
|
|
5985
|
-
return {};
|
|
5986
|
-
};
|
|
5987
|
-
const cancelIfStartsWith = (url, canceledUrls) => {
|
|
5988
|
-
for (const canceledUrl of canceledUrls) {
|
|
5989
|
-
if (url.startsWith(canceledUrl)) {
|
|
5990
|
-
return {
|
|
5991
|
-
cancel: true
|
|
5992
|
-
};
|
|
5993
|
-
}
|
|
5994
|
-
}
|
|
5995
|
-
return {};
|
|
5996
|
-
};
|
|
5997
|
-
const getBeforeRequestResponseXhrPost = url => {
|
|
5998
|
-
const canceledUrls = ['https://www.youtube.com/api/stats/qoe', 'https://www.youtube.com/youtubei/v1/log_event', 'https://play.google.com/log'];
|
|
5999
|
-
return cancelIfStartsWith(url, canceledUrls);
|
|
6000
|
-
};
|
|
6001
|
-
const getBeforeRequestResponseXhrGet = url => {
|
|
6002
|
-
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'];
|
|
6003
|
-
return cancelIfStartsWith(url, canceledUrls);
|
|
6004
|
-
};
|
|
6005
|
-
const getBeforeRequestResponseXhrOptions = url => {
|
|
6006
|
-
const canceledUrls = ['https://play.google.com/log'];
|
|
6007
|
-
return cancelIfStartsWith(url, canceledUrls);
|
|
6008
|
-
};
|
|
6009
|
-
const getBeforeRequestResponseXhrHead = url => {
|
|
6010
|
-
const canceledUrls = ['https://www.youtube.com/generate_204'];
|
|
6011
|
-
return cancelIfStartsWith(url, canceledUrls);
|
|
6012
|
-
};
|
|
6013
|
-
const getBeforeRequestResponseXhr = (method, url) => {
|
|
6014
|
-
switch (method) {
|
|
6015
|
-
case Get:
|
|
6016
|
-
return getBeforeRequestResponseXhrGet(url);
|
|
6017
|
-
case Head:
|
|
6018
|
-
return getBeforeRequestResponseXhrHead(url);
|
|
6019
|
-
case Options:
|
|
6020
|
-
return getBeforeRequestResponseXhrOptions(url);
|
|
6021
|
-
case Post:
|
|
6022
|
-
return getBeforeRequestResponseXhrPost(url);
|
|
6023
|
-
default:
|
|
6024
|
-
return {};
|
|
6025
|
-
}
|
|
6026
|
-
};
|
|
6027
|
-
const getBeforeRequestResponseDefault = (method, url) => {
|
|
6028
|
-
return {};
|
|
6029
|
-
};
|
|
6030
|
-
const getBeforeRequestResponseScript = (method, url) => {
|
|
6031
|
-
const canceledUrls = ['https://static.doubleclick.net'];
|
|
6032
|
-
return cancelIfStartsWith(url, canceledUrls);
|
|
6033
|
-
};
|
|
6034
|
-
const getBeforeRequestResponse = details => {
|
|
6035
|
-
const {
|
|
6036
|
-
method,
|
|
6037
|
-
resourceType,
|
|
6038
|
-
url
|
|
6039
|
-
} = details;
|
|
6040
|
-
switch (resourceType) {
|
|
6041
|
-
case MainFrame:
|
|
6042
|
-
return getBeforeRequestResponseMainFrame();
|
|
6043
|
-
case Script:
|
|
6044
|
-
return getBeforeRequestResponseScript(method, url);
|
|
6045
|
-
case Xhr:
|
|
6046
|
-
return getBeforeRequestResponseXhr(method, url);
|
|
6047
|
-
default:
|
|
6048
|
-
return getBeforeRequestResponseDefault();
|
|
6049
|
-
}
|
|
6050
|
-
};
|
|
6051
|
-
|
|
6052
|
-
/**
|
|
6053
|
-
*
|
|
6054
|
-
* @param {Electron.OnBeforeRequestListenerDetails } details
|
|
6055
|
-
* @param {(response: globalThis.Electron.CallbackResponse) => void} callback
|
|
6056
|
-
*/
|
|
6057
|
-
const handleBeforeRequest = (details, callback) => {
|
|
6058
|
-
const response = getBeforeRequestResponse(details);
|
|
6059
|
-
callback(response);
|
|
6060
|
-
};
|
|
6061
|
-
const filter = {
|
|
6062
|
-
// urls: ['https://*.youtube.com/*'],
|
|
6063
|
-
urls: ['<all_urls>']
|
|
6064
|
-
};
|
|
6065
|
-
|
|
6066
|
-
const state = {
|
|
6067
|
-
session: undefined
|
|
6068
|
-
};
|
|
6069
|
-
const isAllowedPermission = permission => {
|
|
6070
|
-
switch (permission) {
|
|
6071
|
-
case ClipBoardRead:
|
|
6072
|
-
case ClipBoardSanitizedWrite:
|
|
6073
|
-
case FullScreen:
|
|
6074
|
-
case GeoLocation:
|
|
6075
|
-
case WindowPlacement:
|
|
6076
|
-
return true;
|
|
6077
|
-
default:
|
|
6078
|
-
return false;
|
|
6079
|
-
}
|
|
6080
|
-
};
|
|
6081
|
-
const handlePermissionRequest = (webContents, permission, callback, details) => {
|
|
6082
|
-
callback(isAllowedPermission(permission));
|
|
6083
|
-
};
|
|
6084
|
-
const handlePermissionCheck = (webContents, permission, origin, details) => {
|
|
6085
|
-
return isAllowedPermission(permission);
|
|
6086
|
-
};
|
|
6087
|
-
const createSession = () => {
|
|
6088
|
-
const sessionId = `persist:browserView`;
|
|
6089
|
-
const session = Electron.session.fromPartition(sessionId, {
|
|
6090
|
-
cache: true
|
|
6091
|
-
});
|
|
6092
|
-
session.setPermissionRequestHandler(handlePermissionRequest);
|
|
6093
|
-
session.setPermissionCheckHandler(handlePermissionCheck);
|
|
6094
|
-
session.webRequest.onBeforeRequest(filter, handleBeforeRequest);
|
|
6095
|
-
// session.webRequest.addSessionChromeExtensions(session)
|
|
6096
|
-
return session;
|
|
6097
|
-
};
|
|
6098
|
-
const getSession = () => {
|
|
6099
|
-
state.session ||= createSession();
|
|
6100
|
-
return state.session;
|
|
6101
|
-
};
|
|
6102
|
-
|
|
6103
6347
|
const send = (method, ...params) => {
|
|
6104
6348
|
const rpc = get(EmbedsProcess);
|
|
6105
6349
|
if (!rpc) {
|
|
@@ -6688,6 +6932,8 @@ const trash = async path => {
|
|
|
6688
6932
|
const commandMap = {
|
|
6689
6933
|
'AppWindow.createAppWindow': createAppWindow,
|
|
6690
6934
|
'Beep.beep': beep$1,
|
|
6935
|
+
'ChromeCookieImport.getInfo': getInfo,
|
|
6936
|
+
'ChromeCookieImport.importCookies': importCookies,
|
|
6691
6937
|
'Crash.crashMainProcess': crashMainProcess$1,
|
|
6692
6938
|
'CreateMessagePort.createMessagePort': createMessagePort,
|
|
6693
6939
|
'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.15.0",
|
|
4
4
|
"keywords": [
|
|
5
5
|
"lvce-editor",
|
|
6
6
|
"electron"
|
|
@@ -14,7 +14,7 @@
|
|
|
14
14
|
"type": "module",
|
|
15
15
|
"main": "dist/mainProcessMain.js",
|
|
16
16
|
"dependencies": {
|
|
17
|
-
"electron": "43.
|
|
17
|
+
"electron": "43.2.0"
|
|
18
18
|
},
|
|
19
19
|
"engines": {
|
|
20
20
|
"node": ">=22"
|