I am the creator of an addon called BeautifyTumblr that changes the look of Tumblr. I want the Chrome extension to automatically detect when it is updated and display the change log to the user. I use the event page with the chrome.runtime.onInstalled.addListener hook to determine when the update occurred, get the change log from the text file in the extension .. it all works fine, and then when I want to redirect it to my script content via chrome .tabs.sendmessage it just doesn't work, nothing happens, no errors, nothing. I'm at a dead end.
Any help would be greatly appreciated!
Event Page:
chrome.runtime.onInstalled.addListener(function (details) { "use strict"; if (details.reason === "install") { } else if (details.reason === "update") { var thisVersion = chrome.runtime.getManifest().version, xmlDom, xmlhttp; xmlDom = null; xmlhttp = new XMLHttpRequest(); xmlhttp.open("GET", chrome.extension.getURL("changelog.txt"), false); xmlhttp.send(null); xmlDom = xmlhttp.responseText; chrome.tabs.query({'url' : 'http://www.tumblr.com/*'}, function (tabs) { if (tabs.length > 0) { var mTab = tabs[0].id; chrome.tabs.update(mTab, {active: true}); setTimeout(chrome.tabs.sendMessage(mTab, {beautifyTumblrUpdate: xmlDom}), 500); } else { chrome.tabs.create({'url' : 'http://www.tumblr.com/dashboard'}, function (tab) { setTimeout(chrome.tabs.sendMessage(tab.id, {beautifyTumblrUpdate: xmlDom}), 500); }); } }); } });
Relevant code in Script content:
chrome.runtime.onMessage.addListener( function (request, sender, sendResponse) { "use strict"; window.alert('test'); if (request.beautifyTumblrUpdate) { window.alert(request.beautifyTumblrUpdate); } else if (request.beautifyTumblrInstall) { window.alert(request.beautifyTumblrInstall); } } );
source share