我有一个扩展程序,我在启用应用程序时对用户进行身份验证。然后服务器返回一个通道令牌,我用它来建立一个通道。身份验证的代码发生在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);
}
答案 0 :(得分:1)
如果收到channelToken,您应该使用messagePassing通知background.html。 http://code.google.com/chrome/extensions/messaging.html