
Security News
The Code You Didn't Write Is Still Yours to Defend
AI agents are pulling packages into environments no scanner is watching, creating exposure before security teams can see it.
console-class-browser
Advanced tools
This module implements the Node.js `console` module for browser environments.
简体中文
This module implements the Node.js console module for browser environments.
The motivation came from my attempt to simulate a shell in the frontend, where I found that console-browserify did not implement the Console class.
I originally considered submitting a PR, but the changes required would likely be extensive and might be rejected. Therefore, I spent a few hours rewriting this module.
The usage of this module is mostly the same as the Node.js standard library, with some minor differences.
A simple example (test.js):
const console = require("console-class-browser")
console.group("SIMPLE LOG")
console.group("LOG")
console.log("Hello %s", "World")
console.info("Hello %s", "World")
console.debug("Hello %s", "World")
console.dirxml("Hello %s", "World")
console.table("Hello %s", "World") // TODO
console.warn("Hello %s", "World")
console.groupEnd()
console.group("ERROR")
console.error("Bye %s", "Bug")
console.trace("Bye %s", "Bug")
console.groupEnd()
console.groupEnd()
console.groupCollapsed("UTIL LOG")
console.assert(true, "Hello %s", "World")
console.time("Time")
console.timeLog("Time")
console.timeEnd("Time")
console.count("Count")
console.count("Count")
console.countReset("Count")
console.log({key: "value"}, "Hello", "World")
console.dir(console.Console.prototype, {depth: 0})
console.groupEnd()
Example using the Console class:
// If you have your own stdout or stderr
var myConsole = new console.Console(stdout, stderr)
myConsole.log("Hello World")
TIP: It is recommended that stdout and stderr be Node.js writable stream objects. In practice, they can be any object containing a write method. If you want to use console.clear, the stdout should also implement a clear method.
BrowserStdout and BrowserStderr (simulating stderr and stdout in the browser):
console.stdout // Pre-instantiated stdout
console.stderr // Pre-instantiated stderr
// You can also instantiate your own
var stdout = new console.BrowserStdout()
var stderr = new console.BrowserStderr()
This module implements the following methods (excluding details that differ from the console module):
Some methods are implemented as empty functions.
Thank you for reading. PRs are welcome!
本模块实现了Nodejs的console模块)
起因是我在尝试在前端模拟shell时候发现console-browserify没有实现Console类
本来想提一个pr的,但是要我改的话可能就要大变动了,八成可能会被拒绝,因此我就花几个小时重写了这个模块
本模块用法与Node标准库基本相同,细节有不同
一个简单的示例(test.js)
const console = require("console-class-browser")
console.group("SIMPLE LOG")
console.group("LOG")
console.log("Hello %s", "World")
console.info("Hello %s", "World")
console.debug("Hello %s", "World")
console.dirxml("Hello %s", "World")
console.table("Hello %s", "World") // TODO
console.warn("Hello %s", "World")
console.groupEnd()
console.group("ERROR")
console.error("Bye %s", "Bug")
console.trace("Bye %s", "Bug")
console.groupEnd()
console.groupEnd()
console.groupCollapsed("UTIL LOG")
console.assert(true, "Hello %s", "World")
console.time("Time")
console.timeLog("Time")
console.timeEnd("Time")
console.count("Count")
console.count("Count")
console.countReset("Count")
console.log({key: "value"}, "Hello", "World")
console.dir(console.Console.prototype, {depth: 0})
console.groupEnd()
Console类示例
// 如果你有自己的stdout或stderr
var myConsole = new console.Console(stdout, stderr)
myConsole.log("Hello World")
TIP: 建议stdout和stderr是一个nodejs的可写流对象,实际上可以是任何包含write方法的对象,如果希望console.clear还需要在stdout上实现clear方法
BrowserStdout和BrowserStderr(在浏览器上模拟stderr和stdout)
console.stdout // 已经实例化的stdout
console.stderr // 已经实例化的stderr
// 也可以自己实例化一个
var stdout = new console.BrowserStdout()
var stderr = new console.BrowserStderr()
本模块实现了以下方法(不包括与console模块不同的细节)
部分方法使用空函数实现
感谢阅读,欢迎pr补充)
FAQs
This module implements the Node.js `console` module for browser environments.
We found that console-class-browser demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Security News
AI agents are pulling packages into environments no scanner is watching, creating exposure before security teams can see it.

Security News
GitHub Actions checkout now blocks risky pull_request_target checkouts by default to help prevent pwn request supply chain attacks.

Product
Socket now supports Custom Roles and Repository Access Permissions so organizations can control who can access specific repositories and actions.