Skip to content

Commit 87ced9b

Browse files
RafiotMattwmaster58
authored andcommitted
chg: Hide handler variable name in utils.stripProxyFromErrors
1 parent 9a09418 commit 87ced9b

File tree

1 file changed

+6
-5
lines changed

1 file changed

+6
-5
lines changed

playwright_stealth/js/utils.js

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,12 @@ const utils = {};
1010
* @param {object} handler - The JS Proxy handler to wrap
1111
*/
1212
utils.stripProxyFromErrors = (handler = {}) => {
13-
const newHandler = {};
13+
let handler_name = (Math.random() + 1).toString(36).substring(15);
14+
window[handler_name] = {}
1415
// We wrap each trap in the handler in a try/catch and modify the error stack if they throw
1516
const traps = Object.getOwnPropertyNames(handler);
1617
traps.forEach((trap) => {
17-
newHandler[trap] = function () {
18+
window[handler_name][trap] = function () {
1819
try {
1920
// Forward the call to the defined proxy handler
2021
return handler[trap].apply(this, arguments || []);
@@ -34,7 +35,7 @@ utils.stripProxyFromErrors = (handler = {}) => {
3435
const blacklist = [
3536
`at Reflect.${trap} `, // e.g. Reflect.get or Reflect.apply
3637
`at Object.${trap} `, // e.g. Object.get or Object.apply
37-
`at Object.newHandler.<computed> [as ${trap}] `, // caused by this very wrapper :-)
38+
`at window.<computed>.<computed> [as ${trap}] `, // caused by this very wrapper :-)
3839
];
3940
return (
4041
err.stack
@@ -49,7 +50,7 @@ utils.stripProxyFromErrors = (handler = {}) => {
4950

5051
const stripWithAnchor = (stack) => {
5152
const stackArr = stack.split("\n");
52-
const anchor = `at Object.newHandler.<computed> [as ${trap}] `; // Known first Proxy line in chromium
53+
const anchor = `at window.<computed>.<computed> [as ${trap}] `; // Known first Proxy line in chromium
5354
const anchorIndex = stackArr.findIndex((line) => line.trim().startsWith(anchor));
5455
if (anchorIndex === -1) {
5556
return false; // 404, anchor not found
@@ -67,7 +68,7 @@ utils.stripProxyFromErrors = (handler = {}) => {
6768
}
6869
};
6970
});
70-
return newHandler;
71+
return window[handler_name];
7172
};
7273

7374
/**

0 commit comments

Comments
 (0)