GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

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 #2701

New issue
Copy link
New issue
Copy link
Closed
Closed
DOMException on GM.xmlHttpRequest when context contains functions#2701
Copy link
Labels
confirmed
Milestone
4.14

Description

@hkyuwon
hkyuwon
opened on Nov 18, 2017
Issue body actions

When 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}});

Reacted by Cerberus-tm

Activity

  1. ccloli commented on Nov 20, 2017

    @ccloli
    ccloli
    on Nov 20, 2017
    Contributor
    More actions

    I have this problem too, maybe it's related to #2647 . Try adding location.origin before the URL.

  2. arantius
    changed the title [-]DOMException on GM.xmlHttpRequest[/-] [+]DOMException on GM.xmlHttpRequest when using `context`[/+] on Nov 21, 2017
  3. arantius
    added this to the This milestone has been deleted milestone on Nov 21, 2017
  4. arantius
    removed this from the This milestone has been deleted milestone on Jan 19, 2018
  5. Mzyxptlk commented on Jan 3, 2021

    @Mzyxptlk
    Mzyxptlk
    on Jan 3, 2021
    More actions

    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.

    Reacted by Cerberus-tm
  6. arantius commented on May 28, 2026

    @arantius
    arantius
    on May 28, 2026
    Collaborator
    More actions

    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.
    
  7. arantius
    added
    confirmed
    on May 28, 2026
  8. arantius
    changed the title [-]DOMException on GM.xmlHttpRequest when using `context`[/-] [+]DOMException on GM.xmlHttpRequest when `context` contains functions[/+] on May 28, 2026
  9. arantius commented on May 28, 2026

    @arantius
    arantius
    on May 28, 2026
    Collaborator
    More actions

    https://wiki.greasespot.net/index.php?title=GM.xmlHttpRequest&diff=8643&oldid=7747

    I've noted the root issue in the documentation.

  10. arantius commented on May 28, 2026

    @arantius
    arantius
    on May 28, 2026
    Collaborator
    More actions

    An even more minimal test script:

    // ==UserScript==
    // @name     GM issue 2701
    // @grant    GM.xmlHttpRequest
    // ==/UserScript==
    GM.xmlHttpRequest({
      'url': location.origin,
      'context': {
        'call_me': () => {},
      }
    });
  11. arantius
    added this to the 4.14 milestone on May 28, 2026
  12. arantius
    added a commit that references this issue on May 28, 2026

    Fix sanitizing port messages for GM.xhr.

    ac4a214
  13. arantius commented on May 28, 2026

    @arantius
    arantius
    on May 28, 2026
    Collaborator
    More actions

    I've pushed a commit (see above) that should fix this, but I still need to test how it interacts with the upload handlers.

  14. arantius commented on May 28, 2026

    @arantius
    arantius
    on May 28, 2026
    Collaborator
    More actions

    Actually, I rolled back the documentation I mentioned above -- the code change makes that untrue.

  15. arantius commented on May 29, 2026

    @arantius
    arantius
    on May 29, 2026
    Collaborator
    More actions

    Test script https://github.com/greasemonkey/greasemonkey/blob/master/test/scripts/api-xhr-upload.user.js

    Logs upload progress and load, before the overall load. LGTM.

  16. arantius
    closed this as completedon May 29, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    confirmed

    Projects

    No projects

      Milestone

      • 4.14No due date

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions

      You are visitor 01402503 — GeezerVison does not store the pages you look up.
      Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.