1 // Copyright (c) 2013 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 function takeScreenshot(onScreenshot) { 6 console.log('Taking screenshot.'); 7 chrome.tabs.captureVisibleTab(null, {format: 'png'}, function(img) { 8 console.log('Got screenshot, returning...'); 9 onScreenshot(img); 10 }); 11 } 12 13 chrome.tabs.onUpdated.addListener(function(tabId, changeInfo, tab) { 14 if (changeInfo.status != 'complete') 15 return; 16 17 chrome.tabs.executeScript(tabId, 18 {file: 'injected.js', runAt: 'document_start'}); 19 }); 20 21 chrome.runtime.onMessage.addListener( 22 function(request, sender, sendResponse) { 23 takeScreenshot(sendResponse); 24 25 // Keep the sendResponse channel open, so a response can be sent 26 // asynchronously. 27 return true; 28 }); 29