Skip to content

Instantly share code, notes, and snippets.

@PurpShell
Last active September 4, 2024 12:59
Show Gist options
  • Save PurpShell/67f0b9f178a603023dcd16b9dfde07ea to your computer and use it in GitHub Desktop.
Save PurpShell/67f0b9f178a603023dcd16b9dfde07ea to your computer and use it in GitHub Desktop.
A monitoring script based on Tulir's wa-web/web-scripts logging script, for 2.3000x
if (!window.decodeStanza) {
window.decodeStanza = require("WAWap").decodeStanza;
window.encodeStanza = require("WAWap").encodeStanza;
}
require("WAWap").decodeStanza = async (e, t) => {
const result = await window.decodeStanza(e, t);
console.log('RECV', result.toString(), result);
return result;
}
require("WAWap").encodeStanza = (...args) => {
const result = window.encodeStanza(...args);
console.log('SEND', args[0].toString(), args[0]);
return result;
}
if (!window.loggerSet) {
const _logger = window.require("WAWebLoggerImpl").Logger
const _origLogImpl = _logger.logImpl.bind(_logger)
const logLevel = {
0: console.debug,
1: console.info,
2: console.log,
3: console.warn,
4: console.error,
5: console.error,
}
_logger.logImpl = (level, message, a, b, area) => {
const logArgs = []
if (area) logArgs.push(`[${area}]`)
logArgs.push(message)
if (a || b) logArgs.push([a, b])
logLevel[level](...logArgs)
_origLogImpl(level, message, a, b, area)
}
window.loggerSet = true
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment