()
| 688 | |
| 689 | // Function to capture and send element data |
| 690 | function captureAndSendElement() { |
| 691 | chrome.devtools.inspectedWindow.eval( |
| 692 | `(function() { |
| 693 | const el = $0; // $0 is the currently selected element in DevTools |
| 694 | if (!el) return null; |
| 695 | |
| 696 | const rect = el.getBoundingClientRect(); |
| 697 | |
| 698 | return { |
| 699 | tagName: el.tagName, |
| 700 | id: el.id, |
| 701 | className: el.className, |
| 702 | textContent: el.textContent?.substring(0, 100), |
| 703 | attributes: Array.from(el.attributes).map(attr => ({ |
| 704 | name: attr.name, |
| 705 | value: attr.value |
| 706 | })), |
| 707 | dimensions: { |
| 708 | width: rect.width, |
| 709 | height: rect.height, |
| 710 | top: rect.top, |
| 711 | left: rect.left |
| 712 | }, |
| 713 | innerHTML: el.innerHTML.substring(0, 500) |
| 714 | }; |
| 715 | })()`, |
| 716 | (result, isException) => { |
| 717 | if (isException || !result) return; |
| 718 | |
| 719 | console.log("Element selected:", result); |
| 720 | |
| 721 | // Send to browser connector |
| 722 | sendToBrowserConnector({ |
| 723 | type: "selected-element", |
| 724 | timestamp: Date.now(), |
| 725 | element: result, |
| 726 | }); |
| 727 | } |
| 728 | ); |
| 729 | } |
| 730 | |
| 731 | // Listen for element selection in the Elements panel |
| 732 | chrome.devtools.panels.elements.onSelectionChanged.addListener(() => { |
no test coverage detected