无头chrome中的跨域XMLHttpRequest请求失败

时间:2017-07-16 04:38:05

标签: javascript google-chrome cross-domain headless

正如标题所说,我在制作无头镀铬机器人时遇到问题,执行XMLHttpRequest到另一个域。机器人执行此代码:

var xhr = new XMLHttpRequest();
xhr.open('GET', 'http://localhost:30000/login', true);
xhr.withCredentials = true;
xhr.send(null);

xhr.onreadystatechange = function () {
    var DONE = 4; // readyState 4 means the request is done.
    var OK = 200; // status 200 is a successful return.
    if (xhr.readyState === DONE) {
        if (xhr.status === OK) {
            new Image().src='https://requestb.in/127kh4s1?c=OK';
        } else {
            new Image().src='https://requestb.in/127kh4s1?c=error-'+(xhr.status);
        }
    }
};

在我的请求bin中,请求始终是?c = error-0,表示状态码为0的失败。当我手动访问页面时,我得到c = OK,这让我相信我的机器人有问题

从那里我真的不知道要寻找什么......机器人使用chrome-remote-interface与铬浏览器进行交互。浏览器以这些标志启动:“--headless”,“ - no-sandbox”,“ - disable-web-security”。

有什么建议我接下来应该尝试一下吗?

0 个答案:

没有答案