【问题标题】:Chrome - How To Load Channel Token?Chrome - 如何加载频道令牌?
【发布时间】: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


    【解决方案1】:

    如果收到 channelToken,您应该使用 messagePassing 通知 background.html。 http://code.google.com/chrome/extensions/messaging.html

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2020-08-07
      • 2013-08-09
      • 2021-09-03
      • 2013-06-04
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多