Chrome扩展程序发送带有请求的旧Cookie

时间:2019-08-01 12:41:31

标签: google-chrome-extension xmlhttprequest

我创建了一个相当简单的Chrome扩展程序,让人们可以提交指向网站的链接。它将xhr请求发送到该站点,该站点应自动将请求发送给该站点存储的cookie。但它会发送较旧的Cookie。我使用该站点中的一个帐户登录,但是链接是在另一个帐户下提交的。我尝试重新加载扩展程序,重新启动chrome,甚至重新启动计算机,但无济于事。

这是请求的代码:

  var xhr = new XMLHttpRequest();
  xhr.withCredentials = true;
  xhr.crossDomain = true;

  xhr.open('POST', "https://www.example.com/articles/")

  var formData = new FormData();
  formData.append('utf8', true);
  formData.append('article[link]', request.link);
  formData.append('article[title]', request.title);
  formData.append('commit', "Create+Article");
  xhr.setRequestHeader("X-requested-with", "XMLHttpRequest");
  xhr.send(formData);

我在扩展控制台中遇到两个错误,不确定是否与错误有关:

Unchecked runtime.lastError: The message port closed before a response was received.
www.example.com/articles/:1 Failed to load resource: the server responded with a status of 401 ()

0 个答案:

没有答案