cuzi / RequestQueue


Version: 6+5d00a23 updated

Summary: A simple queue for GM.xmlHttpRequest, GM_xmlhttpRequests or other async functions


License: MIT

A simple queue for GM_xmlhttpRequests or other async functions

  • Version 6
  • Support for Greasemonkey version 4 and Firefox version 57
  • Version 5
  • New methods: resetTotal(), hasReachedTotal(), hasRunning()
  • Version 4
  • Fix for XMLHttpRequest.abort()
  • Version 3
  • Fix for Chrome
  • Version 2
  • Fix for Firefox 36.0
  • Version 1
  • initial version

new RequestQueue([maxParallel[, maxTotal]])

  • maxParallel
    defaults to 1 i.e. no paralllel requests
  • maxTotal
    defaults to unlimited

RequestQueue.prototype.add(req[, fun[, thisArg]])
Schedule a request

  • req
    An object that is the only argument of fun. This will be extended and therefore must be mutable.
    At least one of the following methods onload, onerror or onabort must be implemented.
  • fun
    defaults to GM_xmlhttpRequest
  • thisArg
    The value of this provided for the call to fun. Keep strict mode in mind!

Results in a call like this:

For all scheduled requests that are currently running: result =
this will call result.abort()
For GM_xmlhttpRequest this will subsequently fire an onabort event

Clear the list of pending requests i.e. requests that were not sent yet.

Abort both running and pending requests


var rq = new RequestQueue(1); // 1 -> Allow no parallel requests
  method: "GET",
  url: "",
  onload: function (response){
    console.log("onload 1");
  method: "GET",
  url: "",
  onload: function (response){
    console.log("onload 2");

The request to page 1 will be sent immediately.
The request to page 2 will be sent after the the first request has finished, but before the first onload event is called.

Rating: 3

3 Votes