Communication from chrome extension to web page
You can use chrome.tabs.executeScript API to do this.
var dataToWebPage = {text: 'test', foo: 1, bar: false}; chrome.tabs.executeScript({ code: '(' + function(params) { //This function will work in webpage console.log(params); //logs in webpage console return {success: true, response: "This is from webpage."}; } + ')(' + JSON.stringify(dataToWebPage) + ');' }, function(results) { //This is the callback response from webpage console.log(results[0]); //logs in extension console });
Please note that it needs tabs permission.