apify/crawlee · error · Error

The `gotoOptions` property is not available until `prepareNa

Error message

The `gotoOptions` property is not available until `prepareNavigation` runs.

What it means

The `gotoOptions` object is produced by the prepareNavigation middleware. Before that middleware runs, the property exists only as a throwing getter to catch premature access, so reading it earlier fails with this error.

Source

Thrown at packages/browser-crawler/src/internals/browser-crawler.ts:611

        const addRequests = crawlingContext.addRequests;

        const extractLinks = async (options?: ExtractLinksOptions): Promise<string[]> => {
            return extractUrlsFromPage(
                page as any,
                options?.selector ?? 'a',
                options?.baseUrl ?? crawlingContext.request.loadedUrl ?? crawlingContext.request.url,
            );
        };

        return {
            page,
            get response(): Response {
                throw new Error(
                    "The `response` property is not available. This might mean that you're trying to access it before navigation or that navigation resulted in `null` (this should only happen with `about:` URLs)",
                );
            },
            get gotoOptions(): Dictionary {
                throw new Error('The `gotoOptions` property is not available until `prepareNavigation` runs.');
            },
            extractLinks,
            enqueueLinks: async (options: EnqueueLinksOptions = {}) => {
                const baseUrl = resolveBaseUrlForEnqueueLinksFiltering({
                    enqueueStrategy: options.strategy,
                    finalRequestUrl: crawlingContext.request.loadedUrl,
                    originalRequestUrl: crawlingContext.request.url,
                    userProvidedBaseUrl: options.baseUrl,
                });

                const urls = await extractLinks(options);

                return addRequests(urls, {
                    ...options,
                    baseUrl,
                    strategy: options.strategy ?? EnqueueStrategy.SameHostname,
                });
            },

View on GitHub (pinned to dbe57fb09c)

Solutions

  1. Read gotoOptions only after the prepareNavigation middleware has run
  2. To customize navigation, wrap/extend prepareNavigation or use the appropriate hook rather than reading early
  3. Guard access with a try/catch or property check if the timing is uncertain
Defensive patterns

Strategy: validation

Try / catch

let gotoOptions: Dictionary | undefined;
try { gotoOptions = ctx.gotoOptions; } catch { /* prepareNavigation has not run yet */ }

Prevention

When it happens

Trigger: Reading crawlingContext.gotoOptions in code that executes before prepareNavigation (pre-navigation hooks, context construction, custom middlewares registered before navigation).

Common situations: Custom browser-crawler middlewares inspecting gotoOptions; users hooking into the crawling context before navigation to modify goto options (they should use the prepareNavigation phase instead).

Related errors


AI-assisted analysis of apify/crawlee@dbe57fb09c (2026-08-30). Data as JSON: /api/errors/c81d94bb13ae2ebd. Report an issue: GitHub.