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.
TypeScript apifyautomationcrawlercrawlingheadlessheadless-chromejavascriptnodejsnpmplaywrightpuppeteerscraperscrapingtypescriptweb-crawlerweb-crawlingweb-scraping
Better logging of live view URLs and ports
Jan Curn6c2eb2de3c31
diff --git a/src/puppeteer_live_view_server.js b/src/puppeteer_live_view_server.jsindex 4bc7df428..f557525f9 100644--- a/src/puppeteer_live_view_server.js+++ b/src/puppeteer_live_view_server.js@@ -2,7 +2,6 @@ import http from 'http';import EventEmitter from 'events';import Promise from 'bluebird';import WebSocket from 'ws';-import _ from 'underscore';import log from 'apify-shared/log';import { promisifyServerListen } from 'apify-shared/utilities';import { checkParamOrThrow } from 'apify-client/build/utils';@@ -278,23 +277,22 @@ const sendCommand = (socket, command, data) => {* Enables live monitoring of actor execution by spawning a web server that responds with a list* of available browsers at its root path. Once the user chooses a browser, PuppeteerLiveViewServer will* periodically serve screenshots of the selected browser's latest loaded page.+ *+ * The server is started on a port defined by the `CONTAINER_PORT` environment variable.* @ignore*/export default class PuppeteerLiveViewServer extends EventEmitter {constructor() {super();- this.containerUrl = process.env[ENV_VARS.CONTAINER_URL] || 'http://localhost';- this.containerPort = parseInt(process.env[ENV_VARS.CONTAINER_PORT], 10) || 0;-- if (!this.containerUrl) {- throw new Error(`Cannot start LiveViewServer - the environment variable ${ENV_VARS.CONTAINER_URL} is not set!-If you are running on localhost then set ${ENV_VARS.CONTAINER_URL}='http://localhost'`);+ const containerPort = process.env[ENV_VARS.CONTAINER_PORT];+ this.liveViewPort = parseInt(containerPort, 10) || 0;+ if (!(this.liveViewPort >= 0 && this.liveViewPort <= 65535)) {+ throw new Error(`Cannot start LiveViewServer - invalid port specified by the ${+ ENV_VARS.CONTAINER_PORT} environment variable (was "${containerPort}").`);}- if (!_.isNumber(this.containerPort)) {- throw new Error(`Cannot start LiveViewServer - the environment variable ${ENV_VARS.CONTAINER_PORT} is not set!`);- }+ this.liveViewUrl = process.env[ENV_VARS.CONTAINER_URL] || `http://localhost:${this.liveViewPort}`;this.browsers = new Set();this.browserIdCounter = 0;@@ -335,9 +333,9 @@ If you are running on localhost then set ${ENV_VARS.CONTAINER_URL}='http://localwss.on('connection', this._wsRequestListener.bind(this));- return promisifyServerListen(server)(this.containerPort)+ return promisifyServerListen(server)(this.liveViewPort).then(() => {- log.info(`Live view server is now available at URL ${this.containerUrl} (running on port ${server.address().port}).`);+ log.info(`Live view is now available at ${this.liveViewUrl}`);this.httpServer = server;});}@@ -352,7 +350,7 @@ If you are running on localhost then set ${ENV_VARS.CONTAINER_URL}='http://local* @ignore*/_httpRequestListener(req, res) {- const body = layout(this.containerUrl);+ const body = layout(this.liveViewUrl);res.writeHead(200, {'Content-Type': 'text/html','Content-Length': Buffer.byteLength(body),