diff --git a/README.md b/README.md
index aae26a6..ad873db 100644
--- a/README.md
+++ b/README.md
@@ -335,6 +335,9 @@ Few rules:
cookies
Configure cookies that will be contained in request. HTTP message body is the easiest way for sending cookies to Manet (ex: using JSON format).
+ captureOnCallback
+ Allow the page to tell Manet when it's ready for capture. This uses page.onCallback under the hood. (default is `false`)
+
diff --git a/public/js/app.js b/public/js/app.js
index 64ba99f..6c1eef8 100644
--- a/public/js/app.js
+++ b/public/js/app.js
@@ -9,12 +9,14 @@
'user', 'password',
'callback', 'headers', 'clipRect',
'force', 'selector',
- 'engine'
+ 'engine',
+ 'captureOnCallback'
];
function cleanBoolValue(name, value) {
return ((value && (name === 'js' || name === 'images')) ||
- (!value && name === 'force')) ? null : value;
+ (!value && name === 'force') ||
+ (!value && name === 'captureOnCallback')) ? null : value;
}
function readOptions() {
diff --git a/public/usage.html b/public/usage.html
index d23357e..e5bd443 100644
--- a/public/usage.html
+++ b/public/usage.html
@@ -84,6 +84,11 @@ Website screenshot service
+
+
+
+
+
diff --git a/src/options.js b/src/options.js
index 65f317a..0e5c657 100644
--- a/src/options.js
+++ b/src/options.js
@@ -41,7 +41,8 @@ function createSchema() {
secure: joi.boolean(),
expires: joi.string()
})
- )
+ ),
+ captureOnCallback: joi.boolean()
});
}
diff --git a/src/scripts/screenshot.js b/src/scripts/screenshot.js
index 91241c6..14bdb6c 100644
--- a/src/scripts/screenshot.js
+++ b/src/scripts/screenshot.js
@@ -221,16 +221,33 @@
try {
var page = createPage(options, captureScreenshot);
+ var addStylesAndRender = function() {
+ try {
+ addStyles(page, DEF_STYLES);
+ renderScreenshotFile(page, options);
+ } catch (e) {
+ exit(page, e);
+ }
+ };
+
+ if (options.captureOnCallback === true) {
+ page.onCallback = function(data) {
+ log('CALLBACK: '+ JSON.stringify(data));
+ addStylesAndRender();
+ };
+ }
+
page.open(options.url, function (status) {
- var onPageReady = function() {
- try {
- addStyles(page, DEF_STYLES);
- renderScreenshotFile(page, options);
- } catch (e) {
- exit(page, e);
- }
- },
- checkDomElementAvailable = function() {
+
+ if (status !== 'success') {
+ exit();
+ }
+
+ if (options.captureOnCallback === true) {
+ return;
+ }
+
+ var checkDomElementAvailable = function() {
if (options.selector) {
var interval = setInterval(function () {
var element = page.evaluate(function (selector) {
@@ -238,12 +255,12 @@
}, options.selector);
if (element !== null && typeof element === 'object') {
- onPageReady();
+ addStylesAndRender();
clearInterval(interval);
}
}, 250);
} else {
- onPageReady();
+ addStylesAndRender();
}
},
checkReadyState = function() {