GM.xmlHttpRequest `synchronous` 选项不起作用

GM.xmlHttpRequest `synchronous` option not working

以下代码创建内容为 undefined:

的警报
// ==UserScript==
// @name     Unnamed Script 188765
// @version  1
// @grant    GM.xmlHttpRequest
// @include  http*//markasoftware.com/*
// ==/UserScript==

alert(typeof GM.xmlHttpRequest({
  url: 'https://google.com',
  synchronous: true,
  method: 'GET',
}));

基于 documentation,我希望 synchronous 选项使调用 return 成为响应 object。然而,它的行为方式与异步调用相同; onload 处理程序仍然有效。 synchronous 选项是否被禁用?有没有其他方法可以同步发出跨域请求?

文档中说 return 值在使用同步模式时会有所不同是错误的。只需设置一个您在 onload 函数之外使用的变量。

let returnData;
GM.xmlHttpRequest({
  url: 'https://google.com',
  synchronous: true,
  method: 'GET',
  onload: function(response) {
    returnData = response;
  }
}));
alert(returnData);