Console

Heather Arthur edited this page Jul 21, 2013 · 5 revisions

Methods

evaluateJS

evaluateJS(input, cb)

Evaluate a line of JavaScript in the context of the tab's page. Callback gets object with properties result (a primitive or JSObject), exception, exceptionMessage.

tab.Console.evaluateJS("6 + 7", function(err, resp) {
   if (resp.exception) {
      console.error(resp.exceptionMessage);
   }
   console.log("result of eval:", resp.result);
}

startListening

startListening(cb)

Start listening for "page-error" and "console-api-call" events from the page.

stopListening

stopListening(cb)

Stop listening for "page-error" and "console-api-call" events.

getCachedLogs

getCachedLogs(cb)

Get the page errors and console logs so far for the page, including logs from before startListening() was called. Note startListening() must be called and completed before this.

tab.Console.getCachedLogs(function(messages) {
  console.log(messages.length, "cached logs");
})

Events

"page-error"

Fired when there's a new error from the page. Note: startListening() must be called to receive these events.

Event object has properties errorMessage, sourceName, lineText, lineNumber, columnNumber, category, timeStamp, warning (boolean), error (boolean), exception (boolean), strict, private.

tab.Console.on("page-error", function(event) {
  console.log("new error:", event.errorMessage);
});

"console-api-call"

Fired when a Console API call was made from JS on the page. Note: startListening() must be called to receive these events.

Event object has properties: level, filename, lineNumber, functionName, timeStamp, arguments (array of primitives or JSObjects).

tab.Console.on("console-api-call", function(event) {
  console.log("console." + event.level, "called");
});