Skip to content

Instantly share code, notes, and snippets.

@arantius
Created April 6, 2011 19:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save arantius/906344 to your computer and use it in GitHub Desktop.
Save arantius/906344 to your computer and use it in GitHub Desktop.
GM_xmlhttpRequest Alert Interference Test
// ==UserScript==
// @name GM_xmlhttpRequest Alert Interference Test
// @include http*
// ==/UserScript==
// Uses unsafeWindow.dump() because of
// https://github.com/greasemonkey/greasemonkey/issues#issue/1229
function doSampleXhr() {
unsafeWindow.dump('starting gm_xhr ...');
try {
GM_xmlhttpRequest({
method: "GET",
url: "http://localhost/",
onload: function() { unsafeWindow.dump('gm_xhr loaded\n'); },
onerror: function() { unsafeWindow.dump('gm_xhr failed\n'); }
});
} catch (e) { unsafeWindow.dump(e+'\n'); }
unsafeWindow.dump(' done\n');
}
var now = (new Date()).valueOf();
var then = parseInt(GM_getValue('last alert', 0), 10);
if (now - then > 60000) {
alert('Showing an alert which will break GM_xhr\n'
+ '(At URL: '+location.href+')');
GM_setValue('last alert', String(now));
}
doSampleXhr();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment