Javascript 如何在chrome扩展中获得JSON响应

Javascript 如何在chrome扩展中获得JSON响应,javascript,google-chrome-extension,Javascript,Google Chrome Extension,我想做一个chrome扩展。我需要得到在chrome开发工具中可以看到的JSON响应。这是一篇使用fetch的文章。我可以使用哪种API或javascript方式?直接使用(另一个好的选择是) 例如: async function getData() { try { const response = await fetch('https://your-res-website.com'); const resJson = await response.jso

我想做一个chrome扩展。我需要得到在chrome开发工具中可以看到的JSON响应。这是一篇使用fetch的文章。我可以使用哪种API或javascript方式?

直接使用(另一个好的选择是)

例如:

async function getData() {
    try {
        const response = await fetch('https://your-res-website.com');
        const resJson = await response.json();

        return resJson;
    } catch (error) {
        console.warn('getData error', error);
    }

    return null;
}

getData().then(data => console.log(data));

您可以使用jquery AJAX从API获取数据假设您想在选项卡中拦截站点发出的请求,您可以在页面上下文()中使用chrome.debugger API()或hook XMLHttpRequest。到目前为止,您做了哪些尝试?不是应该用JS编写一个普通的扩展,这样你就可以使用JS的东西了吗?谢谢,但我已经用这种方法直接获取了。它不起作用。它是一家大公司的网站,当我用这种方法时,它总是回复“状态500”。但在chrome中,这是正常的,所以我尝试在chrome中获取消息。尝试在chrome中复制成功响应作为fetch,并根据success fetch fetch进行更新。fetch fetch fetch是在js env中发出请求的标准方式,因此它与web、chrome或节点无关(在node js中,您可以找到同构fetch或axios)。好吧,我测试了请求负载只能使用两次,这意味着我是否可以直接得到chrome的响应,或者在chrome的响应之后我得到第一次的有效载荷