Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -167,8 +167,8 @@ the callback in a call to webshot.
<th>siteType</th>
<td>'url'</td>
<td>siteType indicates whether the content needs to be requested ('url'),
loaded locally ('file'), or is being provided directly as a string
('html').</td>
loaded locally ('file'), or is being provided directly as a string or
buffer, see htmlEncoding option ('html').</td>
</tr>
<tr>
<th>renderDelay</th>
Expand Down Expand Up @@ -203,6 +203,11 @@ the callback in a call to webshot.
<td>false</td>
<td>Captures the page area containing the provided selector and saves it to file.</td>
</tr>
<tr>
<th>htmlEncoding</th>
<td>utf-8</td>
<td>If passing HTML the encoding to be used. If none, the html is parsed as a buffer.</td>
</tr>
</tbody>
</table>

Expand Down
1 change: 1 addition & 0 deletions lib/options.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ exports.phantom = {
, cookies: []
, captureSelector: false
, zoomFactor: 1
, htmlEncoding: 'utf-8'
};

// Options that are just passed to the phantom page object
Expand Down
5 changes: 4 additions & 1 deletion lib/webshot.js
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,10 @@ module.exports = function() {
if (options.siteType === 'html') {
var obj = tmp.fileSync();
var tmpPath = obj.name;
fs.writeSync(obj.fd, site, null, 'utf-8');
if (options.htmlEncoding)
fs.writeSync(obj.fd, site, null, options.htmlEncoding);
else
fs.writeSync(obj.fd, site);
fs.close(obj.fd);
options.siteType = 'file';
site = tmpPath;
Expand Down
13 changes: 13 additions & 0 deletions test/options/siteType.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,19 @@ var webshot = require('../../lib/webshot')
describe('siteType', function() {
this.timeout(20000);

it('takes a screenshot of the provided buffer', function(done) {
webshot(new Buffer('<html><body>This is a test</body></html>'),
pngOutput,
{siteType: 'html', htmlEncoding: null},
function(err) {
if (err) return done(err);
fs.exists(pngOutput, function(exists) {
exists.should.equal(true);
done();
});
});
});

it('takes a screenshot of the provided html', function(done) {
webshot('<html><body>This is a test</body></html>',
pngOutput,
Expand Down