rrrfusco
rrrfusco

Reputation: 1119

console.log in the web console for Firefox add-on SDK 1.16

How do you view console.log() in the web console or browser console using SDK 1.16? I'm not seeing any messages in the console under either JS or Logging buttons.

Can I execute console.log in element-getter.js? (content script)

Development Settings


main.js

var tag = ".first, .second";
var data = require("sdk/self").data;
var pageMod = require("sdk/page-mod");

pageMod.PageMod({
  //include: "*.example.com",
  include: "http://example.com/*",
  contentScriptFile: data.url("element-getter.js"),
  onAttach: function(worker) {
    worker.port.emit("getElements", tag);
    worker.port.on("gotElements", function(elementContent) {
      pcPanel.port.emit("message",elementContent);
    });
  }
});


element-getter.js

self.port.on("getElements", function(tag) {
  var elements = Array.map(document.querySelectorAll(tag). function(e) e.innerHTML);
  console.log(elements);
  self.port.emit("gotElements", elements);
});


panel.html

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html>   <head>   <meta http-equiv="content-type" content="text/html; charset=UTF-8">
    <script>
      addon.port.on("message", function handleMyMessage(myMessagePayload) {
          //alert(myMessagePayload);
          //alert(myMessagePayload[0]);
          //alert(myMessagePayload[1]);
      });
    </script>   </head> </html>

Upvotes: 1

Views: 436

Answers (2)

Lori
Lori

Reputation: 1422

With SDK 1.14 they turned off console.log output by default. They posted instructions for turning it back on here.

Upvotes: 1

nmaier
nmaier

Reputation: 33162

There is a SyntaxError.

  var elements = Array.map(document.querySelectorAll(tag). function(e) e.innerHTML);

should be

  var elements = Array.map(document.querySelectorAll(tag), function(e) e.innerHTML);

(dot vs comma)

Unfortunately, this doesn't get logged with correct location information, it seems:

SyntaxError: missing ) after argument list core.js:90

The second problem is that you're using the same log level pref. It should be

extensions.sdk.console.logLevel

(You don't need to adjust the log level when running with cfx run)

Fixing this, I can see log entries in the Browser Console. But, again, this will unfortunately display the wrong location information when logging from content scripts. It will show up as originating from sandbox.js:311 in my copy of Firefox 30. Logging from main.js instead will have the correct location information, though.

Upvotes: 2

Related Questions