0

I have an app that's pulling data from Google Sheets with background.js but I am unable to use that information in the popup.js itself. I am not too familiar with Chrome Apps, what can I do in this case? How do I get Chrome Identity or the API to pass the information to popup.js? I can't implement the API call in popup.js because I need it to work in the background.

So I want to modify a sheet with the Google Sheets API and then read off it.

I am basically doing this in the background.js:

chrome.identity.getAuthToken({ 'interactive': true }, function(token) {
    var response;
    var requestURL = "https://sheets.googleapis.com/v4/spreadsheets/" + spreadsheetId + "/values/" + range;
    var objectHTTP;
    objectHTTP = new XMLHttpRequest();
    objectHTTP.onreadystatechange = function() {

    if (objectHTTP.readyState == 4 && objectHTTP.status == 200) {
            response = objectHTTP.responseText;
        }
    };

    objectHTTP.open("GET", requestURL, false);
    objectHTTP.setRequestHeader('Authorization', 'Bearer ' + token);
    objectHTTP.send();

    // This is the part where I obtain the response, but how do I use it in the main app (popup.js)? Can I somehow share the variables?
    });
Mensan
  • 5
  • 2
  • You should use [Message Passing](https://developer.chrome.com/extensions/messaging), communication between extensions and their content scripts works by using message passing. You cal also check this two related SO post [1](https://stackoverflow.com/a/33317925/5995040) and [2](https://stackoverflow.com/a/43485784/5995040), to see if this will fit on what you want to achieve. – Mr.Rebot Mar 24 '18 at 10:51

1 Answers1

0

You can use the background.js to update another sheet and then use your popup.js to read from it. This way the second sheets acts as data storage.