Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,11 @@ COPY --chown=myuser package*.json ./
COPY --chown=myuser policies.json ./
COPY --chown=myuser patches ./patches

# Install NPM packages, skip optional and development dependencies to
# keep the image small. Avoid logging too much and print the dependency
# tree for debugging
# Install NPM packages, skip development dependencies to keep the image small. Avoid logging too
# much and print the dependency tree for debugging. Optional dependencies are needed - `impit`
# ships its native bindings as one.
RUN npm --quiet set progress=false \
&& npm install --omit=dev --omit=optional \
&& npm install --omit=dev \
&& echo "Installed NPM packages:" \
&& (npm list --omit=dev --all || true) \
&& echo "Node.js version:" \
Expand Down
179 changes: 178 additions & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,10 @@
"type": "module",
"description": "RAG Web Browser - run Google Search queries and extract content from the top search results.",
"engines": {
"node": ">=18.0.0"
"node": ">=20.0.0"
},
"dependencies": {
"@crawlee/impit-client": "^3.17.0",
"@crawlee/memory-storage": "^3.11.1",
"@ghostery/adblocker-playwright": "^2.5.2",
"@modelcontextprotocol/sdk": "^1.0.4",
Expand Down
8 changes: 8 additions & 0 deletions src/crawlers.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { readFile } from 'node:fs/promises';

import { ImpitHttpClient } from '@crawlee/impit-client';
import { MemoryStorage } from '@crawlee/memory-storage';
import { PlaywrightBlocker } from '@ghostery/adblocker-playwright';
import { Actor, RequestQueue } from 'apify';
Expand All @@ -26,6 +27,12 @@ import { addTimeMeasureEvent, createRequest, createSearchRequest, isActorStandby
const crawlers = new Map<string, CheerioCrawler | PlaywrightCrawler>();
const client = new MemoryStorage({ persistStorage: false });

const contentCrawlerHttpClient = new ImpitHttpClient({
browser: 'firefox144',
vanillaFallback: true,
ignoreTlsErrors: true,
});

let ghosteryBlocker: PlaywrightBlocker | undefined;

async function getGhosteryBlocker(): Promise<PlaywrightBlocker | undefined> {
Expand Down Expand Up @@ -241,6 +248,7 @@ async function createCheerioContentCrawler(
return new CheerioCrawler({
...crawlerOptions,
keepAlive: crawlerOptions.keepAlive,
httpClient: contentCrawlerHttpClient,
requestQueue: await RequestQueue.open(key, { storageClient: client }),
requestHandler: (async (context) => {
const typedContext = context as unknown as CheerioCrawlingContext<ContentCrawlerUserData>;
Expand Down
12 changes: 12 additions & 0 deletions tests/cheerio-crawler.content.test.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
import type { Server } from 'node:http';

import { ImpitHttpClient } from '@crawlee/impit-client';
import { MemoryStorage } from '@crawlee/memory-storage';
import { RequestQueue } from 'apify';
import { CheerioCrawler, type CheerioCrawlingContext, Configuration, log } from 'crawlee';
import { afterAll, beforeAll, describe, expect, it, vi } from 'vitest';

import { ContentCrawlerTypes } from '../src/const.js';
import { createAndStartContentCrawler } from '../src/crawlers.js';
import { requestHandlerCheerio } from '../src/request-handler.js';
import type { ContentCrawlerUserData } from '../src/types.js';
import { createRequest } from '../src/utils.js';
Expand Down Expand Up @@ -82,4 +85,13 @@ describe('Cheerio Crawler Content Tests', () => {
expect(failedUrls.size).toBe(0);
expect(successUrls.size).toBe(1);
});

it('test the crawler is created with the impit HTTP client', async () => {
const { crawler } = await createAndStartContentCrawler(
{ type: ContentCrawlerTypes.CHEERIO, crawlerOptions: {} },
false,
);

expect(Reflect.get(crawler!, 'httpClient')).toBeInstanceOf(ImpitHttpClient);
});
});
Loading