-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdevtools.js
More file actions
36 lines (32 loc) · 879 Bytes
/
devtools.js
File metadata and controls
36 lines (32 loc) · 879 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
import { getAbsoluteXPath } from "./xpath.js";
function sendSelector() {
// TODO: debug mode
const expression = `
(function() {
${getAbsoluteXPath.toString()}
const sender = $0.ownerDocument.defaultView.__chrome_inspector_send_$0_xpath;
if (typeof sender !== "function") return;
try{
const xpath = getAbsoluteXPath($0);
sender(xpath);
} catch {}
})();
`;
chrome.devtools.inspectedWindow.eval(
expression,
{},
(_result, exceptionInfo) => {
if (exceptionInfo && exceptionInfo.isException) {
console.error(
`Unable to evaluate selection change script.`,
exceptionInfo,
);
}
},
);
}
if (chrome?.devtools?.panels?.elements) {
chrome.devtools.panels.elements.onSelectionChanged.addListener(sendSelector);
} else {
console.warn(`chrome.devtools API is not available in this context.`);
}