@@ -12,6 +12,9 @@ const RENDERED_IFRAME = /** @type {HTMLIFrameElement} */ (
12
12
document . getElementById ( 'rendered_iframe' )
13
13
) ;
14
14
15
+ /** @type {Element|null } */
16
+ let CONTEXT_ELEMENT = null ;
17
+
15
18
const cfg = I . getConfig ( NS ) ;
16
19
let { nonce } = cfg ;
17
20
@@ -390,6 +393,7 @@ const store = createStore(NS, {
390
393
if ( contextElement ) {
391
394
store . state . DOM . contextNode = contextElement . nodeName ;
392
395
contextElement . innerHTML = store . state . playbackHTML ?? store . state . html ;
396
+ CONTEXT_ELEMENT = contextElement ;
393
397
}
394
398
}
395
399
@@ -572,6 +576,7 @@ const store = createStore(NS, {
572
576
store . state . playbackHTML ??
573
577
store . state . html ;
574
578
579
+ CONTEXT_ELEMENT = null ;
575
580
iframeDocument . open ( ) ;
576
581
iframeDocument . write ( html ) ;
577
582
iframeDocument . close ( ) ;
@@ -646,21 +651,13 @@ const store = createStore(NS, {
646
651
handleCopyTreeClick : function * ( e ) {
647
652
const useDomTree =
648
653
/** @type {HTMLButtonElement } */ ( e . target ) . name === 'tree__dom' ;
654
+
649
655
let tree ;
650
656
if ( useDomTree ) {
651
- const doc = RENDERED_IFRAME . contentWindow . document ;
652
-
653
- /** @type {Element|null } */
654
- let contextElement = null ;
655
- if ( store . state . contextHTMLForUse ) {
656
- const walker = doc . createTreeWalker ( doc , NodeFilter . SHOW_ELEMENT ) ;
657
- while ( walker . nextNode ( ) ) {
658
- // @ts -expect-error It's an Element!
659
- contextElement = walker . currentNode ;
660
- }
661
- }
662
-
663
- tree = contextElement || doc ;
657
+ tree =
658
+ CONTEXT_ELEMENT ||
659
+ // @ts -expect-error It's an Element!
660
+ RENDERED_IFRAME . contentWindow . document ;
664
661
} else {
665
662
tree =
666
663
store . state . playbackTree ?? store . state . htmlapiResponse . result ?. tree ;
0 commit comments