Oh well instead of having the function return a value to be used by a DOM element, why not send the DOM elements that will need the value, as arguments of the function.
and the function may be like
// script.js //
arr = ['x','y','z', element];
var x,y,z, element=document.getElementById('hi');
chrome.extension.sendRequest( 'keys':arr, doStuff);
function doStuff(values, element) {
//do something with values and element id 'hi'
}
// background.html //
chrome.extension.onRequest.addListener(function (request,sender,response) {
if(request.keys) {
var ret = [];
for(var i=0; i<request.keys.length-1; i++)
ret.push(localStorage.getItem(request.keys[i]));
response(ret, request.keys[request.keys.length-1]);
}
else
response();
}
I'm not sure if what I did is the best way to solve my issue, but it at least works for me xD, mine looks a bit different but what I just wrote is basically it.
Where I live there is a phrase that would be translated to English as:
"If Mahoma doesn't go to the mountain, the mountain goes to Mahoma"
I guess thats how I will explain it.