Firefox: "Permission denied ... Components.classes"

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
 
J

Joost Diepenmaat

kj said:
[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?

Sounds like that stuff is not accessible to user scripts. Lots of things
in mozilla are restricted like that for obvious reasons.

Run the code from a FF extension (or use greasemonkey).

Joost.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,012
Latest member
RoxanneDzm

Latest Threads

Top