提问人:Rohit 提问时间:8/20/2023 最后编辑:Rohit 更新时间:8/20/2023 访问量:45
无法在镶边扩展中获取已检查的元素
Unable to get the inspected element in chrome extension
问:
我正在尝试使用 chrome 扩展 api 在网页中获取 dom 元素。
以下是我为扩展程序编写的清单chrome.devtools.inspectedWindow.
{
"manifest_version": 3,
"name": "Component Selector",
"version": "1.0",
"devtools_page": "devtools/devtools.html",
"permissions": ["activeTab", "tabs", "debugger"]
}
我在 devtools 中编写的 js.js如下
function getInspectedElement() {
chrome.devtools.inspectedWindow.eval(
'inspect($0)',
function (result, exceptionInfo) {
if (!exceptionInfo) {
console.log('Element selected for inspection:', result);
if (result) {
console.log(result.style);
}
} else {
console.error('Error selecting element:', exceptionInfo);
}
}
);
}
chrome.devtools.panels.elements.onSelectionChanged.addListener(
getInspectedElement
);
chrome.devtools.panels.create("My Panel",
null,
"devtools/panel.html",
function (panel) {
}
);
答: 暂无答案
评论
useContentScriptContext: true
getInspectedElement
onSelectionChanged.addListener
eval