The tidy way to do it would be to hook straight in to firebase and get the same messages the API is seeing. That would require some knowledge of firebase, and writing an extension. That could be a lot to learn, if it's even possible...
As Martijn said, you can send it to the API log and read it from there. It's probably no going to be super reliable, but:
// Flag to prefix any content we want to grab
const rxTrigger = /^!export\s+/i
// Set up observer function
let apiLogObserver = new MutationObserver((targets) => {
targets.forEach((t) => {
if (t.addedNodes && /text-layer/i.test(t.target.className)) {
let lastChild = t.addedNodes[t.addedNodes.length-1];
let logContent = lastChild.childNodes[0]?.innerText.replace(/(^"|"$)/g, '');
if (rxTrigger.test(logContent)) console.info(`export triggered ===> ${logContent.replace(rxTrigger, '')}`);
}
});
});
// Find the target element and set config
const targetNode = document.querySelector('#apiconsole');
const config = {attributes: false, childList: true, subtree: true};
// Initialise the Mutation Observer
apiLogObserver.observe(targetNode, config);
That's a Mutation Observer. It observes a node and reports any changes, which you can then sort through to find the event you're looking for. In this case, anything sent to the API log starting with "!export " will be grabbed and logged to the browser console.
There's a bunch of issues with this approach - it's only observing HTML, so if the API console stops scrolling, the Observer won't be seeing any events. The API console also updates every line each time you scroll, so if you scroll up and down the Observer sees a crapload of new lines and has no idea that they're 'old' lines.
You could probably add some jQuery in there to disable scrolling up, and ensure the log is always fully scrolled down so you don't miss any output.
You could also set the Observer to the actual R20 chat log, but you can only pick up HTML that's posted to that element, which means no !API calls.
All in all, there's no easy way to do it. Unless you're very familiar with the systems involved, in which case you probably wouldn't be asking :)