AEPKILL/devtools-detector

console.log function-to-string.checker

Closed this issue · 5 comments

I am just starting with javascript, can you explain to me why console.log method is called twice when devtools is open.
Tks bro

good question. I'll write a blog this weekend to explain it.

sorry, I didn't run the 'chormium' debugging environment at the weekend, so I can only give a general description from memory.
when we run the code from the devtools console

image

It will actually be sent to 'devtools Host' execution

image

when the 'Console. API' execution is complete, it will be notified that execution has been completed

image

` args' is a serialized 'Remote Object',which is its definition:
image

we need to focus on the 'description' property because it' s the key, this is how it' s generated:
image

` Devtools' will use 'to String' to generate' description' property
image

so, we just overwrite toString method, when devtools is open, our function will be execute.

Thanks pro @AEPKILL

How will it detect? if I do console.log=()=>{};

@alpgul

devtools-detector will cache the log method, as long as you ensure that devtools-detector is loaded first, it will work even if you override the log method