Robdll
Robdll

Reputation: 6255

How to run a snippet on breakpoint in developer tool

I'm gonna ask a weird question:

Is there a way to run a code snippet on a breakpoint set on the DOM?

Use example:
- Visit a website with a table.
- Set a Break On Subtree Modification
- Run MySnippet when the breakpoint hits.

Upvotes: 2

Views: 693

Answers (2)

olaf
olaf

Reputation: 31

What you can do though is set a conditional breakpoint with an eval('...') statement.

for example the following with log to the console:

test 11:59:51:326

Good for checking timing issues...

eval('let current=new Date();console.log("test",current.getHours()+":"
+current.getMinutes()+":"+current.getSeconds()+":"
+current.getMilliseconds());')

you can also print a local object, e.g if localVar is defined:

eval('let current=new 
Date();console.log("test”,localVar,current.getHours()+":"
+current.getMinutes()+":"+current.getSeconds()+":"+current.getMilliseconds());')

Upvotes: 3

Kayce Basques
Kayce Basques

Reputation: 25897

DevTools doesn't have this feature. After your DOM breakpoint triggers you can run a Snippet though. You can run Snippets from the Command Menu.

Upvotes: 1

Related Questions