@lvce-editor/main-process 6.46.1 → 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.
@@ -5689,7 +5689,7 @@ const openContextMenu = async (menuItems, x, y, browserViewId) => {
5689
5689
  };
5690
5690
 
5691
5691
  const profileDuration = 10_000;
5692
- const getFileName$1 = targetName => {
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$1(targetName));
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 {
@@ -6741,40 +6831,44 @@ const attach$9 = (webContents, listener) => {
6741
6831
  const detach$6 = (webContents, listener) => {
6742
6832
  webContents.off(PageFaviconUpdated, listener);
6743
6833
  };
6744
- const getFaviconDataUrl = async (fetcher, favicon, signal) => {
6834
+ const getFaviconData = async (fetcher, favicon, signal) => {
6745
6835
  try {
6746
6836
  const response = await fetcher(favicon, {
6747
6837
  signal
6748
6838
  });
6749
6839
  if (!response.ok) {
6750
- return '';
6840
+ return undefined;
6751
6841
  }
6752
6842
  const contentLength = Number(response.headers.get('content-length'));
6753
6843
  if (contentLength > maxFaviconBytes) {
6754
- return '';
6844
+ return undefined;
6755
6845
  }
6756
- const bytes = Buffer.from(await response.arrayBuffer());
6846
+ const bytes = new Uint8Array(await response.arrayBuffer());
6757
6847
  if (bytes.byteLength > maxFaviconBytes) {
6758
- return '';
6848
+ return undefined;
6759
6849
  }
6760
6850
  const contentType = response.headers.get('content-type') || 'image/x-icon';
6761
6851
  const mimeType = contentType.split(';', 1)[0].trim();
6762
6852
  if (!mimeType.startsWith('image/') && mimeType !== 'application/octet-stream') {
6763
- return '';
6853
+ return undefined;
6764
6854
  }
6765
- return `data:${mimeType};base64,${bytes.toString('base64')}`;
6855
+ return {
6856
+ bytes,
6857
+ mimeType,
6858
+ url: favicon
6859
+ };
6766
6860
  } catch {
6767
- return '';
6861
+ return undefined;
6768
6862
  }
6769
6863
  };
6770
6864
  const resolveWithFetcher = async (fetcher, favicons, signal) => {
6771
6865
  for (const favicon of favicons) {
6772
- const dataUrl = await getFaviconDataUrl(fetcher, favicon, signal);
6773
- if (dataUrl) {
6774
- return dataUrl;
6866
+ const data = await getFaviconData(fetcher, favicon, signal);
6867
+ if (data) {
6868
+ return data;
6775
6869
  }
6776
6870
  }
6777
- return '';
6871
+ return undefined;
6778
6872
  };
6779
6873
  const resolveWithTimeout = async (fetcher, favicons) => {
6780
6874
  const controller = new AbortController();
@@ -6782,7 +6876,7 @@ const resolveWithTimeout = async (fetcher, favicons) => {
6782
6876
  const timeoutPromise = new Promise(resolve => {
6783
6877
  timeout = setTimeout(() => {
6784
6878
  controller.abort();
6785
- resolve('');
6879
+ resolve(undefined);
6786
6880
  }, faviconFetchTimeout);
6787
6881
  });
6788
6882
  try {
@@ -6794,7 +6888,8 @@ const resolveWithTimeout = async (fetcher, favicons) => {
6794
6888
  const resolveFavicon = async (webContents, favicons) => {
6795
6889
  const dataUrl = favicons.find(favicon => favicon.startsWith('data:'));
6796
6890
  if (dataUrl) {
6797
- return [dataUrl];
6891
+ const data = await resolveWithTimeout((url, options) => fetch(url, options), [dataUrl]);
6892
+ return data ? [data] : [dataUrl];
6798
6893
  }
6799
6894
  const sessionFavicon = await resolveWithTimeout((url, options) => webContents.session.fetch(url, options), favicons);
6800
6895
  if (sessionFavicon) {
@@ -6806,7 +6901,8 @@ const resolveFavicon = async (webContents, favicons) => {
6806
6901
  const resolveNetworkFavicon = async favicons => {
6807
6902
  const dataUrl = favicons.find(favicon => favicon.startsWith('data:'));
6808
6903
  if (dataUrl) {
6809
- return [dataUrl];
6904
+ const data = await resolveWithTimeout((url, options) => fetch(url, options), [dataUrl]);
6905
+ return data ? [data] : [dataUrl];
6810
6906
  }
6811
6907
  const networkFavicon = await resolveWithTimeout((url, options) => fetch(url, options), favicons);
6812
6908
  return networkFavicon ? [networkFavicon] : [];
@@ -8180,6 +8276,7 @@ const commandMap = {
8180
8276
  'ElectronContextMenu.openContextMenu': openContextMenu,
8181
8277
  'ElectronDeveloper.crashMainProcess': crashMainProcess,
8182
8278
  'ElectronDeveloper.getPerformanceEntries': getPerformanceEntries,
8279
+ 'ElectronDeveloper.takeRendererHeapSnapshot': takeRendererHeapSnapshot,
8183
8280
  'ElectronDeveloper.takeWindowCpuProfile': takeWindowCpuProfile,
8184
8281
  'ElectronDeveloper.takeWorkerCpuProfile': takeWorkerCpuProfile,
8185
8282
  'ElectronDeveloper.takeWorkerHeapSnapshot': takeWorkerHeapSnapshot,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lvce-editor/main-process",
3
- "version": "6.46.1",
3
+ "version": "6.47.0",
4
4
  "keywords": [
5
5
  "lvce-editor",
6
6
  "electron"