SimpleChatTC:Promises: trap normal fetch (dont care await or not)

This commit is contained in:
hanishkvc 2025-10-15 22:10:27 +05:30
parent 0241b7b469
commit 92e5b2133e
1 changed files with 9 additions and 0 deletions

View File

@ -15,6 +15,8 @@
*/ */
export async function evalWithPromiseTracking(codeToEval) { export async function evalWithPromiseTracking(codeToEval) {
const _Promise = globalThis.Promise; const _Promise = globalThis.Promise;
const _fetch = globalThis.fetch
/** @type {any[]} */ /** @type {any[]} */
const trackedPromises = []; const trackedPromises = [];
@ -43,6 +45,13 @@ export async function evalWithPromiseTracking(codeToEval) {
Promise.prototype = _Promise.prototype; Promise.prototype = _Promise.prototype;
Object.assign(Promise, _Promise); Object.assign(Promise, _Promise);
const fetch = function(/** @type {any[]} */ ...args) {
console.info("WW:PT:Fetch")
const fpromise = _fetch(args);
trackedPromises.push(fpromise)
return fpromise;
}
eval(codeToEval); eval(codeToEval);
//await Promise(resolve=>setTimeout(resolve, 0)); //await Promise(resolve=>setTimeout(resolve, 0));