1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 2 // Use of this source code is governed by a BSD-style license that can be 3 // found in the LICENSE file. 4 5 document.body.innerHTML = ""; 6 7 function addButton(name, cb) { 8 var a = document.createElement("button"); 9 a.innerText = name; 10 a.onclick = cb; 11 document.body.appendChild(document.createElement("br")); 12 document.body.appendChild(a); 13 } 14 15 function log(str) { 16 console.log(str); 17 logDiv.innerHTML += str + "<br>"; 18 } 19 20 addButton("Clear logs", function() { 21 logDiv.innerHTML = ""; 22 }); 23 24 addButton("Send message with delayed response", function() { 25 chrome.runtime.sendMessage({delayedResponse: true}, function(response) { 26 log("Background page responded: " + response); 27 }); 28 }); 29 30 addButton("Show counters", function() { 31 chrome.runtime.sendMessage({getCounters: true}, function(response) { 32 log("In-memory counter is: " + response.counter); 33 log("Persisted counter is: " + response.persistentCounter); 34 }); 35 }); 36 37 addButton("Set an alarm", function() { 38 chrome.runtime.sendMessage({setAlarm: true}); 39 }); 40 41 chrome.runtime.onMessage.addListener(function(msg, _, sendResponse) { 42 log("Got message from background page: " + msg); 43 }); 44 45 var logDiv = document.createElement("div"); 46 logDiv.style.border = "1px dashed black"; 47 document.body.appendChild(document.createElement("br")); 48 document.body.appendChild(logDiv); 49 50 log("Ready."); 51