GeezerVison is showing github.com — DOMException on GM.xmlHttpRequest when `context` contains functions · Issue #2701 · greasemonkey/greasemonkey
DOMException on GM.xmlHttpRequest when context contains functions #2701DescriptionWhen I try to use [context] on xHR, I meet this error.
Script error: DOMException { }
// no problem
GM.xmlHttpRequest({method:"GET",url:"/",onload:function(r){console.log(r);}});
// error
GM.xmlHttpRequest({method:"GET",url:"/",context:{f:function(r){console.log(r);}}});
// error
GM.xmlHttpRequest({method:"GET",url:"/",context:{d:document}}); Activityccloli commented on Nov 20, 2017 I have this problem too, maybe it's related to #2647 . Try adding location.origin before the URL. changed the title [-]DOMException on GM.xmlHttpRequest[/-] [+]DOMException on GM.xmlHttpRequest when using `context`[/+] on Nov 21, 2017added this to the This milestone has been deleted milestone on Nov 21, 2017removed this from the This milestone has been deleted milestone on Jan 19, 2018Mzyxptlk commented on Jan 3, 2021 I am also experiencing this issue. Minimal testcase:
// ==UserScript==
// @name onload context bug
// @grant GM.xmlHttpRequest
// @include https://github.com/greasemonkey/greasemonkey/issues/2701
// ==/UserScript==
var does_not_work = function() {
console.log('context called!');
};
GM.xmlHttpRequest({
'url': location.origin,
'onload': function(req) {
console.log('onload called');
if (req.context.call_me) {
req.context.call_me();
}
else {
console.log('nothing to call');
}
},
'context': {
'call_me': does_not_work
}
});
console.log('sent request!');
Loading this page with the above user script installed results in the following error:
Script error in [Greasemonkey script null/onload context bug; version 1]:
DataCloneError: The object could not be cloned.
The error does not occur when the context object is empty (but obviously does_not_work is not called in that case either). Unfortunately I've not been able to find a useful backtrace. arantius commented on May 28, 2026 Using GitHub as the repro is not ideal as opening it spews hundreds of log entries to the console, but the above minimal test case on a simpler page does still log:
Script error in [Greasemonkey script null/onload context bug]:
DataCloneError: Function object could not be cloned.
changed the title [-]DOMException on GM.xmlHttpRequest when using `context`[/-] [+]DOMException on GM.xmlHttpRequest when `context` contains functions[/+] on May 28, 2026arantius commented on May 28, 2026 arantius commented on May 28, 2026 An even more minimal test script:
// ==UserScript==
// @name GM issue 2701
// @grant GM.xmlHttpRequest
// ==/UserScript==
GM.xmlHttpRequest({
'url': location.origin,
'context': {
'call_me': () => {},
}
});arantius commented on May 28, 2026 I've pushed a commit (see above) that should fix this, but I still need to test how it interacts with the upload handlers. arantius commented on May 28, 2026 Actually, I rolled back the documentation I mentioned above -- the code change makes that untrue. arantius commented on May 29, 2026
MetadataMetadataDevelopmentNo branches or pull requestsIssue actions
|