gpt4 book ai didi

javascript - 使用 Chrome Devtools 查找哪个变量保存有值

转载 作者:行者123 更新时间:2023-12-02 11:26:29 26 4
gpt4 key购买 nike

我正在尝试访问远程 Web 应用程序中的某些值来构建 Chrome 扩展程序。

为此,我想找到哪个 JS 变量保存给定值,并且我想知道是否可以对内存中所有变量的值进行某种“全局搜索”。

使用任何工具都可以做到这一点吗?检查员、分析员等...?

最佳答案

所有功劳为 this answer goes to tomwrong 。有关此代码片段的问题/改进的更多详细信息,请参阅他的回答。

代码

function globalSearch(startObject, value) {
var stack = [[startObject,'']];
var searched = [];
var found = false;

var isArray = function(test) {
return Object.prototype.toString.call( test ) === '[object Array]';
}

while(stack.length) {
var fromStack = stack.pop();
var obj = fromStack[0];
var address = fromStack[1];

if( typeof obj == typeof value && obj == value) {
var found = address;
break;
}else if(typeof obj == "object" && searched.indexOf(obj) == -1){
if ( isArray(obj) ) {
var prefix = '[';
var postfix = ']';
}else {
var prefix = '.';
var postfix = '';
}
for( i in obj ) {
stack.push( [ obj[i], address + prefix + i + postfix ] );
}
searched.push(obj);
}
}
return found == '' ? true : found;
}

关于javascript - 使用 Chrome Devtools 查找哪个变量保存有值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26796873/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com