@lvce-editor/main-process 6.46.2 → 6.47.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 +95 -4
- package/package.json +1 -1
package/dist/mainProcessMain.js
CHANGED
|
@@ -5689,7 +5689,7 @@ const openContextMenu = async (menuItems, x, y, browserViewId) => {
|
|
|
5689
5689
|
};
|
|
5690
5690
|
|
|
5691
5691
|
const profileDuration = 10_000;
|
|
5692
|
-
const getFileName$
|
|
5692
|
+
const getFileName$2 = targetName => {
|
|
5693
5693
|
const safeTargetName = targetName.replaceAll(/[^a-zA-Z0-9._-]+/g, '-').replace(/^-/, '').replace(/-$/, '') || 'extension-host';
|
|
5694
5694
|
return `${safeTargetName}-${Date.now()}.cpuprofile`;
|
|
5695
5695
|
};
|
|
@@ -5744,7 +5744,7 @@ const takeCpuProfile = async (windowId, workerName) => {
|
|
|
5744
5744
|
recursive: true
|
|
5745
5745
|
});
|
|
5746
5746
|
const targetName = workerName || `Extension Host Window ${windowId}`;
|
|
5747
|
-
filePath = join$1(downloadsPath, getFileName$
|
|
5747
|
+
filePath = join$1(downloadsPath, getFileName$2(targetName));
|
|
5748
5748
|
writeFileSync(filePath, JSON.stringify(profile), {
|
|
5749
5749
|
flag: 'wx'
|
|
5750
5750
|
});
|
|
@@ -5788,7 +5788,7 @@ const takeWorkerCpuProfile = async (windowId, workerName) => {
|
|
|
5788
5788
|
return takeCpuProfile(windowId, workerName);
|
|
5789
5789
|
};
|
|
5790
5790
|
|
|
5791
|
-
const getFileName = workerName => {
|
|
5791
|
+
const getFileName$1 = workerName => {
|
|
5792
5792
|
const safeWorkerName = workerName.replaceAll(/[^a-zA-Z0-9._-]+/g, '-').replace(/^-/, '').replace(/-$/, '') || 'worker';
|
|
5793
5793
|
return `${safeWorkerName}-${Date.now()}.heapsnapshot`;
|
|
5794
5794
|
};
|
|
@@ -5828,7 +5828,7 @@ const takeWorkerHeapSnapshot = async (windowId, workerName) => {
|
|
|
5828
5828
|
mkdirSync(downloadsPath, {
|
|
5829
5829
|
recursive: true
|
|
5830
5830
|
});
|
|
5831
|
-
filePath = join$1(downloadsPath, getFileName(workerName));
|
|
5831
|
+
filePath = join$1(downloadsPath, getFileName$1(workerName));
|
|
5832
5832
|
fileDescriptor = openSync(filePath, 'wx');
|
|
5833
5833
|
const currentFileDescriptor = fileDescriptor;
|
|
5834
5834
|
let writeError;
|
|
@@ -5882,6 +5882,96 @@ const takeWorkerHeapSnapshot = async (windowId, workerName) => {
|
|
|
5882
5882
|
}
|
|
5883
5883
|
};
|
|
5884
5884
|
|
|
5885
|
+
const getFileName = pid => {
|
|
5886
|
+
return `renderer-${pid}-${Date.now()}.heapsnapshot`;
|
|
5887
|
+
};
|
|
5888
|
+
const getRendererWebContents = pid => {
|
|
5889
|
+
for (const browserWindow of Electron.BrowserWindow.getAllWindows()) {
|
|
5890
|
+
const {
|
|
5891
|
+
webContents
|
|
5892
|
+
} = browserWindow;
|
|
5893
|
+
if (webContents.getOSProcessId() === pid) {
|
|
5894
|
+
return webContents;
|
|
5895
|
+
}
|
|
5896
|
+
}
|
|
5897
|
+
for (const value of getAll()) {
|
|
5898
|
+
const {
|
|
5899
|
+
webContents
|
|
5900
|
+
} = value.view;
|
|
5901
|
+
if (webContents.getOSProcessId() === pid) {
|
|
5902
|
+
return webContents;
|
|
5903
|
+
}
|
|
5904
|
+
}
|
|
5905
|
+
return undefined;
|
|
5906
|
+
};
|
|
5907
|
+
const takeRendererHeapSnapshot = async pid => {
|
|
5908
|
+
number(pid);
|
|
5909
|
+
const webContents = getRendererWebContents(pid);
|
|
5910
|
+
if (!webContents) {
|
|
5911
|
+
throw new Error(`Renderer process not found: ${pid}`);
|
|
5912
|
+
}
|
|
5913
|
+
if (webContents.isDestroyed()) {
|
|
5914
|
+
throw new Error(`Renderer process was destroyed: ${pid}`);
|
|
5915
|
+
}
|
|
5916
|
+
const electronDebugger = webContents.debugger;
|
|
5917
|
+
const wasAttached = electronDebugger.isAttached();
|
|
5918
|
+
let fileDescriptor;
|
|
5919
|
+
let filePath = '';
|
|
5920
|
+
let writeError;
|
|
5921
|
+
let success = false;
|
|
5922
|
+
if (!wasAttached) {
|
|
5923
|
+
electronDebugger.attach();
|
|
5924
|
+
}
|
|
5925
|
+
try {
|
|
5926
|
+
const downloadsPath = Electron.app.getPath('downloads');
|
|
5927
|
+
mkdirSync(downloadsPath, {
|
|
5928
|
+
recursive: true
|
|
5929
|
+
});
|
|
5930
|
+
filePath = join$1(downloadsPath, getFileName(pid));
|
|
5931
|
+
fileDescriptor = openSync(filePath, 'wx');
|
|
5932
|
+
const currentFileDescriptor = fileDescriptor;
|
|
5933
|
+
const handleMessage = (_event, method, parameters, sessionId) => {
|
|
5934
|
+
if (method !== 'HeapProfiler.addHeapSnapshotChunk' || sessionId || writeError) {
|
|
5935
|
+
return;
|
|
5936
|
+
}
|
|
5937
|
+
try {
|
|
5938
|
+
writeSync(currentFileDescriptor, parameters.chunk);
|
|
5939
|
+
} catch (error) {
|
|
5940
|
+
writeError = error;
|
|
5941
|
+
}
|
|
5942
|
+
};
|
|
5943
|
+
electronDebugger.on('message', handleMessage);
|
|
5944
|
+
try {
|
|
5945
|
+
await electronDebugger.sendCommand('HeapProfiler.enable');
|
|
5946
|
+
await electronDebugger.sendCommand('HeapProfiler.takeHeapSnapshot', {
|
|
5947
|
+
reportProgress: false
|
|
5948
|
+
});
|
|
5949
|
+
if (writeError) {
|
|
5950
|
+
throw writeError;
|
|
5951
|
+
}
|
|
5952
|
+
} finally {
|
|
5953
|
+
electronDebugger.off('message', handleMessage);
|
|
5954
|
+
}
|
|
5955
|
+
success = true;
|
|
5956
|
+
return pathToFileURL(filePath).href;
|
|
5957
|
+
} finally {
|
|
5958
|
+
try {
|
|
5959
|
+
if (fileDescriptor !== undefined) {
|
|
5960
|
+
closeSync(fileDescriptor);
|
|
5961
|
+
}
|
|
5962
|
+
if (!success && filePath) {
|
|
5963
|
+
rmSync(filePath, {
|
|
5964
|
+
force: true
|
|
5965
|
+
});
|
|
5966
|
+
}
|
|
5967
|
+
} finally {
|
|
5968
|
+
if (!wasAttached && electronDebugger.isAttached()) {
|
|
5969
|
+
electronDebugger.detach();
|
|
5970
|
+
}
|
|
5971
|
+
}
|
|
5972
|
+
}
|
|
5973
|
+
};
|
|
5974
|
+
|
|
5885
5975
|
const getPerformanceEntries = () => {
|
|
5886
5976
|
const entries = getEntries();
|
|
5887
5977
|
const {
|
|
@@ -8186,6 +8276,7 @@ const commandMap = {
|
|
|
8186
8276
|
'ElectronContextMenu.openContextMenu': openContextMenu,
|
|
8187
8277
|
'ElectronDeveloper.crashMainProcess': crashMainProcess,
|
|
8188
8278
|
'ElectronDeveloper.getPerformanceEntries': getPerformanceEntries,
|
|
8279
|
+
'ElectronDeveloper.takeRendererHeapSnapshot': takeRendererHeapSnapshot,
|
|
8189
8280
|
'ElectronDeveloper.takeWindowCpuProfile': takeWindowCpuProfile,
|
|
8190
8281
|
'ElectronDeveloper.takeWorkerCpuProfile': takeWorkerCpuProfile,
|
|
8191
8282
|
'ElectronDeveloper.takeWorkerHeapSnapshot': takeWorkerHeapSnapshot,
|