unjs / consola

🐨 Elegant Console Logger for Node.js and Browser

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

consola does not work under AudioWorkletGlobalScope

baadc0de opened this issue · comments

Version

v2.11.2

Reproduction link

https://codesandbox.io/s/gracious-mendel-uw0vh

Steps to reproduce

Functions like setTimeout and clearTimeout are not defined on https://developer.mozilla.org/en-US/docs/Web/API/AudioWorkletGlobalScope

Logging with consola uses these functions in order to throttle logging. It should be possible to disable the throttling or have consola disable throttling if these functions are not available.

Creating a worklet.js file with the following code:
console.log({setTimeout: typeof setTimeout, clearTimeout: typeof clearTimeout})

And another file, index.js with the following:
new AudioContext().audioWorklet.addModule("/worklet.js")

Outputs
{setTimeout: "undefined", clearTimeout: "undefined"}

What is expected ?

Consola to log without a crash

What is actually happening?

Consola code crashes

This bug report is available on Nuxt community (#c62)

Hi and sorry for reply late. I think this issue is valid but the scope is limited. You might try to polyfill globalThis.setTimeout and globalThis.clearTimeout to make it working. When using Nuxt 3 or Nitro / Unenv, does the polyfill too.

Closing issue since is stalled. Please let me know if you still thinks worth to implement polyfill built-in.