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.

Added defaultViewport option to Apify.launchPuppeteer()

Jan Curn3cc27989aa4a
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 353ba8381..1a8e0a699 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -1,3 +1,8 @@
+xxx
+==================
+- `Apify.launchPuppeteer()` now sets the `defaultViewport` option if not provided by user,
+ to improve screenshots and debugging experience.
+
0.9.4 / 2018-11-19
==================
- Automatically adding `--enable-resource-load-scheduler=false`
diff --git a/src/puppeteer.js b/src/puppeteer.js
index e0c1631ce..d438c00fd 100644
--- a/src/puppeteer.js
+++ b/src/puppeteer.js
@@ -15,6 +15,11 @@ const LAUNCH_PUPPETEER_LOG_OMIT_OPTS = [
'proxyUrl', 'userAgent', 'useApifyProxy', 'apifyProxySession', 'apifyProxyGroups',
];
+const LAUNCH_PUPPETEER_DEFAULT_VIEWPORT = {
+ width: 1200,
+ height: 900,
+};
+
/**
* Represents options passed to the
* [`Apify.launchPuppeteer()`](../api/apify#module_Apify.launchPuppeteer)
@@ -160,6 +165,10 @@ const getPuppeteerOrThrow = () => {
* Also it adds <code>--enable-resource-load-scheduler=false</code>
* to make crawling of pages in all tabs run equally fast.
* </li>
+ * <li>
+ * Sets <code>defaultViewport</code> Puppeteer option (if not already set)
+ * to a more reasonable default for screenshots and debugging.
+ * </li>
* </ul>
*
* To use this function, you need to have the <a href="https://www.npmjs.com/package/puppeteer" target="_blank">puppeteer</a>
@@ -213,6 +222,9 @@ export const launchPuppeteer = (options = {}) => {
sessionParamName: 'options.apifyProxySession',
});
}
+ if (!optsCopy.defaultViewport) {
+ optsCopy.defaultViewport = LAUNCH_PUPPETEER_DEFAULT_VIEWPORT;
+ }
// When User-Agent is not set and we're using Chromium or headless mode,
// it is better to use DEFAULT_USER_AGENT to reduce chance of detection