【问题标题】:Project to make an extension to detect phishing URL制作扩展程序以检测网络钓鱼 URL 的项目
【发布时间】:2022-01-26 19:32:16
【问题描述】:

目标:该项目旨在制作一个 chrome 扩展,可以在页面加载时检测任何网络钓鱼 URL。

当前进程:我制作了一个 API,每当我们传递任何 URL 时,它都会给出响应,因为它是网络钓鱼 URL 还是非网络钓鱼 URL。制作 API 后,我按照制作清单、HTML 和 JavaScript 文件的方法进行操作。 API 负载: 网址:https://phishingurldetectorapi.herokuapp.com/predict1(方法=发布)

Body:
{
    "url" : "www.google.com"
}

Response:
"It is  not a phishing url"

我想在任何页面加载到我的 API 的“url”字段时传递它的 URL,它可以显示响应。

问题:我目前停留在关于如何在我的 API 正文中使用 javascript 传递 URL 的部分。 有人可以帮忙吗?

【问题讨论】:

  • 你使用window.location.href获取当前页面的URL并传递给body怎么样?
  • 这个抓取的url怎么能通过我的api体呢?

标签: javascript python jquery google-chrome-extension


【解决方案1】:

您可以通过 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://*/*。 例如

"content_scripts": [
      {
        "matches": [
          "https://*/*"
        ]
      }
 ]

https://phishingurldetectorapi.herokuapp.com/predict1

很遗憾,此服务器不允许跨域请求,如果您拥有它,则必须先允许 cors。否则,您将无法从您的 chrome 扩展程序发送请求。

【讨论】:

  • 我用flask制作了这个api,你能帮我如何在这个api中允许cors。
  • 不,如果您不是该 Heroku API 服务器的所有者,则不能。这就是 CORS 的工作原理。
  • 我是这台服务器的所有者.. 因为我已经在 heroku 上构建了这个应用程序..
  • 好的,您可以允许来自服务器的 CORS。以下是如何启用php corspython corsnodejs cors。就是这样。
猜你喜欢
  • 2014-12-27
  • 1970-01-01
  • 2022-12-19
  • 1970-01-01
  • 2021-09-07
  • 2020-01-16
  • 2023-04-10
  • 1970-01-01
  • 2012-04-14
相关资源
最近更新 更多