diff --git a/src/audio-worklet/audio-worklet.ts b/src/audio-worklet/audio-worklet.ts index e574c66..5cafbf2 100644 --- a/src/audio-worklet/audio-worklet.ts +++ b/src/audio-worklet/audio-worklet.ts @@ -53,6 +53,18 @@ function getErrorMessage(err: any, time: number) { } } +// replace Proxy so that they can be detected from the bytebeat code +// this is completely undetectable by the bytebeat code +const proxies = new WeakSet(); +Proxy = Object.getPrototypeOf(Proxy).contructor = new Proxy(Proxy, { + construct(target, args) { + // @ts-expect-error + const newProxy = new target(...args); + proxies.add(newProxy); + return newProxy; + }, +}) + class BytebeatProcessor extends AudioWorkletProcessor { audioSample = 0; // TODO: is this needed? might be better to use currentTime global lastFlooredTime = -1; @@ -250,9 +262,7 @@ class BytebeatProcessor extends AudioWorkletProcessor { funcValue = NaN; } - if (Array.isArray(funcValue)) { - // replace array for safety, arrays could have modified functions - // TODO can the index operator be overridden? is this safe? + if (Array.isArray(funcValue) && !proxies.has(funcValue)) { funcValue = [funcValue[0], funcValue[1]]; } else { funcValue = [funcValue, funcValue]; @@ -261,7 +271,11 @@ class BytebeatProcessor extends AudioWorkletProcessor { let changedSample = false; for (const c in funcValue) { try { - funcValue[c] = Number(funcValue[c]); + if (proxies.has(funcValue[c])) { + throw new TypeError("can't convert proxy to number"); + } else { + funcValue[c] = +funcValue[c]; + } } catch (err) { funcValue[c] = NaN; }