Console string substitution doesn't work in addons

RESOLVED INVALID

Status

defect
P3
normal
RESOLVED INVALID
5 years ago
4 months ago

People

(Reporter: grobinson, Unassigned)

Tracking

(Blocks 1 bug)

Firefox Tracking Flags

(Not tracked)

Details

(Whiteboard: [console-papercuts])

Attachments

(1 attachment)

According to [0], Firefox's console.log has had string substitutions since Firefox 9.0. If I open the web console and run

  console.log("foo %s", "bar)

I get "foo bar", as expected. But the same use of string substitutions in addon code fails, and no substitution is performed. I've created a simple example add-on [1] to demonstrate this problem.

STR:

1. Install the example add-on (in a clean profile if you want)
2. Check the Browser Console (or your terminal, if you ran Firefox from the command line)
3. Output: "foo %s, 1+1=%d, Math.PI=%f" "bar" 2 3.141592653589793
4. Expected: "foo bar, 1+1=2, Math.PI=3.141592653589793"

This addon was created with the Jetpack SDK [2], so it's possible that the issue is with those API's instead.

[0] https://developer.mozilla.org/en-US/docs/Web/API/console#Using_string_substitutions
[1] https://people.mozilla.org/~grobinson/console-string-sub-bug.xpi
[2] https://developer.mozilla.org/en-US/Add-ons/SDK
+1, I think we should pursue a 'no surprises' policy with console, it should work consistently regardless of environment.
The console API is being rewritten in C++ and it will unify implementations.
Depends on: 965860
OS: Linux → All
Priority: -- → P3
Hardware: x86_64 → All
Depends on: 988636
Whiteboard: [console-papercuts]
Whiteboard: [console-papercuts] → [console-papercuts][devedition-40]
Andrea - now that bug 988636 is resolved, what needs to happen here? Mainly curious, this isn't very high priority just now.
Flags: needinfo?(amarchesini)
Whiteboard: [console-papercuts][devedition-40] → [console-papercuts]
We didn't fix that bug yet. We unified the console in workers and main-thread but not for JSM/addons. The main reason is because that is used completely in a different way:

1. You have to import Console.jsm
2. Then create your own Console object with custom optional parameters

So, all of this is still implemented separately by Console.jsm. Very low priority, my plan is to replace the implementation with the C++ Console, without changing the current behavior too much.
Unfortunately we cannot get rid of Console.jsm because it's used by way too many addons.
Flags: needinfo?(amarchesini)
Thanks - I agree this is lower priority. I suppose we could hollow out Console.jsm so it's just a shim on the C++ component as much as possible?
Yes, that's the plan.
Posted patch WIPSplinter Review
This is just a WIP. It breaks all the jetpack console tests and all the devtools tests (ignore the crash, that is already fixed):

https://treeherder.mozilla.org/#/jobs?repo=try&revision=6e64c3432690

I wonder how much we can change the tests to make it pass...

Updated

Last year
Product: Firefox → DevTools

just checked and works in webextension (content and background), so let's close this.

Status: NEW → RESOLVED
Closed: 4 months ago
Resolution: --- → INVALID
You need to log in before you can comment on or make changes to this bug.