This is a follow up to my previous question.
I am working on a Chrome extension http://ting-1.appspot.com/ that saves the bookmarked page to Google App Engine backend. Looking at the Chrome web store I see that extensions have an "add to chrome" button. Since my extension requires communication with the backend (so the user must have a gmail account to use this extension) how do I indicate in the extension to use the username (the gmail address of the person who added the extension to Chrome) to write the bookmark to google app engine with his user id? I have a gap in my understanding and I don't seem to find anything related to this question in the documentation. My background.html
is below. Thanks.
background.html
<html>
<script>
chrome.browserAction.onClicked.addListener(function(tab) {
chrome.tabs.getSelected(null, function(tab) {
// Send a request to the content script.
chrome.tabs.sendRequest(tab.id, {action: "getDOM"}, function(response) {
var firstParagraph = response.dom;
console.log("background -- before *console.log(response.dom)*")
console.log("this is *console.log(response.dom)*: " + response.dom)
console.log("background -- after *console.log(response.dom)*")
//}); moved to end to get the variable firstParagraph
var formData = new FormData();
formData.append("url", tab.url);
formData.append("title", tab.title);
formData.append("pitch", firstParagraph);
var xhr = new XMLHttpRequest();
xhr.open("POST", "http://ting-1.appspot.com/submithandlertest", true);
xhr.onreadystatechange = function (aEvt) {
if (xhr.readyState == 4) {
if (xhr.status == 200){
console.log("request 200-OK");
chrome.browserAction.setBadgeText ( { text: "done" } );
setTimeout(function () {
chrome.browserAction.setBadgeText( { text: "" } );
}, 2000);
}else{
console.log("connection error");
chrome.browserAction.setBadgeText ( { text: "ERR" } );
}
}
};
xhr.send(formData);
}); //chrome.tabs.sendRequest
});
});
</script>
</html>
Your extension needs to send the user to your app to sign in, so that the appropriate cookies will be set and your extension can authenticate as the user. The Chrome to Phone extension does this, and you can examine its source to see how.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With