Closed Bug 570856 Opened 14 years ago Closed 14 years ago

it should be possible to view console.log messages for addon installed via XPI

Categories

(Add-on SDK Graveyard :: General, defect)

defect
Not set
normal

Tracking

(Not tracked)

RESOLVED FIXED

People

(Reporter: myk, Unassigned)

References

Details

Attachments

(1 file)

When you install an addon via a XPI, you can't see console.log messages unless you run Firefox from a terminal, which almost no users do.  It should be possible to see those messages without having to run Firefox from a terminal.

I know in the long run we'll have a new console built into Firefox (perhaps in Firefox 4, although that is currently at risk), and it'll be possible to log to that console, but I think we need a shorter term solution here, as developers are already using the SDK to build addons they distribute to users.
Blocks: 561001
Very well. I suppose the easiest way to do this will be to create a forsaken-console.js that just uses Cu.reportError() and similar calls to log to the Forsaken Error Console when running in an XPI.
Sounds like a plan!
What's the importance of this, btw? It seems fairly important to me since it'll also be the only way to debug things at all on FlightDeck, as FD will be delivering built XPIs too...
Of course you just use the Firebug Console code.
It seems pretty important to me, too.
Chromebug 1.6a12 will support window.console in nsIDOMWindows. Components, modules, and sandboxes could be added. 

Even if you want to do your own thing eventually, you might consider this as a temporary solution.
Thanks John.

This patch does something odd: it just replaces the dump/print callable in harness.js with one that logs a plaintext message to the Error Console if it's detected that the addon isn't being run by cfx.

The major downside of this is that there's no semantic distinction between the addon calling console.log() or console.error(): both show up as plain old "messages" in the Error Console, so if the user is specifically filtering only errors/warnings, they won't see anything the addon has to say.

That said, this is a really simple quick fix. I would be okay with putting more time and effort into this if EC was the ultimate solution, but as either the HUD or a custom FlightDeck console will be replacing it relatively soon and provide a much better developer experience, I'd rather just use this to "tide us over" until we can migrate to something much better.

Thoughts?
As a side note, this patch also makes it possible to create a console.log("hello, world") addon that actually does something to Firefox, i.e. displays "hello, world" in the Error Console.
Attachment #450505 - Flags: review?(myk)
Comment on attachment 450505 [details] [diff] [review]
patch to route dump/print/console.* calls to nsIConsoleService::logStringMessage()

>+    if (msg.indexOf('\n') >= 0) {
>+      cService.logStringMessage(buffer + msg);
>+      buffer = "";
>+    } else
>+      buffer += msg;

Nit: per the style guide <https://wiki.mozilla.org/Labs/Jetpack/Reboot/Style_Guide>, don't cuddle else, but do surround single line conditional blocks with braces if other branches have braces.

Otherwise looks good and works well! r=myk
Attachment #450505 - Flags: review?(myk) → review+
(In reply to comment #10)
> Nit: per the style guide
> <https://wiki.mozilla.org/Labs/Jetpack/Reboot/Style_Guide>, don't cuddle else,
> but do surround single line conditional blocks with braces if other branches
> have braces.

Just a note on that since I wrote it:  I wrote it by myself with the intention of having other people edit it and so forth until we came to agreement, but we never did.  So that page mostly represents my personal preferences, which I don't want to force anyone to follow, least of all Atul.  I myself don't follow the second point anymore. :)
Thanks! Fixed the nit and pushed:

Bug 570856  - it should be possible to view console.log messages for addon installed via XPI
Atul Varma
http://hg.mozilla.org/labs/jetpack-sdk/rev/7fa6ebb155c3f6fdba15dd3934b6c23c11193dcc
Status: NEW → RESOLVED
Closed: 14 years ago
Resolution: --- → FIXED
The Add-on SDK is no longer a Mozilla Labs experiment and has become a big enough project to warrant its own Bugzilla product, so the "Add-on SDK" product has been created for it, and I am moving its bugs to that product.

To filter bugmail related to this change, filter on the word "looptid".
Component: Jetpack SDK → General
Product: Mozilla Labs → Add-on SDK
QA Contact: jetpack-sdk → general
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: