Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8089581
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T19:26:29+00:00 2026-06-05T19:26:29+00:00

This code works fine in Chrome. However, in Firefox, when it hits the GMxhr

  • 0

This code works fine in Chrome. However, in Firefox, when it hits the GMxhr request, it simply stops. It gets right up to the GMxhr call, then just… stops. I’ve checked everything I can think of, making sure that the responseType param is only set for chrome, etc… yet still nothing. Any ideas?

var body       = document.getElementsByTagName('body')[0]
  , messageDiv = document.createElement('div')
  ;

messageDiv.id = 'xhrComlink';
body.appendChild(messageDiv);

function getUri(e) {
'use strict';
var chrome = navigator.userAgent.toString().toLowerCase().indexOf('chrome') !== -1;

var bin2base64 = function bin2base64 (binary) {
...
};


var storeRetrievedFile = function storeRetrievedFile(response) {
    console.log(2);
    var thisComlink = e.target
      , evt         = document.createEvent("MouseEvents")
      ;

    var text = response.responseText
      , len  = text.length
      , arr  = new Uint8Array(len)
      , i    = 0
      ;

    if (!chrome) {
        for( i = 0; i < len; ++i ) {
            arr[i] = text.charCodeAt(i) & 0xFF;
        }
    }

    thisComlink.innerHTML = '';
    thisComlink.appendChild(
        document.createTextNode(
            chrome ? bin2base64(response.responseText) : bin2base64(arr.buffer)
        )
    );

    evt.initMouseEvent("dblclick", true, true, window, 0, 0, 0, 0, 0, false, false, false, false, 0, null);
    thisComlink.dispatchEvent(evt);
};

var gmXOptions = { method           : 'GET'
                 , overrideMimeType : 'text/plain; charset=x-user-defined'
                 , onload           : storeRetrievedFile
                 , url              : e.target.innerHTML
                 };

chrome && (gmXOptions.responseType = 'arraybuffer');

console.log(1);

GM_xmlhttpRequest(gmXOptions);
}

In the console, I get only “1” on Firefox. In Chrome, I get “1”, “2”, it rewrites the innerHTML, fires the event, and off we go.

I have also checked to make sure that Firefox has everything correct, with a dir of the gmXOptions at the same spot as the log(1) call:

Firefox:

method  "GET"
overrideMimeType    "text/plain; charset=x-user-defined"
url     "http://www.home...e-and-land-packages.jpg"
onload      storeRetrievedFile(response)

EDIT to explain the answer; maybe this’ll help someone else in the future:

Firefox’s GM has an annoying behaviour/bug:

1) Write a userscript which attaches an event listener. In that event listener function, such as getUri() above, use a GM_ function.

2) Now invoke that event’s trigger from any other javascript context except for the one which just created the listener. For example, use the common Chrome-friendly “inject jquery, callback to main(), continue” pattern.

3) But doing that, you lose access to GM functions in main(). So you have to put them right at the start of the script, outside of main(), before you inject jQuery, then “communicate” between those GM-using (a GM context) functions and the functions in main (an injected, non-GM context), in this case w/events.

Result) In GM terms, unsafeWindow is calling GM_xmlhttpRequest. That triggers the “security” in Firefox Greasemonkey, and it silently blocks the call to GM_xmlhttpRequest. You have to use the workaround to get the stack “cleaned up” enough to make Firefox GM’s “security” happy. Then it will call the GM_xmlhttpRequest.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-05T19:26:31+00:00Added an answer on June 5, 2026 at 7:26 pm

    I finally found the problem, though Firefox Greasemonkey makes it REALLY hard to find, and for whatever reason, it wasn’t throwing any error/warning/etc messages at all, which might have helped solve this faster.

    Anyhow, this was the problem: http://wiki.greasespot.net/0.7.20080121.0_compatibility

    Add

     setTimeout(function() {
    

    and

    }, 0);
    

    around the GM_xhr call, and all now works as it should.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This code works fine for FF, Safari, Chrome and IE9, but doesn't work 100%
This code works fine in <= IE7, but it doesn't work in firefox ..
I have this code that works fine when I call it from within the
ok, this code works just fine in Chrome. But, for some reason it does
This code works fine to create a grid of divs: for (var i =
this code works fine until I start scrolling: - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
This code works fine to find an available room within certain date, but it
This code works fine in C#: Expression.Lambda(LambdaBody); But none of the methods for building
The code below is creating a server to communicate with clients.This code works fine
web page : http://sideradesign.com/eco-art/gallery/ This code works fine in all brwosers except IE8 (haven't

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.