MCPcopy
hub / github.com/AgentDeskAI/browser-tools-mcp / captureAndSendElement

Function captureAndSendElement

chrome-extension/devtools.js:690–729  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

688
689// Function to capture and send element data
690function 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
732chrome.devtools.panels.elements.onSelectionChanged.addListener(() => {

Callers 1

devtools.jsFile · 0.85

Calls 1

sendToBrowserConnectorFunction · 0.85

Tested by

no test coverage detected