How to save user email as a variable when someone installs an extension?

In my bookmark extension, I need to send the user's gmail address to the Google engine in order to write the bookmark to the database as the user as the "owner".

I understand that I cannot use the popup because I have a help page (I remember reading about it, but I could not find it again). I also read the installation process in the Chrome store. I would appreciate it if anyone could direct me to the right place in the documentation.

I will copy background.html below with the extension_user variable enabled. How to get this variable from the user when loading the extension? This is my previous question .

 <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; var formData = new FormData(); formData.append("url", tab.url); formData.append("title", tab.title); formData.append("pitch", firstParagraph); //***the variable with user email to send to backend:***// //formData.append("extension_user", extension_user) 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> 
0
source share
1 answer

You can use both popup and background page in one extension. Many of my extensions use both ... Use background page to link and save data for your popup page ...

You can ask your user to save his email address when installing on your background page as follows:

 <script type="text/javascript"> addEventListener('load', function(){ var MAJOR_VERSION=1.0; if(!localStorage.updateread||localStorage.updateread!=MAJOR_VERSION) { var email=prompt("Enter the Email Address : ") localStorage["Email"] = Email; localStorage.updateread=MAJOR_VERSION } }, 0); </script> 

This script will only be run the first time the extension is installed. And the users email address will be stored in the LocalStorage extensions until they are deleted ... Calling this variable will now work on both your background page and your popup page ...

+2
source

Source: https://habr.com/ru/post/899659/


All Articles