eval done && fix findDOMNode warning

This commit is contained in:
go0p
2024-05-14 23:02:40 +08:00
parent cb65d57cef
commit dd1b2a9513
10 changed files with 87 additions and 102 deletions
+11 -5
View File
@@ -8,24 +8,30 @@
if (event.source !== window) {
return;
}
let result = "";
let result
switch (event.data.type) {
case 'CONTENT_CALL_FUNCTION':
const fn_name = event.data.value.fn_name;
const args = event.data.value.args;
result = window[fn_name](args);
window.postMessage({type: 'FROM_INJECT_JS', result: result}, '*');
break;
case 'CONTENT_EVAL_CODE':
const code = event.data.value.code;
result = eval(code);
result = (() => {
try {
return eval(code);
} catch (e) {
// console.error("Error evaluating code:", e);
return e.toString();
}
})();
// console.log("CONTENT_EVAL_CODE result: ", result);
window.postMessage({type: 'FROM_INJECT_JS', result: result}, '*');
break;
default:
break;
}
if (result && typeof result === 'object' && Object.keys(result).length > 0) {
window.postMessage({type: 'FROM_PAGE', result: result}, '*');
}
});
})();