Getting a Status Code of 0 when doing some XMLHtttpRequest in a Background Page

49 views
Skip to first unread message

mfcabrera

unread,
May 11, 2011, 7:15:56 PM5/11/11
to Chromium-extensions
Hi Guys,

I am writing an extension (my first want, also I am not well versed in
JS, actually this is my first project in the language). And I am
having problems while fetching an url using the backgroud page.

I am getting an status code of 0 and no data from a request. The
strange thing is that when I use Wireshark (to sniff the packages
sent by Chrome) I get the data OK and with a status code of 200. Below
you see my manifiest file and the code. I basically copied the code
form the content script documentation page link:


http://src.chromium.org/viewvc/chrome/trunk/src/chrome/common/extensions/docs/examples/howto/contentscript_xhr/



Heres the code and the manifest. Thanks in advance.

background.html
===============

function fetchCurrency(callback) {
var invocation = new XMLHttpRequest();
var url = 'http://download.finance.yahoo.com/d/quotes.csv?
e=.csv&f=l1&s=USDCOP=X';


invocation.onreadystatechange = function(data) {
alert('Invocation Ready State: ' +invocation.readyState);
if (invocation.readyState == 4) {
alert('Invocation Status: ' + invocation.status); //shows
0!
if (invocation.status == 200 ) {
var data = invocation.responseText;
alert('The data es ' + invocation.data);
callback(data);

} else {
callback(null);
}
}
}
invocation.open('GET', url, true);
invocation.send();
};

function onRequest(request, sender, callback) {
if (request.action == 'getRate') {
fetchCurrency(callback);
}
};

// Wire up the listener.
chrome.extension.onRequest.addListener(onRequest);


/*
I then connect the content script as exemplified in the link I
posted. All is working OK but I am getting a weird 0 status code :'(
*/





Manifest.json
=====
{
"name": "XXXXX",
"version": "0.1",
"description": "test extension",

"browser_action": {
"default_icon": "icon.png",
"popup": "popup.html"
},
"content_scripts": [
{
"matches": ["http://*.amazon.com/*"],
"js": ["jquery.js", "content.js"]
}
],
"background_page": "background.html",
"permissions": [
"tabs",
"http://finance.yahoo.com/*",
"http://*.amazon.com/"
]
}

Abraham Williams

unread,
May 13, 2011, 3:56:18 PM5/13/11
to mfcabrera, Chromium-extensions
Your request is to http://download.finance.yahoo.com/ but your manifest specifies permission for http://finance.yahoo.com/.

Abraham
-------------
Abraham Williams | InboxQ | abrah.am
@abraham | github.com/abraham | blog.abrah.am
This email is: [ ] shareable [x] ask first [ ] private.




--
You received this message because you are subscribed to the Google Groups "Chromium-extensions" group.
To post to this group, send email to chromium-...@chromium.org.
To unsubscribe from this group, send email to chromium-extens...@chromium.org.
For more options, visit this group at http://groups.google.com/a/chromium.org/group/chromium-extensions/?hl=en.


PhistucK

unread,
May 13, 2011, 4:27:26 PM5/13/11
to mfcabrera, Abraham Williams, Chromium-extensions
Also, the "permissions" key is only supposed to have permission names ("tabs" and such) or hosts (scheme://domain/) - not paths (scheme://domain/path) - remove the "*" from the hosts you specified.

PhistucK
Reply all
Reply to author
Forward
0 new messages