Console polyfill
Console API polyfill (@roku-sdk/native)
@roku-sdk/native)The Hermes JavaScript engine used on Roku devices natively provides only console.log, console.warn, console.error, console.info, and console.debug. All other Console API methods are absent.
The @roku-sdk/native package ships a polyfill that installs the missing methods automatically when you first import the package.
Methods polyfilled
The following table lists the polyfilled methods:
| Method | Behavior |
|---|---|
console.time(label?) | Starts a named timer. Default label is "default". Warns if the label is already active. |
console.timeEnd(label?) | Stops a named timer and logs "label: Nms". Removes the timer. Warns if the label does not exist. |
console.timeLog(label?, ...data) | Logs elapsed time without stopping the timer. Appends any extra data args after the elapsed string. |
console.assert(condition?, ...data) | No-op when condition is truthy. Writes "Assertion failed" (or "Assertion failed: message") to console.error when falsy. Follows WHATWG semantics: prepends ": " only when the first extra arg is a string. |
console.count(label?) | Increments a named counter and logs "label: N". Default label is "default". |
console.countReset(label?) | Resets a named counter to 0. Warns if the label has never been counted. Per the WHATWG specification, it sets the counter to 0 (it does not delete the key); therefore, a subsequent countReset on a zeroed counter does not warn. |
console.group(label?) | Logs the label (if provided) and increments the indentation depth. |
console.groupCollapsed(label?) | Identical to group. There is no visual collapse on Roku because Roku does not have DevTools. |
console.groupEnd() | Decrements the indentation depth. The depth never goes below 0. |
Understanding indentation
The group depth applies two spaces of indentation per level to the output of the polyfilled methods (time, timeEnd, timeLog, assert, and count). The polyfill does not wrap the global console.log; therefore, direct console.log calls are unaffected by group depth.
Understanding guard behavior
The polyfill installs each method only if typeof console.<method> !== "function". If Hermes ever ships a native implementation, the native version takes precedence, and the polyfill skips that method.
Understanding production builds
In production builds (npx rk build), esbuild drops all console.* call expressions through drop: ["console"]. The @roku-sdk/native entry point also guards the polyfill import with if (__DEV__), and __DEV__ is false in production by default; therefore, the build eliminates the entire polyfill module from production bundles.
Updated about 6 hours ago