How do I send an HTTP GET request in chrome extension?

两盒软妹~` 提交于 2019-12-02 21:07:09

You have to go to your manifest.json and add the permission for www.example.com:

{
    "name": "My extension",
    ...
    "permissions": [
        "http://www.example.com/*"
    ],
    ...
}

Then in your background page (or somewhere else) you can do:

fetch('http://www.example.com?par=0').then(r => r.text()).then(result => {
    // Result now contains the response text, do what you want...
})

Old (deprecated) version using XMLHttpRequest:

var xhr = new XMLHttpRequest();

xhr.open("GET", "http://www.example.com?par=0", false);
xhr.send();

var result = xhr.responseText;

For more information on this topic, see the relative documentation page.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!