@@ -26,15 +26,23 @@ export default function setupHighlighter({
2626 onSelectNode = ( ) => { } ,
2727} = { } ) {
2828 let isInspecting = false ;
29+ let stopOnClick = true ;
30+ let blockEvents = true ;
2931
3032 Bridge . onMessage ( 'CLEAR_HIGHLIGHTS' , withMessageData ( clearHighlights ) ) ;
3133 Bridge . onMessage ( 'HIGHLIGHT_ELEMENTS' , withMessageData ( highlightElements ) ) ;
3234 Bridge . onMessage ( 'SHUTDOWN' , withMessageData ( stopInspecting ) ) ;
3335 Bridge . onMessage ( 'START_INSPECTING' , withMessageData ( startInspecting ) ) ;
3436 Bridge . onMessage ( 'STOP_INSPECTING' , withMessageData ( stopInspecting ) ) ;
3537
36- function startInspecting ( ) {
38+ function startInspecting ( options ) {
3739 isInspecting = true ;
40+
41+ if ( options ) {
42+ stopOnClick = options . stopOnClick ?? true ;
43+ blockEvents = options . blockEvents ?? true ;
44+ }
45+
3846 addEventListeners ( view ) ;
3947 }
4048
@@ -51,6 +59,13 @@ export default function setupHighlighter({
5159 }
5260 }
5361
62+ function stopPropagation ( event ) {
63+ if ( blockEvents ) {
64+ event . preventDefault ( ) ;
65+ event . stopPropagation ( ) ;
66+ }
67+ }
68+
5469 function stopInspecting ( ) {
5570 hideOverlay ( ) ;
5671 removeEventListeners ( view ) ;
@@ -99,30 +114,27 @@ export default function setupHighlighter({
99114 }
100115
101116 function onClick ( event ) {
102- event . preventDefault ( ) ;
103- event . stopPropagation ( ) ;
117+ stopPropagation ( event ) ;
104118
105- stopInspecting ( ) ;
119+ if ( isInspecting && stopOnClick ) {
120+ stopInspecting ( ) ;
121+ }
106122 }
107123
108124 function onMouseEvent ( event ) {
109- event . preventDefault ( ) ;
110- event . stopPropagation ( ) ;
125+ stopPropagation ( event ) ;
111126 }
112127
113128 function onPointerDown ( event ) {
114- event . preventDefault ( ) ;
115- event . stopPropagation ( ) ;
129+ stopPropagation ( event ) ;
116130
117- selectNode ( event . target ) ;
131+ selectNode ( event . target , { origin : event . isTrusted ? 'click' : 'script' } ) ;
118132 }
119133
120134 function onPointerOver ( event ) {
121- event . preventDefault ( ) ;
122- event . stopPropagation ( ) ;
135+ stopPropagation ( event ) ;
123136
124137 const target = event . target ;
125-
126138 if ( target . tagName === 'IFRAME' ) {
127139 try {
128140 if ( ! iframesListeningTo . has ( target ) ) {
@@ -136,12 +148,11 @@ export default function setupHighlighter({
136148 }
137149
138150 showOverlay ( [ target ] , false ) ;
139- selectNode ( target ) ;
151+ selectNode ( target , { origin : event . isTrusted ? 'hover' : 'script' } ) ;
140152 }
141153
142154 function onPointerUp ( event ) {
143- event . preventDefault ( ) ;
144- event . stopPropagation ( ) ;
155+ stopPropagation ( event ) ;
145156 }
146157
147158 const selectNode = throttle (
0 commit comments