Answer the question
In order to leave comments, you need to log in
How to send object from background page to google extension?
//манифест
{
"manifest_version": 2,
"name": "Help Panda",
"version": "2.0",
"icons": {
"128": "panda.png"
},
"content_scripts": [
{
"matches": [ "*://*/*" ],
"js": [ "content.js" ]
}
],
"background": {
"scripts": ["background.js"]
},
"browser_action": {
"default_title": "Help Panda",
"default_icon": "panda.png",
"default_popup": "popup.html"
}
}
//content.js
chrome.extension.sendMessage({objChromMes:localNumb});
//popup.js
chrome.runtime.onMessage.addListener(
function(request, sender, sendResponse) {
var a = request.objChromMes; // данные о сайте
// данные о проведенном времени
// тут делаем с этими данными что хотим.
menu.innerHTML =a;
});
<!doctype html>
<html>
<head>
<title>Потерянное время LostTime</title>
<link href="css.css" rel="stylesheet" type="text/css"/>
</head>
<body>
<div id="options"><!-- меню -->
<h3>first app</h3>
</div>
<div id="dannie"></div> <!-- в этот блок буду загружать данные, которые будут показываться пользователю-->
<script src="popup.js"></script><!-- скрипт, выполняющийся при нажатии на иконку расширения-->
</body>
</html>
Answer the question
In order to leave comments, you need to log in
/// content.js
calc=ваш объект или массив,что угодно.
chrome.runtime.sendMessage({greeting:calc});
background.js
chrome.runtime.onMessage.addListener(
function(request, sender, sendResponse) {
localStorage['abbrev'] += request.greeting;
});
poupop.js
chrome.storage.local.get('channels', function (result) {
channels = result.channels;
menu.innerHTML +=channels;
});
How to send object from background page to google extension?
{
"name": "App",
"description": "Desc",
"version": "1.1",
"icons": {
"16": "icon-16.png",
"128": "icon-128.png"
},
"browser_action": {
"default_icon": "icon-16.png",
"default_popup": "popup/popup.html"
},
"background": {
"scripts": [
"js/listener.js"
"js/background.js",
]
},
"externally_connectable": {
"matches": [
"*://*.site.com/*",
]
},
"manifest_version": 2,
"minimum_chrome_version": "35",
"permissions": [
"webNavigation",
"notifications",
"tabs",
]
}
chrome.runtime.onMessageExternal.addListener(function (message, sender, sendResponse) {
console.log(message);
console.log(message.type);
if(message.type == 'checkBrowserAppInstalled'){
sendResponse({
installed: true
})
}
return true;
});
var BROWSERAPPID = 'ID OF APP';
var OBJECT_TO_SEND = {type: "checkBrowserAppInstalled", data : [1,2,3]};
var checkApp = function () {
return new Promise(function (resolve, reject) {
chrome.runtime.sendMessage(BROWSERAPPID, OBJECT_TO_SEND , null, function (response) {
if (response && response.installed === true) {
resolve(response);
} else {
reject({reason: "APP_NOT_FOUND"})
}
});
});
}
checkApp().then(function(){
...
});
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question