Skip to content

Crawlee—A web scraping and browser automation library for Node.js to build reliable crawlers. In JavaScript and TypeScript. Extract data for AI, LLMs, RAG, or GPTs. Download HTML, PDF, JPG, PNG, and other files from websites. Works with Puppeteer, Playwright, Cheerio, JSDOM, and raw HTTP. Both headful and headless mode. With proxy rotation.

rename quality => screenshotQuality

metalwarrior6653d4bfbada33a
diff --git a/src/puppeteer_utils.js b/src/puppeteer_utils.js
index 05cf4e977..68b1c5cba 100644
--- a/src/puppeteer_utils.js
+++ b/src/puppeteer_utils.js
@@ -519,13 +519,13 @@ export const infiniteScroll = async (page, options = {}) => {
* @param {Object} [options]
* @param {String} [options.key=SNAPSHOT]
* Key under which the screenshot and HTML will be saved. `.jpg` will be appended for screenshot and `.html` for HTML.
- * @param {Number} [options.quality=50]
+ * @param {Number} [options.screenshotQuality=50]
* The quality of the image, between 0-100. Higher quality images have bigger size and require more storage.
* @param {Boolean} [options.saveScreenshot=true]
* If true, it will save a full screenshot of the current page as a record with `key` appended by `.jpg`.
* @param {Boolean} [options.saveHtml=true]
* If true, it will save a full HTML of the current page as a record with `key` appended by `.html`.
- * @param {String} [options.storeName=null]
+ * @param {String} [options.keyValueStoreName=null]
* Name or id of the Key-Value store where snapshot is saved. By default it is saved to default Key-Value store.
* @returns {Promise}
* @memberOf puppeteer
@@ -538,19 +538,19 @@ const saveSnapshot = async (page, options = {}) => {
checkParamOrThrow(page, 'page', 'Object');
checkParamOrThrow(options, 'options', 'Object');
- const { saveScreenshot = true, saveHtml = true, keyValueStoreName = null, quality = 50 } = options;
+ const { saveScreenshot = true, saveHtml = true, keyValueStoreName = null, screenshotQuality = 50 } = options;
key = options.key || DEFAULT_KEY;
checkParamOrThrow(saveScreenshot, 'saveScreenshot', 'Boolean');
checkParamOrThrow(saveHtml, 'saveHtml', 'Boolean');
checkParamOrThrow(key, 'key', 'String');
checkParamOrThrow(keyValueStoreName, 'keyValueStoreName', 'Maybe String');
- checkParamOrThrow(quality, 'quality', 'Number');
+ checkParamOrThrow(screenshotQuality, 'screenshotQuality', 'Number');
const store = await openKeyValueStore(keyValueStoreName);
if (saveScreenshot) {
- const screenshotBuffer = await page.screenshot({ fullPage: true, quality, type: 'jpeg' });
+ const screenshotBuffer = await page.screenshot({ fullPage: true, screenshotQuality, type: 'jpeg' });
await store.setValue(`${key}.jpg`, screenshotBuffer, { contentType: 'image/jpeg' });
}
if (saveHtml) {
diff --git a/test/puppeteer_utils.js b/test/puppeteer_utils.js
index 61a768719..e361e4cb5 100644
--- a/test/puppeteer_utils.js
+++ b/test/puppeteer_utils.js
@@ -385,7 +385,7 @@ describe('Apify.utils.puppeteer', () => {
const contentHTML = '<html><head></head><body><div style="border: 1px solid black">Div number: 1</div></body></html>';
await page.setContent(contentHTML);
- const screenshot = await page.screenshot({ fullPage: true, type: 'jpeg', quality: 60 });
+ const screenshot = await page.screenshot({ fullPage: true, type: 'jpeg', screenshotQuality: 60 });
// Test saving both image and html
const object = { setValue: async () => {} };
@@ -396,7 +396,7 @@ describe('Apify.utils.puppeteer', () => {
.withExactArgs('TEST-STORE')
.resolves(object);
- await Apify.utils.puppeteer.saveSnapshot(page, { key: 'TEST', keyValueStoreName: 'TEST-STORE', quality: 60 });
+ await Apify.utils.puppeteer.saveSnapshot(page, { key: 'TEST', keyValueStoreName: 'TEST-STORE', screenshotQuality: 60 });
expect(stub.calledWithExactly('TEST.jpg', screenshot, { contentType: 'image/jpeg' })).to.be.eql(true);
expect(stub.calledWithExactly('TEST.html', contentHTML, { contentType: 'text/html' })).to.be.eql(true);
@@ -411,7 +411,7 @@ describe('Apify.utils.puppeteer', () => {
await Apify.utils.puppeteer.saveSnapshot(page, { saveHtml: false });
// Default quality is 50
- const screenshot2 = await page.screenshot({ fullPage: true, type: 'jpeg', quality: 50 });
+ const screenshot2 = await page.screenshot({ fullPage: true, type: 'jpeg', screenshotQuality: 50 });
expect(stub2.calledOnceWithExactly('SNAPSHOT.jpg', screenshot2, { contentType: 'image/jpeg' })).to.be.eql(true);
mock.verify();