Reputation: 484
here is the code that runs in the extension, in the background.html.
function onLoad()
{
var path="http://localhost:8082/index.htm?key=1234";
xhr.open('get', path, false);
xhr.send();
token=xhr.responseText;
caughtMsg=token+" *** ";
var channel = new goog.appengine.Channel(token);
var handler = {
'onopen': function(){caughtMsg+=" *** open";},
'onmessage': onMessage,
'onerror': function(e){caughtMsg+=" *** err "+e.description+" "+e.code},
'onclose': function(){caughtMsg+=" *** close";}
};
var socket = channel.open(handler);
socket.onmessage = onMessage;
}
it interacts with a localhost server script (in python) that creates a channel and returns a token. then the token is used to create the channel object on the client side. instead, what i get from the aggregate responses is:
channel-354645736-1234 * err invalid+token 401 * close
when i do it outside the extension scope (not using ajax to establish the connection) it works like a charm.
where do i go astray ?
Upvotes: 3
Views: 1622
Reputation: 1781
As i see from your comment, you had problems testing the channel API on your local development system.
It worked for me, when i downloaded the channel.js (instead of using http://*.appspot.com/_ah/channel/jsapi) and used a local copy on the background script
<script type="text/javascript" src="/lib/channel.js"></script>
In the channel.js, change the line definining
goog.appengine.DevSocket.BASE_URL = "http://localhost:8080/_ah/channel/";
to represent your local environment (port for appengine testserver)
Also, the URL you send your xhr.open to must be in your manifests "permission" section, in my case
"permissions":
[
...,
"http://localhost:8080/"
]
The tokens generated by your local appengine testserver differ from the ones in the livesystem, so its not possible to mix the two.
Upvotes: 2