Closed nexushoratio closed 11 months ago
No generic way to catch errors that works inside of userscripts.
The recommended way seems to be self.addEventListener('error', handler);
, where using self
rather than window
works on both apps and workers.
One approach could be to listen for a CustomEvent like we do for urlchange
, but if we do that, we really want to have a function in base that generate the event. And if we do that, we might as well just directly call something to save it.
So, now we are kind of looking at a pubsub service with a memory, not just a dispatcher. Though one can be built on top of Dispatcher
.
The built in MessageChannel
looks like it will work.
const channel = new MessageChannel();
channel.port2.addEventListener('message', (event) => {
logger.log('port2:', event.data);
});
for (let i = 0; i < 100; i += 1) {
channel.port1.postMessage(i);
}
channel.port2.start();
So, just needs a little wrapping.
Technically, this is another WEB API, like console
. Though at least not DOM related.
Actually, just write our own to avoid any more use of the WEB API in base.
Like what we have going with
SPA.addError()
, but way down inNH.base
.I do not think it is possible to just catch all Errors. Obviously LI itself does, because it keeps eating LIT's. But from a userscript, may be tricky.
SPA.addError()
SPADetails.addSetupIssue()
SPA.dumpInfoAboutElement()
to lib/web.js