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.

Add auto-connect to live view client

Ondra Urban6a1b4b530cb4
diff --git a/src/live_view/index.html b/src/live_view/index.html
index c8071227f..9ce08e222 100644
--- a/src/live_view/index.html
+++ b/src/live_view/index.html
@@ -132,8 +132,15 @@
socket.on('connect', () => {
console.log('Client ID: ' + socket.id);
// Don't wait for the next screenshot to be made.
+ $('#resumeButton').hide();
+ $('#pauseButton').show();
showSnapshot(window.lastSnapshot);
});
+ socket.on('disconnect', () => {
+ if (liveViewSocket) liveViewSocket = null;
+ $('#resumeButton').show();
+ $('#pauseButton').hide();
+ });
return socket;
}
@@ -148,11 +155,22 @@
}
}
+ function isThisTopWindow () {
+ try {
+ return window.self === window.top;
+ } catch (e) {
+ return false;
+ }
+ }
+
window.addEventListener('message', onMessageFromPlatform);
$(() => {
// Show initial snapshot if it exists when client is fetched.
showSnapshot(window.lastSnapshot);
+ // When displayed in a separate window, connect immediately.
+ if (isThisTopWindow()) liveViewSocket = connect();
+
$('#resumeButton').click((event) => {
event.preventDefault();
if (!liveViewSocket) {