Skip to content

fix(ingest): run on Cloudflare Workers - #587

Merged
anurag629 merged 1 commit into
codercops:devfrom
anurag629:fix/ingest-on-workers
Nov 4, 2026
Merged

anurag629 merged 1 commit into
codercops:devfrom
anurag629:fix/ingest-on-workers

Conversation

@anurag629

Copy link
Copy Markdown
Member

@chatcops/ingest didn't work inside a Cloudflare Worker. Bundlers targeting Workers (wrangler, esbuild with the workerd/browser conditions) pick turndown's browser build, and that build parses an HTML string with the global document. A Worker has none, so every page failed with document is not defined.

The fix parses the fragment with @mixmark-io/domino and passes turndown the element. domino is the parser turndown's Node build already uses, so Markdown output on Node doesn't change, and the existing extract tests pass as they were.

The node:fs/node:path imports for directory sources turned out not to be a problem. They load fine under nodejs_compat, so they stay as they are.

How I checked

  • New tests/extract-workers.test.ts swaps in turndown's browser build and converts the pricing fixture (a table included) with no global document. On dev it fails with ReferenceError: document is not defined, and with this change it passes.
  • I ran a full ingest() of https://chat.codercops.com/sitemap-index.xml in Miniflare (workerd), bundled the way a Worker would be (esbuild, platform browser, conditions workerd,worker,browser,import, nodejs_compat), with a stub embedder and memory stores. On dev all pages failed. With this change: 30 pages indexed, 262 chunks, 0 failed, in 14.5 s.
  • build, typecheck, ingest tests (81), lint (38 warnings, same as dev), api:check, publint.

This is what the hosted crawl needs to run in a Workflow.

Workers bundles pick turndown's browser build, which parses an HTML
string with the page's document. A Worker has no document, so every
page failed with "document is not defined". Parse with domino (the
parser turndown's Node build already uses) and hand turndown the element.
@anurag629
anurag629 merged commit ac269f4 into codercops:dev Nov 4, 2026
5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant