javascript - 如何在 chrome ext 的弹出窗口中显示来自像素的调用?
问题描述
我正在寻找创建一个与 Ghostry 或类似的工作非常相似的 chrome ext。chrome ext 的弹出窗口显示某些网络调用。
我想显示来自某种像素类型的网络调用,然后能够显示来自该调用的项目。
我已经浏览了这个https://www.pubnub.com/blog/category/product-updates/
这似乎不起作用。我相信这可能会被破坏。
我有这个
// popup.html
<!DOCTYPE html>
<html>
<head>
<link rel="stylesheet" href="../main.css"/>
<link href="https://unpkg.com/tailwindcss@^2/dist/tailwind.min.css" rel="stylesheet">
</head>
<body class="flex flex-col p-4">
<main class="main flex-grow">
<h1 class="text-center font-bold text-xl">HCP365 Debugger</h1>
<section class="p-4">
<div id="data"></div>
</section>
</main>
<footer>
<button id="getCurrentURL" class="btn w-full drop-shadow bg-purple-500 capitalize outline-none focus:outline-none mr-1 mb-1 ease-linear transition-all duration-150 hover:bg-purple-800">get url</button>
</footer>
<!-- Scripts -->
<script src="popup.js"></script>
</body>
</html>
// popup.js
let button = document.getElementById('getCurrentURL');
let dataTest = document.getElementById('data');
// When the button is clicked, get current url from current tab
button.addEventListener('click', async () => {
let queryOptions = { active: true, currentWindow: true };
let [tab] = await chrome.tabs.query(queryOptions);
let currentURL = tab.url;
dataTest.innerHTML = currentURL;
});
chrome.devtools.network.onRequestFinished.addListener(function (request) {
var parser = document.createElement('a');
parser.href = request.request.url;
if (parser.hostname.split('.')[1] == 'pubnub') {
params = parser.pathname.split('/');
if (params[1] == 'publish') {
channel = params[5];
message = params[7];
}
}
request.getContent(function (body) {
parsed = JSON.parse(body);
console.log(parsed);
dataTest.innerHTML = parsed;
});
});
作为一项测试,我设法通过单击一个按钮来获取 currentTabs url,但我希望在没有单击按钮的情况下在弹出窗口中显示调用。我只是希望他们已经在那里。
这必须通过background.js
吗?
如果有人能指出我正确的方向或给我任何指示,那就太好了。
解决方案
推荐阅读
- compilation - 当 setup.py 更改为 Pip 可编辑时重新编译 Cython 扩展
- scala - Spark Dataframe : Custom Function on Window
- api - How to host WSO2 API manager?
- ruby-on-rails - Rails query with more than one nested attributes
- html - 在工具提示中插入 html 标签
- vba - Get row and column number of first cell in Excel table
- vue.js - (VUEJS) Access methods from Axios inside created
- r - 平滑线没有线浸ggplot
- php - 使用 php mysql Ajax 使用弹出表单在数据库中插入数据
- docker - 如何将 Kong 部署到 docker swarm?