首次使用该网站提出问题我对Chrome扩展程序不熟悉,所以我确定我犯了一些错误我提前道歉
我要通过邮寄请求发送当前标签的网址,我只能通过提交发送网址如何在页面加载中自动发送
这是我的代码
的manifest.json
{
"manifest_version": 2,
"name": "Phishing tool",
"description": "This extension send url to server to check for phishing",
"version": "1.0",
"browser_action": {
"default_icon": "icon.png",
"default_popup": "popup.html"
},
"permissions": [
"activeTab",
"tabs",
"http://localhost:8080/ph/FirstServlet*"
]
}
popup.html
<!DOCTYPE html>
<html>
<head><script src="p.js"></script></head>
<body>
<object width="200" height="50" ></object>
<form action="http://localhost:8080/ph/FirstServlet" method="POST">
link:<input type="text" name="first_name"> <br /><br />
<input type="submit" value="Submit" />
</form>
<p>
<button id="myBtn"> click here to display the url</button> </p>
<h1 id="demo">Url displays Here</h1>
</body>
</html>
p.js
document.addEventListener("DOMContentLoaded", function() {
chrome.tabs.query({currentWindow: true, active: true}, function(tabs) {
var tabURL = tabs[0].url;
var xhr = new XMLHttpRequest();
xhr.onload = function(){
console.log(xhr.responseText);
};
xhr.open("POST", "http://localhost:8080/ph/FirstServlet");
xhr.send(tabURL);
});
});
我尝试了但是当我点击插件图标时它没有显示来自服务器的响应
答案 0 :(得分:0)
假设您要将弹出式页面(扩展程序)中的网址发送到您的服务器,而您的服务器网址为SERVER_URL
,则需要执行以下操作:
在SERVER_URL
文件的permissions
字段中添加manifest.json
,对于您的情况,它将是
"permissions": [
"http://localhost:8080/ph/FirstServlet/*"
]
在popup.js
document.addEventListener("DOMContentLoaded", function() {
chrome.tabs.query({currentWindow: true, active: true}, function(tabs) {
var tabURL = tabs[0].url;
var formData = new FormData();
formData.append("first_name", tabURL);
var xhr = new XMLHttpRequest();
xhr.onload = function(){
console.log(xhr.responseText);
// Your logic
};
xhr.open("POST", SERVER_URL);
xhr.send(formData);
});
});