/** * Next.js instrumentation hook — runs once before any route handler. * Polyfills browser globals required by pdfjs-dist at module load time. * @napi-rs/canvas normally provides these but may be absent in some server * environments (e.g. linux/amd64 Docker image on ARM build host). * Text extraction never actually calls these — pdfjs needs the classes defined. */ export async function register() { if (process.env.NEXT_RUNTIME === 'nodejs') { if (typeof globalThis.DOMMatrix === 'undefined') { // @ts-expect-error minimal stub globalThis.DOMMatrix = class DOMMatrix { constructor() { return this; } }; } if (typeof globalThis.ImageData === 'undefined') { // @ts-expect-error minimal stub globalThis.ImageData = class ImageData { constructor() { return this; } }; } if (typeof globalThis.Path2D === 'undefined') { // @ts-expect-error minimal stub globalThis.Path2D = class Path2D { constructor() { return this; } }; } } }