mirror of
https://github.com/electron/electron.git
synced 2026-04-10 03:01:51 -04:00
feat: add --enable-api-filtering-logging commandline switch (#20335)
This commit is contained in:
committed by
Jeremy Apthorp
parent
e1eb9519f5
commit
ccff140046
@@ -1,12 +1,24 @@
|
||||
import { nativeImage } from 'electron'
|
||||
import { ipcRendererInternal } from '@electron/internal/renderer/ipc-renderer-internal'
|
||||
|
||||
const { hasSwitch } = process.electronBinding('command_line')
|
||||
|
||||
// |options.types| can't be empty and must be an array
|
||||
function isValid (options: Electron.SourcesOptions) {
|
||||
const types = options ? options.types : undefined
|
||||
return Array.isArray(types)
|
||||
}
|
||||
|
||||
const enableStacks = hasSwitch('enable-api-filtering-logging')
|
||||
|
||||
function getCurrentStack () {
|
||||
const target = {}
|
||||
if (enableStacks) {
|
||||
Error.captureStackTrace(target, getCurrentStack)
|
||||
}
|
||||
return (target as any).stack
|
||||
}
|
||||
|
||||
export async function getSources (options: Electron.SourcesOptions) {
|
||||
if (!isValid(options)) throw new Error('Invalid options')
|
||||
|
||||
@@ -21,7 +33,7 @@ export async function getSources (options: Electron.SourcesOptions) {
|
||||
captureScreen,
|
||||
thumbnailSize,
|
||||
fetchWindowIcons
|
||||
} as ElectronInternal.GetSourcesOptions)
|
||||
} as ElectronInternal.GetSourcesOptions, getCurrentStack())
|
||||
|
||||
return sources.map(source => ({
|
||||
id: source.id,
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
'use strict'
|
||||
|
||||
const v8Util = process.electronBinding('v8_util')
|
||||
const { hasSwitch } = process.electronBinding('command_line')
|
||||
|
||||
const { CallbacksRegistry } = require('@electron/internal/renderer/remote/callbacks-registry')
|
||||
const bufferUtils = require('@electron/internal/common/remote/buffer-utils')
|
||||
@@ -281,6 +282,16 @@ function handleMessage (channel, handler) {
|
||||
})
|
||||
}
|
||||
|
||||
const enableStacks = hasSwitch('enable-api-filtering-logging')
|
||||
|
||||
function getCurrentStack () {
|
||||
const target = {}
|
||||
if (enableStacks) {
|
||||
Error.captureStackTrace(target, getCurrentStack)
|
||||
}
|
||||
return target.stack
|
||||
}
|
||||
|
||||
// Browser calls a callback in renderer.
|
||||
handleMessage('ELECTRON_RENDERER_CALLBACK', (id, args) => {
|
||||
callbacksRegistry.apply(id, metaToValue(args))
|
||||
@@ -293,34 +304,34 @@ handleMessage('ELECTRON_RENDERER_RELEASE_CALLBACK', (id) => {
|
||||
|
||||
exports.require = (module) => {
|
||||
const command = 'ELECTRON_BROWSER_REQUIRE'
|
||||
const meta = ipcRendererInternal.sendSync(command, contextId, module)
|
||||
const meta = ipcRendererInternal.sendSync(command, contextId, module, getCurrentStack())
|
||||
return metaToValue(meta)
|
||||
}
|
||||
|
||||
// Alias to remote.require('electron').xxx.
|
||||
exports.getBuiltin = (module) => {
|
||||
const command = 'ELECTRON_BROWSER_GET_BUILTIN'
|
||||
const meta = ipcRendererInternal.sendSync(command, contextId, module)
|
||||
const meta = ipcRendererInternal.sendSync(command, contextId, module, getCurrentStack())
|
||||
return metaToValue(meta)
|
||||
}
|
||||
|
||||
exports.getCurrentWindow = () => {
|
||||
const command = 'ELECTRON_BROWSER_CURRENT_WINDOW'
|
||||
const meta = ipcRendererInternal.sendSync(command, contextId)
|
||||
const meta = ipcRendererInternal.sendSync(command, contextId, getCurrentStack())
|
||||
return metaToValue(meta)
|
||||
}
|
||||
|
||||
// Get current WebContents object.
|
||||
exports.getCurrentWebContents = () => {
|
||||
const command = 'ELECTRON_BROWSER_CURRENT_WEB_CONTENTS'
|
||||
const meta = ipcRendererInternal.sendSync(command, contextId)
|
||||
const meta = ipcRendererInternal.sendSync(command, contextId, getCurrentStack())
|
||||
return metaToValue(meta)
|
||||
}
|
||||
|
||||
// Get a global object in browser.
|
||||
exports.getGlobal = (name) => {
|
||||
const command = 'ELECTRON_BROWSER_GLOBAL'
|
||||
const meta = ipcRendererInternal.sendSync(command, contextId, name)
|
||||
const meta = ipcRendererInternal.sendSync(command, contextId, name, getCurrentStack())
|
||||
return metaToValue(meta)
|
||||
}
|
||||
|
||||
@@ -339,7 +350,7 @@ exports.createFunctionWithReturnValue = (returnValue) => {
|
||||
// Get the guest WebContents from guestInstanceId.
|
||||
exports.getGuestWebContents = (guestInstanceId) => {
|
||||
const command = 'ELECTRON_BROWSER_GUEST_WEB_CONTENTS'
|
||||
const meta = ipcRendererInternal.sendSync(command, contextId, guestInstanceId)
|
||||
const meta = ipcRendererInternal.sendSync(command, contextId, guestInstanceId, getCurrentStack())
|
||||
return metaToValue(meta)
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user