[GH-ISSUE #21] console.log function-to-string.checker #9

Closed
opened 2026-03-01 14:33:50 +03:00 by kerem · 5 comments
Owner

Originally created by @LeDinhPhuc on GitHub (May 28, 2021).
Original GitHub issue: https://github.com/AEPKILL/devtools-detector/issues/21

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

Originally created by @LeDinhPhuc on GitHub (May 28, 2021). Original GitHub issue: https://github.com/AEPKILL/devtools-detector/issues/21 I am just starting with javascript, can you explain to me why console.log method is called twice when devtools is open. Tks bro
kerem 2026-03-01 14:33:50 +03:00
  • closed this issue
  • added the
    question
    label
Author
Owner

@AEPKILL commented on GitHub (Jun 3, 2021):

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

<!-- gh-comment-id:853486653 --> @AEPKILL commented on GitHub (Jun 3, 2021): good question. I'll write a blog this weekend to explain it.
Author
Owner

@AEPKILL commented on GitHub (Jun 6, 2021):

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.

<!-- gh-comment-id:855388893 --> @AEPKILL commented on GitHub (Jun 6, 2021): 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](https://user-images.githubusercontent.com/9626630/120923381-ce4cd000-c700-11eb-982b-212f0372d725.png) It will actually be sent to 'devtools Host' execution ![image](https://user-images.githubusercontent.com/9626630/120923318-8037cc80-c700-11eb-9389-bcd743622832.png) when the 'Console. API' execution is complete, it will be notified that execution has been completed ![image](https://user-images.githubusercontent.com/9626630/120923367-c42ad180-c700-11eb-9595-d85dc1f5e463.png) ` args' is a serialized 'Remote Object',which is its definition: ![image](https://user-images.githubusercontent.com/9626630/120923499-76fb2f80-c701-11eb-9d3e-014c67754b00.png) we need to focus on the 'description' property because it' s the key, this is how it' s generated: ![image](https://user-images.githubusercontent.com/9626630/120923698-7616cd80-c702-11eb-8144-1217eb45a53d.png) ` Devtools' will use 'to String' to generate' description' property ![image](https://user-images.githubusercontent.com/9626630/120923754-c130e080-c702-11eb-83d9-7f10b35c8489.png) so, we just overwrite `toString` method, when `devtools` is open, our function will be execute.
Author
Owner

@LeDinhPhuc commented on GitHub (Jun 7, 2021):

Thanks pro @AEPKILL

<!-- gh-comment-id:855557643 --> @LeDinhPhuc commented on GitHub (Jun 7, 2021): Thanks pro @AEPKILL
Author
Owner

@alpgul commented on GitHub (Jun 20, 2021):

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

<!-- gh-comment-id:864491294 --> @alpgul commented on GitHub (Jun 20, 2021): How will it detect? if I do `console.log=()=>{};`
Author
Owner

@AEPKILL commented on GitHub (Jul 7, 2021):

@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

<!-- gh-comment-id:875664757 --> @AEPKILL commented on GitHub (Jul 7, 2021): @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
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
starred/devtools-detector#9
No description provided.