Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Log to Firefox Error Console from JavaScript

Is it possible to add messages to the built-in error console of Firefox from JavaScript code running in web pages?

I know that I there's Firebug, which provides a console object and its own error console, but I was looking for a quick fix earlier on and couldn't find anything.

I guess it might not be possible at all, to prevent malicious web pages from spamming the log?

like image 922
Torsten Marek Avatar asked Apr 23 '09 21:04

Torsten Marek


People also ask

How do you call an error console in Firefox?

Opening the Browser Console You can open the Browser Console in one of two ways: from the menu: select “Browser Console” from the Web Developer submenu in the Firefox Menu (or Tools menu if you display the menu bar or are on macOS). from the keyboard: press Ctrl + Shift + J (or Cmd + Shift + J on a Mac).

Can you console log in JavaScript?

The console. log() is a function in JavaScript which is used to print any kind of variables defined before in it or to just print any message that needs to be displayed to the user. Syntax: console.


1 Answers

If you define a global function that checks for the existence of window.console, you can use Firebug for tracing and still plays nice with other browsers and/or if you turn Firebug's console tracing off:

debug = function (log_txt) {     if (typeof window.console != 'undefined') {         console.log(log_txt);     } }  debug("foo!"); 
like image 147
petsounds Avatar answered Sep 17 '22 04:09

petsounds