Skip to content
This repository has been archived by the owner on Sep 16, 2024. It is now read-only.

Commit

Permalink
fix(browser-emulator): properly clean error stack
Browse files Browse the repository at this point in the history
  • Loading branch information
blakebyrnes committed Apr 18, 2024
1 parent caa5a5d commit 05521ad
Showing 1 changed file with 19 additions and 10 deletions.
29 changes: 19 additions & 10 deletions plugins/default-browser-emulator/injected-scripts/_proxyUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,11 @@ function internalCreateFnProxy(
if (!isFromObjectSetPrototypeOf) {
const stack = new ErrorCached().stack.split(/\r?\n/);

if (stack[1].includes('Object.setPrototypeOf') && stack[1].includes(sourceUrl) && !stack[2].includes('Reflect.setPrototypeOf')) {
if (
stack[1].includes('Object.setPrototypeOf') &&
stack[1].includes(sourceUrl) &&
!stack[2].includes('Reflect.setPrototypeOf')
) {
isFromObjectSetPrototypeOf = true;
}
}
Expand Down Expand Up @@ -348,18 +352,23 @@ function defaultProxyApply<T, K extends keyof T>(
args: [target: any, thisArg: T, argArray: any[]],
overrideFn?: (target?: T[K], thisArg?: T, argArray?: any[]) => T[K] | ProxyOverride,
): any {
if (!overrideFn) {
return ReflectCached.apply(...args);
}
let result: T[K] | ProxyOverride;
try {
result = overrideFn(...args);
} catch (err) {
throw cleanErrorStack(err);
let result: T[K] | ProxyOverride = ProxyOverride.callOriginal;
if (overrideFn) {
try {
result = overrideFn(...args);
} catch (err) {
throw cleanErrorStack(err);
}
}

if (result === ProxyOverride.callOriginal) {
return ReflectCached.apply(...args);
try {
result = ReflectCached.apply(...args);
} catch (err) {
throw cleanErrorStack(err);
}
}

// Try to make clean error stacks for tenables, but don't crash if
// for some reason this doesn't work. Crashing here could have
// a huge impact on other things.
Expand Down

0 comments on commit 05521ad

Please sign in to comment.