Skip to content

Instantly share code, notes, and snippets.

@JJetmar
JJetmar / crawler.js
Created March 25, 2025 16:27
Investigating memory leaks in Crawlee
import { getMemoryInfo } from 'crawlee';
setInterval(async () => {
const mem = await getMemoryInfo();
for (const [key, value] of Object.entries(mem)) {
// @ts-ignore
mem[key] = Math.round(value / 1024 / 1024); // in MB
}
console.log(mem);
@JJetmar
JJetmar / Dockerfile
Last active January 22, 2025 09:13 — forked from jancurn/Dockerfile
Example of an Apify actor stored in a GitHub Gist.
# Here you choose the base Docker image for the actor. Apify provides the following images:
# apify/actor-node-basic
# apify/actor-node-chrome
# apify/actor-node-puppeteer
# However, you can use any other image from Docker Hub.
# For more information, see https://apify.com/docs/actor#base-images
FROM apify/actor-node:20
# Copy all files and directories from the directory to the Docker image
COPY . ./
systemctl --user disable --now wireplumber
@JJetmar
JJetmar / main.ts
Last active October 23, 2023 09:27
Blocks extra unnecessary requests in PupeteerCrawler / Apify SDK
// ...
const crawler = new PuppeteerCrawler({
// ...
preNavigationHooks: [
/*
// Only waits for the initial HTML page and not related assets like, images, etc (also optimization)
async (gotoOptions) => {
if (!gotoOptions) return;
gotoOptions.waitUntil = 'domcontentloaded';
},
@JJetmar
JJetmar / apify-custom-logger.ts
Created September 19, 2023 07:45
Apify Logger customization
import { Actor, log, LoggerText } from 'apify';
import type { LogLevel } from '@apify/log/log_consts';
class MyLogger extends LoggerText {
override log(level: LogLevel, message: string, data?: any, exception?: any) {
super.log(level, message, data, exception);
// Own log + send data to dataDog or whatever
console.log(`My own log `, level, message, data, exception);
}
}
@JJetmar
JJetmar / main.js
Created June 15, 2023 09:10
Aborting Apify acot
import { Actor } from 'apify';
import { CheerioCrawler } from 'crawlee';
import { router } from './routes.js';
await Actor.init();
const startUrls = ['https://apify.com'];
const proxyConfiguration = await Actor.createProxyConfiguration();
@JJetmar
JJetmar / build.sh
Last active June 5, 2023 08:44
Build Docker image for Apify actor locally
# Multirepo
sudo docker build . -f .actor/Dockerfile
# Monorepo
sudo docker build ../ -f .actor/Dockerfile
// Need to run chrome in insecure mode
// - for flatpack: flatpak run com.google.Chrome --args --disable-web-security --allow-running-insecure-content --user-data-dir="/temp/chrome/123"
(() => {
const img = document.querySelector('img');
if (img.complete) {
const canvas = document.createElement('canvas');
canvas.width = img.naturalWidth;
canvas.height = img.naturalHeight;
document.body.appendChild(canvas)

Login

aws sso login --profile my-profile

(or maybe) Configure

aws configure