Google chrome extension Chrome扩展-不在请求中发送Cookie

Google chrome extension Chrome扩展-不在请求中发送Cookie,google-chrome-extension,Google Chrome Extension,我读了很多问题,尝试了很多方法,但都没有成功。我的问题与此类似,但我之所以发帖是因为我已经尝试了所有方法,但仍然没有成功 我想检查我的服务器上是否维护了用户会话。我有一个Web服务,它根据收到的cookies返回一个布尔值 浏览器有责任在请求服务器时发送cookies(如果有)。因此,当我通过chrome扩展请求时,理论上浏览器也应该发送cookies。然而,事实并非如此 这是我的密码:- content.js fetch('https://zoffers.in/apis/shops/get_a

我读了很多问题,尝试了很多方法,但都没有成功。我的问题与此类似,但我之所以发帖是因为我已经尝试了所有方法,但仍然没有成功

我想检查我的服务器上是否维护了用户会话。我有一个Web服务,它根据收到的cookies返回一个布尔值

浏览器有责任在请求服务器时发送cookies(如果有)。因此,当我通过chrome扩展请求时,理论上浏览器也应该发送cookies。然而,事实并非如此

这是我的密码:-

content.js

fetch('https://zoffers.in/apis/shops/get_aff_url/', {
    credentials: 'include',
    mode: 'cors',
    async: false,
    method: 'POST',
    headers: {
        'Content-Type': 'application/json'
    },
    body: JSON.stringify({
        name: 'Hubot',
        login: 'hubot',
    })
})
.then(function(data) {

})
.catch(function(error) {

})
message = {
    'event_type': 'Event1',
}
chrome.runtime.sendMessage(message);
chrome.runtime.onMessage.addListener(
    function(request, sender, sendResponse){
        if(request.event_type === 'Event1'){
            chrome.tabs.query({active: true, currentWindow: true}, function(tabs){
                fetch('https://zoffers.in/apis/shops/get_aff_url/', {
                    credentials: 'include',
                    mode: 'cors',
                    async: false,
                    method: 'POST',
                    headers: {
                        'Content-Type': 'application/json'
                    },
                    body: JSON.stringify({
                        name: 'Hubot',
                        login: 'hubot',
                    })
                })
                .then(function(data) {

                })
                .catch(function(error) {

                })
            }
        }
    }
);
Manifest.json

{
    "manifest_version": 2,
    "version": "0.1",
    "content_scripts": [{
        "matches": [
            "https://*/*/"
        ],
        "js": ["js/content.js"],
        "run_at": "document_start"
    }],
    "browser_action": {
        // "default_icon": "icon.png",
        "default_popup": "popup.html",
        "default_title": "Click here!"
    },
    "permissions": [
        "identity",
        "identity.email",
        "tabs",
        "notifications",
        "cookies",
        "https://zoffers.in/"
    ]
}
我做错了什么?谁能帮我渡过难关

已更新

content.js

fetch('https://zoffers.in/apis/shops/get_aff_url/', {
    credentials: 'include',
    mode: 'cors',
    async: false,
    method: 'POST',
    headers: {
        'Content-Type': 'application/json'
    },
    body: JSON.stringify({
        name: 'Hubot',
        login: 'hubot',
    })
})
.then(function(data) {

})
.catch(function(error) {

})
message = {
    'event_type': 'Event1',
}
chrome.runtime.sendMessage(message);
chrome.runtime.onMessage.addListener(
    function(request, sender, sendResponse){
        if(request.event_type === 'Event1'){
            chrome.tabs.query({active: true, currentWindow: true}, function(tabs){
                fetch('https://zoffers.in/apis/shops/get_aff_url/', {
                    credentials: 'include',
                    mode: 'cors',
                    async: false,
                    method: 'POST',
                    headers: {
                        'Content-Type': 'application/json'
                    },
                    body: JSON.stringify({
                        name: 'Hubot',
                        login: 'hubot',
                    })
                })
                .then(function(data) {

                })
                .catch(function(error) {

                })
            }
        }
    }
);
background.js

fetch('https://zoffers.in/apis/shops/get_aff_url/', {
    credentials: 'include',
    mode: 'cors',
    async: false,
    method: 'POST',
    headers: {
        'Content-Type': 'application/json'
    },
    body: JSON.stringify({
        name: 'Hubot',
        login: 'hubot',
    })
})
.then(function(data) {

})
.catch(function(error) {

})
message = {
    'event_type': 'Event1',
}
chrome.runtime.sendMessage(message);
chrome.runtime.onMessage.addListener(
    function(request, sender, sendResponse){
        if(request.event_type === 'Event1'){
            chrome.tabs.query({active: true, currentWindow: true}, function(tabs){
                fetch('https://zoffers.in/apis/shops/get_aff_url/', {
                    credentials: 'include',
                    mode: 'cors',
                    async: false,
                    method: 'POST',
                    headers: {
                        'Content-Type': 'application/json'
                    },
                    body: JSON.stringify({
                        name: 'Hubot',
                        login: 'hubot',
                    })
                })
                .then(function(data) {

                })
                .catch(function(error) {

                })
            }
        }
    }
);

已将
background.js
添加到manifest.json文件。但仍然不起作用。

您可以对任何可用的URL使用标准和访问cookie。

内容脚本中的Chrome不推荐的跨源请求。在后台脚本中执行,如中所示。仍然没有帮助。即使将获取代码移到background.js,请求仍然没有cookie头。请检查更新的代码。我也尝试与其他用户登录,但没有成功。有什么问题吗?然后我如何将cookie设置到web请求中?@PythonEnthusiast这是另一个问题。顺便说一句,您是否尝试过“凭证:”包括“?对检查问题。已尝试使用
凭据:包括
。我也研究过发送cookie,我们必须使用
webRequest
API。谢谢你的帮助。不过,我相信问题出在别的方面。它与跨来源请求有关。我在DomainB网站上向DomainA提出请求。这将阻止自动发送cookie。我正在尝试是否可以在不显式传递cookies的情况下自动发送。我发现
xhr.withCredentials=true,但仍然不起作用。这方面的任何线索都会有所帮助。谢谢