Display the original caller on stack trace when logging

I’m working on an angular project and I have another project linked through node modules.
I’m calling the loggerService.log('something') from the main application where public log(message) is in the loggerService of the linked project, the method log has console.log(message); which will log the message to the stack.

My problem is when it logs the message to the stack trace it refers to the line number of the loggerService in the linked project (in index.js) but I want to show the line number of the actual caller from my main application.

I have tried console.log.bind() but that didn’t help either.

Declared the console as an ambient

declare var console: any; 

Log method

public log(...args: any[]) {
    if (console && console.log) {
        this.event.next(...args);
        console.log.bind(...args);
    }
}

Any suggestions will be helpful 🙂

accessing pre-injection console log entries from chrome extension

I’m examining several thousand web pages on a commercial site using a Chrome extension. I want to retrieve the console log entries with load errors and warnings in each page, send them back to background and append the log entries for each page to an array showing all the load errors for the whole site.

Once my script is injected to the page I can write additional messages to the console but how do I access prior console log messages?

Chrome: format specifier prints NaN instead of number

Referring the chrome dev-tools documentation, I wrote a simple snippet in the chrome debugger console which is like so –

var age = prompt("How old are you?");
console.log(age); //10
console.log('You are %d years old', age); //You are NaN years old

It appears strange that on the last line NaN is printed instead of 10. Anything obvious that I am missing?

Firefox/Chrome web extension – how do I save outputs that are too big for the console?

I tried to log the entire source of a webpage with console.log() in a chrome web extension. Unfortunately, the output was too big to save in the console. Even if it wasn’t too big, I’d like to save the output in a separate text file so I can view it in the future.

Here’s my current code:

fetch(newURL)
        .then((resp) => resp.text())
        .then(responseText => { console.log(responseText)}

The console crashes/says the output is too big when the program calls console.log(responseText)

How can I save “responseText” to a text file, for easier manipulation, and so the console doesn’t crash?

How to distinguish between a string and number in Chrome Dev Tools

How can I distinguish between a string and number when logging to the console with Chrome Dev Tools?

Image from another post

this answer to “Blue number in Chrome Dev Console?” has a screenshot of what happens when you pass a string to console.log and what happens when you pass a number.

I can make out a difference in colour when it’s blown up this large, but have difficulty when it is its usual size.

By contrast, in Ruby, distinguishing between an Integer object and a String object is easy – doing puts foo.inspect will give you quotation marks around a string, but not around the integer.

Show/Enable type of JavaScript data in Chrome dev tools console

In the past, if you had some data logged to the dev tools console, Chrome would show its type, like Object, Array, etc. But now, it just shows the data itself, without its type.

For instance, in the console, if you type –

var h = {a:1, b: 2}

then input h to see the value, you’ll just get back –

{a:1, b:2}

In the past, the console would display the type as well –

Object { a: 1, b: 2 }

Here is a screenshot of some code logging data to the Chrome console from a while back –

enter image description here

As is evident in the picture, all data types are clearly represented in the console, which happens to be Object in this case.

Here’s another screenshot from today where I just log an object to the screen –

enter image description here

Just the data, no type.

I’m using the latest version (Version 64.0.3282.140) of Chrome. If this feature was removed in an update, how do I get it back?

I’ve checked if I’ve applied some filters on end that hides the types, but I couldn’t find anything.

PS – I know it shows the prototype info. if you expand the arrow on the left, but that’s not what I am after.

Stop Specific Error Types Showing In Console

Is there any way that one can stop the console listing a specific error?

I ask, as since Chrome 63 it displays an error “Found 2 elements with non-unique id” many times in the console, and can make it more difficult to find any errors for any other issues that I am debugging.

Thanks
James

Javascript object displays differing values at the same time

I’m trying to understand why the following code behaves as it does. Specifically, why does the first console.log(...) expression output the full-and-final version of someObject? I realize it has something to do with hoisting (maybe?) or some other concept I don’t fully grasp. Just searching this on the web was challenging, as I don’t have the lexicon to properly search what I want to know.

var someObject = {};
                              // OUTPUT:
console.log(someObject);      // {prop: {key: "differentValue"}} <-- WHY!?
console.log(someObject.prop); //  undefined

someObject.prop = {key:"value"};

console.log(someObject);      // {prop: {key: "differentValue"}} <-- WHY!?
console.log(someObject.prop); // {key: "value"}

someObject.prop = {key:"differentValue"};

console.log(someObject);      // {prop: {key: "differentValue"}}
console.log(someObject.prop); // {key: "differentValue"}

I discovered this while coding something for myself wherein I wanted to see the state of an object at each iteration through a for-loop. I was surprised to see the object output to the console was the same at each turn; that state being the end-state of the object after the whole loop had executed.

What's even more confusing to me, and the part I really would like to understand, is why the reading of the properties of the object do seem to work as one (or at least I) would expect, while at the same moment, the whole object itself appears to have different values.

I thought maybe this question or this question might've helped explain, but I think they're not quite related.