我想弄明白Chrome开发者扩展是如何工作的。我想在开发工具面板窗口中显示当前活动选项卡的URL。
我见过这样做的例子:
chrome.tabs.query({'active': true, 'lastFocusedWindow': true}, function (tabs) {
var url = tabs[0].url;
});不幸的是,我不知道该把它放在哪里,以及如何将结果放到面板中。我从未看到来自chrome.devtools.panels.create回调的console.log输出。
下面是我到目前为止创建的文件。
manifest.html
{
"name": "DevTools panel",
"version": "0.0.1",
"manifest_version": 2,
"description": "Dev tools test.",
"devtools_page": "devtools.html",
"permissions": [
"tabs",
"http://*/*",
"https://*/*"
]
}devtools.js
chrome.devtools.panels.create("DevTools panel","chrome.png", "panel.html", function(panel) {
console.log("After panel create");
});panel.html
<html>
<head>
<script>alert('hello')</script>
</head>
<body>
<h2>DevTools panel</h2>
<div id="currentUrl">The current url should go here</div>
</body>
发布于 2021-10-18 23:15:47
chrome.tabs在开发工具中不可用。如果使用的是devtools_page,则可以使用devtools接口
在火狐中或在webextension-polyfill中
const [response, error] = await browser.devtools.inspectedWindow.eval(
"location.href"
);
// Your URL is in `response`在Chrome中:
browser.devtools.inspectedWindow.eval("location.href", (response, error) => {
// Your URL is in `response`
});https://stackoverflow.com/questions/43351103
复制相似问题