目标:这个项目的目的是使一个铬扩展,可以检测任何钓鱼网址时,一个网页加载。
当前进程:我已经做了一个API,在这个API中,每当我们传递任何URL时,它都会给出一个响应,因为它是一个钓鱼URL,或者不是一个网络钓鱼URL。在创建API之后,我将遵循下面的方法来生成清单、HTML和JavaScript文件。API有效载荷: URL:https://phishingurldetectorapi.herokuapp.com/predict1 (方法= Post)
Body:
{
"url" : "www.google.com"
}
Response:
"It is not a phishing url"每当任何页面加载到我的API的" URL“字段时,我都想传递它的url,并且它可以显示响应。
问题:我目前还停留在如何在API主体中使用javascript传递URL的部分。有人能帮忙吗?
发布于 2022-01-26 09:43:15
您可以通过ajax正文发送当前页面url,如下所示。
(()=>{
let current_page_url = window.location.href;
fetch('https://phishingurldetectorapi.herokuapp.com/predict1',{
method:'POST',
headers:{
'Content-Type':'application/json'
},
body:JSON.stringify({url:current_page_url})
})
.then(e=>e.json())
.then(res=>console.log(res))
.catch(err=>console.log(err))
})()要在所有页面中工作,必须在匹配数组中设置https://*/*。e.g
"content_scripts": [
{
"matches": [
"https://*/*"
]
}
]https://phishingurldetectorapi.herokuapp.com/predict1不幸的是,此服务器不允许跨域请求,如果您拥有它,您必须首先允许cors。否则,您将无法从您的铬扩展名发送请求。
https://stackoverflow.com/questions/70858770
复制相似问题