【发布时间】:2012-04-15 18:42:10
【问题描述】:
我有一个扩展程序,当用户启用应用程序时,我会在其中对用户进行身份验证。然后服务器返回一个通道令牌,我用它来建立一个通道。身份验证代码出现在 script.js 中,而通道创建在 background.html 中。我的问题是,在加载 background.html 后运行身份验证时,如何将 channelToken 放入 background.html?
我想说明我正在运行 Google App Engine (Python) 作为我的服务器。我还从 here 复制了 javascript 代码并将其放在我的清单中,而不是将 <script type="text/javascript" src="/_ah/channel/jsapi"></script> 放在 background.html 中。
//background.html
var channel = new goog.appengine.Channel(channelToken);
var socket = channel.open()
socket.onopen = function() {
// Do stuff right after opening a channel
console.log('socket opened');
}
socket.onmessage = function(evt) {
// Do more cool stuff when a channel message comes in
console.log('message recieved');
console.log(evt);
}
【问题讨论】:
标签: javascript python google-app-engine google-chrome-extension channel