0

I have an issue in passing content from my background.html file to my popup.html one. Here's what I'm doing on background.js:

var pollInterval = 15000 * 60; // 15 minutes, in milliseconds
function getBandi() {
    $.get('http://www.comune.cormons.go.it/index.php?id=6367&no_cache=1', function (data) {
        var $data = $(data);
        var $bandi = $data.find('.news-latest-container .news-latest-item').has('h3:contains("Bando")');
        var itemsArray = [];

        $bandi.each(function () {
            itemsArray.push($(this).html());
        });
        chrome.runtime.sendMessage({messaggi: itemsArray}, function(response) {
          console.log(response);
        });
    });
}

function initRequest() {
    getBandi();
    window.setTimeout(initRequest, pollInterval)
}

$(document).ready(function () {
    initRequest();
});

here's my popup html file

<!doctype html>
<style type="text/css">
    #mainPopup {
        padding: 10px;
        height: 200px;
        width: 400px;
        font-family: Helvetica, Ubuntu, Arial, sans-serif;
    }
    h1 {
        font-size: 2em;
    }
</style>
<script type="text/javascript" src="../../js/jquery/jquery.min.js"></script>
<script type="text/javascript" src="browser_action.js"></script>
<div id="mainPopup">
<h1>Bandi Disponibili a Cormons</h1>
<ul id="messaggi"></ul>
</div>

Here's my javascript for the popup:

$(document).ready(function () {
    chrome.runtime.onMessage.addListener(
  function(request, sender, sendResponse) {
    console.log('sono qui?')
    var $container = $('#messaggi');
    var $array = request.messaggi;
    $array.each(function () {
        $container.append("<li/>").html($(this).html());
    });
    sendResponse({test: true});
  });
});

It is obvious by now that I'm definitely screwing something on the usage of chrome.runtime messages. But I can't figure what exactly (it is my first and probably last chrome extension).

  • Try to check this [SO question](http://stackoverflow.com/questions/17226770/chrome-extension-pass-data-from-content-to-background), I think it can help you. – KENdi Mar 31 '16 at 06:15
  • The question you linked talks about a message which has to be sent on tan opening. I need it to be always be sent in a polling fashion. – Daniele Cencig Mar 31 '16 at 06:20

0 Answers0