0

I have the following GreaseMonkey Script:

GM_xmlhttpRequest({
     method: 'GET',
     url: "http://www.testurl.com",
     headers: {
         'User-agent': 'Mozilla/4.0 (compatible) Greasemonkey/0.3',
     },
     onload: function(responseDetails) {

   var tagString = responseDetails.responseText;       
   var range = document.createRange();
   range.selectNode(document.body);
   var documentFragment = range.createContextualFragment(tagString);

How do I now extract stuff from documentFragment? documentFragment.getElementById(''), document.body etc all returns undefined.

I suspect this is due to the createContextualFragment method returning a XPCNativeWrapper object, but how do I work around this to access the underlying DOM?

Thanks

Dave
  • 433
  • 1
  • 5
  • 7

2 Answers2

1

Not sure if this is answered by Load and parse remote url with greasemonkey

Depending what you want to do, might be easier to include jquery..

Community
  • 1
  • 1
aland
  • 1,824
  • 2
  • 26
  • 43
0

I suspect this is due to the createContextualFragment method returning a XPCNativeWrapper object, but how do I work around this to access the underlying DOM?

This is done using wrappedJSObject:

var documentFragment = range.createContextualFragment(tagString).wrappedJSObject;
hlovdal
  • 26,565
  • 10
  • 94
  • 165