0

console.log

background.js

I have no idea why

console.log(otherBrowsingHistoryList[0])

is returning as undefined in console.log command

background.js

otherBrowsingHistoryList = []

const millisecondsPerWeek = 1000 * 60 * 60 *24 * 7; 
const oneWeekAgo = (new Date).getTime() - millisecondsPerWeek;

//the current code that works best
chrome.runtime.onMessage.addListener(function (request, sender, sendResponse) {
  if (request.data == "getStatus") {
      console.log(request.data)
      sendResponse({ data: "validation" })

      chrome.history.search({
        text: '',
        startTime: oneWeekAgo,
        maxResults: 30
        },  
    
        function(data) {
            data.forEach(function(page) {
                // browsingHistoryList.push(page.lastVisitTime);
                // var timeInMilliseconds = page.lastVisitTime;
                // let newDate = new Date(timeInMilliseconds);
                // browsingHistoryList.push(newDate);
                otherBrowsingHistoryList.push(page.url)
                chrome.runtime.sendMessage(
                    page.url, function(response) {
                            // console.log(response.data);
                            // console.log(page.url);
                    }
                );
        });
    });      
  }
});

console.log(otherBrowsingHistoryList)
console.log(otherBrowsingHistoryList[0])



randomList = [4,5,6,12]
console.log(randomList)
console.log(randomList[0])

popup.js (for more reference)

browsingHistoryList = [];

//code example from stackoverflow with the "handshake" idea
chrome.runtime.sendMessage({data: "getStatus" }, function(response) {
  console.log(response.data);

return true;
});

//listen to the onMessage request and push to the browsing history list
chrome.runtime.onMessage.addListener(function(message,sender,sendResponse){
    // str = JSON.stringify(message.data);
    sendResponse({data: "request recieved"});
    // browsingHistoryList.append(message.data);
    // console.log(message.data);
    browsingHistoryList.push(message);
}); 

console.log(browsingHistoryList);
nokiafan
  • 1
  • 1

0 Answers0