K
kj
Hi!
I'd like to implement a "global error observer" [GEO] for my
JavaScript scripts. The ideal GEO would be one that would be able
to detect any error or exception whatsoever (including those
triggered by throw), and optionally execute some code in response.
I realize that the implementation of a GEO is probably intimately
tied to the browser, but for starters, I'd be happy to be able to
do this for Firefox.
My first (very naive) approach was to define an onerror event
handler for the 'body' element, but I immediately discovered that
this misses the exceptions raised by "throw". I want something
better.
I spent some time trying to figure out how Firebug
(http://www.getfirebug.com) does it, and I determined that it relies
on an "addObserver" method of a certain "observer-service" class.
To load this class, Firebug executes the equivalent of this:
var C = Components;
var _CC = C.classes; // *bombs*
var _CI = Components.interfaces;
var c_name = '@mozilla.org/observer-service;1';
var iface_name = 'nsIObserverService';
var observer_service = _CC[ c_name ].getService( _CI[ iface_name ] );
But when I try to execute this code (specifically, the line indicated
with the comment) I get the error
[Exception... "'Permission denied to get property UnnamedClass.classes' when calling method: [nsIDOMEventListener::handleEvent]" nsresult: "0x8057001e (NS_ERROR_XPC_JS_THREW_STRING)" location: "<unknown>" data: no]
Does anyone know how I can get around this problem?
TIA!
kynn
I'd like to implement a "global error observer" [GEO] for my
JavaScript scripts. The ideal GEO would be one that would be able
to detect any error or exception whatsoever (including those
triggered by throw), and optionally execute some code in response.
I realize that the implementation of a GEO is probably intimately
tied to the browser, but for starters, I'd be happy to be able to
do this for Firefox.
My first (very naive) approach was to define an onerror event
handler for the 'body' element, but I immediately discovered that
this misses the exceptions raised by "throw". I want something
better.
I spent some time trying to figure out how Firebug
(http://www.getfirebug.com) does it, and I determined that it relies
on an "addObserver" method of a certain "observer-service" class.
To load this class, Firebug executes the equivalent of this:
var C = Components;
var _CC = C.classes; // *bombs*
var _CI = Components.interfaces;
var c_name = '@mozilla.org/observer-service;1';
var iface_name = 'nsIObserverService';
var observer_service = _CC[ c_name ].getService( _CI[ iface_name ] );
But when I try to execute this code (specifically, the line indicated
with the comment) I get the error
[Exception... "'Permission denied to get property UnnamedClass.classes' when calling method: [nsIDOMEventListener::handleEvent]" nsresult: "0x8057001e (NS_ERROR_XPC_JS_THREW_STRING)" location: "<unknown>" data: no]
Does anyone know how I can get around this problem?
TIA!
kynn