0

I'm trying to fetch my chrome extension version, using the following code:

function getVersion(callback) {
        var xmlhttp = new XMLHttpRequest();
        xmlhttp.open('GET', 'manifest.json');
        xmlhttp.onload = function (e) {
            var manifest = JSON.parse(xmlhttp.responseText);
            callback(manifest.version);
        }
        xmlhttp.send(null);
}

getVersion(function (ver) { console.log(ver); });

Problem is, HTTP request is sent to the site I'm injecting the script into, and obviously it fails.

For instance when my script is injecting into http://prodgame19.lordofultima.com/189, the HTTP request is sent to http://prodgame19.lordofultima.com/189/manifest.json.

What am I doing wrong?

Thanks.

user1617735
  • 451
  • 5
  • 16
  • You do realize you get 404 on the url? (the manifest.json file) – JoxTraex Jan 01 '13 at 08:11
  • Yes, and that's the question. Why does it send the request to the site I'm injecting into? – user1617735 Jan 01 '13 at 08:13
  • Are you trying to retrieve the manifest.json file on that server? Can you confirm that that file exists on the ftp url? – JoxTraex Jan 01 '13 at 08:16
  • I'm trying to retrieve the manifest of my chrome extension, and I'm using, more or less, the example I've found around here. I was presuming the http request would access the extension's manifest.json, but that doesn't happen. So obviously, I'm doing something wrong. – user1617735 Jan 01 '13 at 08:21
  • I think you're misunderstanding how an HTTP GET works. It just retrieves data from the site. Specifically if its going to the url+manifest.json its because you're claiming a file that like that exists on the server. If it doesn't it can't read the json file. In the Example try using the url and you'll see that it most likely returns a json file that can be parsed and read. – JoxTraex Jan 01 '13 at 08:28
  • Try this link: https://groups.google.com/a/chromium.org/forum/?fromgroups=#!topic/chromium-extensions/F-eg1H6aY5k – JoxTraex Jan 01 '13 at 08:33
  • That's exactly the code I'm using and that particular example sends GET request to '/manifest.json'. However when I inject my extension script, the website I'm injecting into doesn't have manifest.json, it's located on my local hard drive in the same directory where script code resides. The question is how can that example code access the manifest.json of the extension? – user1617735 Jan 01 '13 at 08:41
  • I think there's a bit of confusion here. I have an extension I've developed. Once I install it, chrome stores it in a certain directory on my local hard disk, along with its manifest.json file, which contains version information I want to fetch when my script is being injected, or is running. The example I've found is supposed to do that, but it does something completely different, hence the original question. – user1617735 Jan 01 '13 at 08:53

0 Answers0