Skip to content
This repository has been archived by the owner on Aug 26, 2019. It is now read-only.

Commit

Permalink
Fix for captureArea. Added public key.
Browse files Browse the repository at this point in the history
  • Loading branch information
williamparry committed Feb 5, 2018
1 parent 9929972 commit f547e37
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 23 deletions.
57 changes: 35 additions & 22 deletions src/js/background.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,38 +22,51 @@ chrome.browserAction.onClicked.addListener(function (tab) {
});
});

function captureAreaDelegate(evtD, tabId, tabURL) {

requestMessenger.addEventListener("got_area", function (e) {

if(e.Sender.tab.id === tabId && e.Sender.tab.url === tabURL) {

requestMessenger.removeEventListener("got_area", arguments.callee);

setTimeout(function() {

chrome.tabs.captureVisibleTab(null, { format: "png" }, function (img) {

var canvas = document.createElement('canvas');
canvas.width = e.Data.width;
canvas.height = e.Data.height;
var ctx = canvas.getContext('2d');
var i = new Image();
i.src = img;
i.onload = function () {
ctx.drawImage(i, e.Data.left, e.Data.top, e.Data.width, e.Data.height, 0, 0, e.Data.width, e.Data.height);
evtD.dispatchEvent(evtD.EVENT_SUCCESS, canvas.toDataURL("image/png"));
};
});

}, 50);

}

}, true);

}

function handleCapture() {

var evtD = new UTILS.EventDispatcher(['EVENT_SUCCESS', 'EVENT_ERROR']);

chrome.tabs.query({
active: true,
currentWindow: true
}, function (tab) {

}, function (tabs) {
var tab = tabs[0]
chrome.tabs.executeScript(tab.id, { file: "js/inject/captureArea.js" }, function (info) {

if (typeof info !== "undefined") {

chrome.tabs.captureVisibleTab(null, { format: "png" }, function (img) {

requestMessenger.addEventListener("got_area", function (e) {
requestMessenger.removeEventListener("got_area", arguments.callee);
var canvas = document.createElement('canvas');
canvas.width = e.Data.width;
canvas.height = e.Data.height;
var ctx = canvas.getContext('2d');
var i = new Image();
i.src = img;
i.onload = function () {
ctx.drawImage(i, e.Data.left, e.Data.top, e.Data.width, e.Data.height, 0, 0, e.Data.width, e.Data.height);
evtD.dispatchEvent(evtD.EVENT_SUCCESS, canvas.toDataURL("image/png"));
};
}, true);

});


captureAreaDelegate(evtD, tab.id, tab.url);
} else {
evtD.dispatchEvent(evtD.EVENT_ERROR, "Access to the page is denied");
}
Expand Down
2 changes: 1 addition & 1 deletion src/manifest/chrome.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"version": "2.1.3",
"minimum_chrome_version": "22",
"key": "bclgcbonbpjpojckfhhlbhdlihecjico",
"key": "MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQDM6D3wZNAfHGpc9/Hk7sPNSCnauK/sQPhAPViDmjT8Sj+Ot7ugDafYSynzhIFPZyckXm+4TkmlcqQukCI8GP+yqcb70oWVus8GplHTimJkoDKLwJkLH55lhBjg5Z8Aa7BngFf0W/C7ZASElFNfQqWQJI3bgK6vHX5cRgJrhZ9AoQIDAQAB",
"background": {
"scripts": [
"lib/utils-1.4.js",
Expand Down

0 comments on commit f547e37

Please sign in to comment.