views:

20

answers:

1

I really can't figure out, what's wrong with this code:

This is my manifest.json file:

    {
     "name": "Test!",
     "version": "1.0",
     "description": "Testing this",
     "content_scripts": [ {
       "js": [ "jquery-1.4.2.min.js", "parser.js" ],
       "matches": [ "file:///*/*" ]
      } ],
     "permissions": [
       "tabs", 
       "http://*/*"
     ]
   }

Here is parser.js file

var xmlcontent = "<?xml version=\"1.0\" encoding=\"utf-8\"?><A><B><C>Hey</C></B></A>";
var doc = $(xmlcontent).find('C').text();

This simple script, throws the following error:

Uncaught TypeError: Cannot read property 'childNodes' of null

Can anyone help me?

A: 

This works for me here:

http://jsfiddle.net/Y9mPM/

Are you sure you have access to jQuery from this environment?

treeface
I have just copied the source directly from jquery's website in the same file that the previous code, and now it throws an other error: Uncaught TypeError: Cannot set property 'display' of null. This time the error comes from jquery code.
fceruti
Hmm...OK try something simple instead. Try: `alert($.toString());`. I don't think it will reveal much, but I'm curious.
treeface
output: function (a,b){return new c.fn.init(a,b)}
fceruti
Blast...as I suspected nothing appears to be wrong. Try this one: `$('<a><b></b></a>').html()`. I'm beginning to wonder if it's because `.text()` searches for HTML text nodes, but I could be wrong.
treeface
output: Uncaught TypeError: Cannot read property 'childNodes' of null
fceruti
OK, try something even simpler: `$.trim('test ')`. Basically I want to see what *does* work in the jQuery core.
treeface
=D that works... hope can be helpful
fceruti
I've been trying changing the version of jquery, and the 1.2.6 doesn't throw errors, but it doesn't find the element either =S
fceruti
I think the problem is that when jquery loads, as the current page is actually a XML file it tries to do some dom stuff that it cant.
fceruti
I'm guessing it's got something to do with that as well. I'm having no luck finding anything, and I'm currently at work, so I'm not in a position to mess around with Chrome extensions (though, I suppose, this is as good an excuse as any to try it out). Please let me know if you find the solution..I'm very curious!
treeface