Index: native_client_sdk/src/build_tools/screenshot_extension/background.js |
diff --git a/native_client_sdk/src/build_tools/screenshot_extension/background.js b/native_client_sdk/src/build_tools/screenshot_extension/background.js |
new file mode 100644 |
index 0000000000000000000000000000000000000000..f1e1808edc9611a1298b09abacae266b4f5a48d2 |
--- /dev/null |
+++ b/native_client_sdk/src/build_tools/screenshot_extension/background.js |
@@ -0,0 +1,28 @@ |
+// Copyright (c) 2013 The Chromium Authors. All rights reserved. |
+// Use of this source code is governed by a BSD-style license that can be |
+// found in the LICENSE file. |
+ |
+function takeScreenshot(onScreenshot) { |
+ console.log('Taking screenshot.'); |
+ chrome.tabs.captureVisibleTab(null, {format: 'png'}, function(img) { |
+ console.log('Got screenshot, returning...'); |
+ onScreenshot(img); |
+ }); |
+} |
+ |
+chrome.tabs.onUpdated.addListener(function(tabId, changeInfo, tab) { |
+ if (changeInfo.status != 'complete') |
+ return; |
+ |
+ chrome.tabs.executeScript(tabId, |
+ {file: 'injected.js', runAt: 'document_start'}); |
+}); |
+ |
+chrome.runtime.onMessage.addListener( |
+ function(request, sender, sendResponse) { |
+ takeScreenshot(sendResponse); |
+ |
+ // Keep the sendResponse channel open, so a response can be sent |
+ // asynchronously. |
+ return true; |
+ }); |