Question

I'm trying to build an extension for Firefox. This extension uses an XPCOM component (a C++ dll). I'm compiling the DLL, compilation is OK.

The next step would be to use the component in Javascript from my extension. I added the code to register my component from my c++ file :

static const mozilla::Module::CategoryEntry kSampleCategories[] = {
    { JAVASCRIPT_GLOBAL_PROPERTY_CATEGORY, "greenfox", NS_SAMPLE_CONTRACTID },
};

In my manifest, I declare the XPCOM :

component {03A6D0B4-22B9-11DF-B844-20D556D89593} components/GreenCodeLabFox.dll

The problem is, when I try to use the component in JS, it seems it is not registered :

    try {
        greenfox;
        return true;
    } catch( e ) {
        alert( e );
        return false;
    }   

This gives me the alert error:

ReferenceError: greenfox is not defined

In error console, I have no message.

How would I debug this if I have no error message ? By the way, my javascript.options.showInConsole is set to true.

Thanks !

Was it helpful?

Solution

Per https://developer.mozilla.org/en/XPCOM/XPCOM_changes_in_Gecko_2.0 you must use a binary-component directive to register a binary component.

That page also links to an example; you only posted a part of the code required for registration.

If the component still doesn't work, I'd try to get it via Components.classes[contract id] from the Error Console - that will show if the problem is with the component registration or just with the global property part.

https://developer.mozilla.org/en/Troubleshooting_XPCOM_components_registration might be useful for troubleshooting, although it's a bit dated.

OTHER TIPS

Perhaps an Update, since Firefox 41 using binary-component for extensions is no longer supported in release builds, but may be available for custom builds using MOZ_BINARY_EXTENSIONS

https://blog.mozilla.org/addons/2015/05/04/dropping-support-for-binary-components/

https://github.com/mozilla/gecko-dev/blob/master/xpcom/components/ManifestParser.cpp

You may see errors like
[JavaScript Warning: "Only application manifests may use the 'binary-component' directive." {file: "..." line: ..}]

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top