Używam interfejsu API kanału w rozszerzeniu Chrome.Dlaczego Google App Engine Channel API (jsapi) nie może się załadować w rozszerzeniu Chrome?
W Google App Engine Channel API Javascript Reference (Python) strony mówi, że
Include the following in your html page before any JavaScript code that refers to it:
<script type="text/javascript" src="/_ah/channel/jsapi"></script>
Więc stawiam, że w nagłówku mojego pliku options.html:
<html>
<head>
<title>Extension Options</title>
<script type="text/javascript" src="/_ah/channel/jsapi"></script>
</head>
ale Chrome rzuca jsapiFailed to load resource
błąd. Co ja robię źle?
Aktualizacja
Jak na odpowiedź Moishe za I uaktualniony wywołanie JSAPI tak:
<head>
<title>Extension Options</title>
<!-- this does not work because it is local
<script type="text/javascript" src="/_ah/channel/jsapi"></script>
-->
<script type="text/javascript" src="https://talkgadget.google.com/talkgadget/channel.js"></script>
</head>
Aktualizacja
dodałem onopen
i inne właściwości. Teraz otrzymuję alert onopen
, ale nie otrzymuję alertu evt.data
. Co ja robię źle?
<html>
<head>
<title>Extension Options</title>
<!-- this does not work because it is local url
<script type="text/javascript" src="/_ah/channel/jsapi"></script>
-->
<script type="text/javascript" src="https://talkgadget.google.com/talkgadget/channel.js"></script>
</head>
<body>
<p>Enter your gmail address:</p>
<textarea id="getEmail" style="margin-bottom: 4px; width: 250px; height: 20px">
</textarea><br />
<button id="save">Save</button>
<!--<button id="save">Clear</button>-->
<script>
document.getElementById("getEmail").placeholder = "your gmail address" ;
//save entered gmail address
document.getElementById("save").addEventListener
(
"click",
function()
{
var userEmail = document.getElementById("getEmail").value;
var formData = new FormData();
formData.append("extension_user", userEmail);
alert("after formData.append")
var channel;
var socket;
var handler =
{
onopen: function() { alert("onopen") },
onerror: function() { alert("onerror") },
onclose: function() { alert("onclose") },
onmessage:
function (evt)
{
//evt.data will be what the server sends in channel.send_message
console.log("evt.data received from authhandler: " + evt.data);
alert("evt.data is: " + evt.data)
}
};
var xhr = new XMLHttpRequest();
//changed to lowercase
xhr.onreadystatechange = function()
{
//alert("xhr.onReadyStateChange")
//error handling etc not included
if (xhr.readyState == 4 && xhr.status == 200)
{
token = xhr.responseText;
alert("token: " + token)
channel = new goog.appengine.Channel(token);
socket = channel.open(handler);
}
};
xhr.open("POST", "http://ting-1.appspot.com/authsender", true);
xhr.send(formData);
console.log("formData sent to authsender: " + formData);
}, false
)
</script>
</body>
</html>
Czy używasz dev_appserver lub w produkcji? Czy możesz podać szczegółowe informacje na temat karty "Sieć" w narzędziach przeglądarki Chrome? –
To jest w produkcji. Najpierw nic nie było w zakładce "Sieć"; następnie ponownie załadowałem stronę zgodnie z instrukcjami i widzę 2 elementy: options.html i jsapi: name: options.html; Metoda: GET; Status: (z pamięci podręcznej); Wpisz: text/html; Rozmiar: (z pamięci podręcznej); Czas: 3ms i 'jsapi/_ah/channel; GET, (nie powiodło się); niezdefiniowany; 30B; 5ms' Dzięki! – Zeynel
Czy chcesz przekazać mi swój appid? Co się stanie, jeśli spróbujesz przejść bezpośrednio do "http://your-app-id.appspot.com/_ah/channel/jsapi"? –