5

I'm researching on writing some JavaScript code that tampers with HTTP POST requests and responses. Since the code I want to write is largely a proof-of-concept, a Firefox extension is too much I think (plus I would prefer to not deal with all that wrapping and over-SSL restrictions). I wondered then if I could write it as a Greasemonkey script. My question therefore is this:

Can you use Mozilla's event observers (http-on-modify-request etc) under Greasemonkey ?

Please have in mind that I learned what JavaScript is 10 minutes ago and I don't have any experience in that domain. However I believe this is within my skills and with a little research and stubbornness I can implement it. Though I worry about trying to make something work in an impossible way.

Thanks!

George.

Brock Adams
  • 90,639
  • 22
  • 233
  • 295
george
  • 231
  • 1
  • 2
  • 4

1 Answers1

2

No, Greasemonkey scripts do not have access to XPCOM components. With the exception of the GM_ functions, Greasemonkey scripts can only do what ordinary JavaScript does.

You can usually intercept AJAX calls by overwriting XMLHttpRequest() -- see question 629671. Beware that there may be interference from JS libraries that the page may use.

Community
  • 1
  • 1
Brock Adams
  • 90,639
  • 22
  • 233
  • 295
  • Hey! thanks for the reply! I'm not interested in AJAX calls, just simple plain 'ole POST request/responses (and some binary data inside but that doesn't matter). "Greasemonkey scripts can only do what ordinary JavaScript does." So, event observers aren't "ordinary Javascript" ? – george Feb 07 '11 at 01:06
  • Event *listeners/handlers* are part of JavaScript, but only for things like AJAX. The kind of function you want is only available for add-ons/extensions. You might be able to tamper with the post data and then post the form using GM, but this is highly page specific and won't work for all data (EG files). – Brock Adams Feb 07 '11 at 02:19