{"record":{"id":"7858a55dabe6b96a","repo":"puppeteer/puppeteer","slug":"cannot-poll-with-non-positive-interval","errorCode":null,"errorMessage":"Cannot poll with non-positive interval","messagePattern":"Cannot poll with non-positive interval","errorType":"validation","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/puppeteer-core/src/api/Realm.ts","lineNumber":168,"sourceCode":"    Func extends EvaluateFunc<Params> = EvaluateFunc<Params>,\n  >(\n    pageFunction: Func | string,\n    options: {\n      polling?: 'raf' | 'mutation' | number;\n      timeout?: number;\n      root?: ElementHandle<Node>;\n      signal?: AbortSignal;\n    } = {},\n    ...args: Params\n  ): Promise<HandleFor<Awaited<ReturnType<Func>>>> {\n    const {\n      polling = 'raf',\n      timeout = this.timeoutSettings.timeout(),\n      root,\n      signal,\n    } = options;\n    if (typeof polling === 'number' && polling < 0) {\n      throw new Error('Cannot poll with non-positive interval');\n    }\n    const waitTask = new WaitTask(\n      this,\n      {\n        polling,\n        root,\n        timeout,\n        signal,\n      },\n      pageFunction as unknown as\n        ((...args: unknown[]) => Promise<Awaited<ReturnType<Func>>>) | string,\n      ...args,\n    );\n    return await waitTask.result;\n  }\n\n  /** @internal */\n  abstract adoptBackendNode(backendNodeId?: number): Promise<JSHandle<Node>>;","sourceCodeStart":150,"sourceCodeEnd":186,"githubUrl":"https://github.com/puppeteer/puppeteer/blob/d484e21c17f6023826fefdcdeeb553e04a7aaed8/packages/puppeteer-core/src/api/Realm.ts#L150-L186","documentation":"Thrown by Realm.waitForFunction() (and the page/frame wrappers) when the `polling` option is a negative number. Polling controls how often the function is re-evaluated; a negative interval is invalid. Note the guard uses `polling < 0`, so the string modes ('raf', 'mutation') and 0 are accepted, despite the message saying 'non-positive'.","triggerScenarios":"Calling `page.waitForFunction(fn, { polling: -100 })`, `page.waitForSelector(sel, { polling: -1 })`, or any negative numeric polling value. The default is 'raf' (requestAnimationFrame), which is unaffected.","commonSituations":"Passing a computed interval that went negative; reusing a `timeout` value as `polling` by mistake; porting code that used a signed delta for delay.","solutions":["Use a positive polling interval in milliseconds (e.g. `polling: 100`).","Prefer the string modes `polling: 'raf'` or `polling: 'mutation'` for most waits.","If the interval is computed, clamp it: `polling: Math.max(0, interval)`."],"exampleFix":"// before\nawait page.waitForFunction(() => window.ready, { polling: -50 });\n// after\nawait page.waitForFunction(() => window.ready, { polling: 100 });","handlingStrategy":"validation","validationCode":"if (typeof polling === 'number' && polling < 0) {\n  throw new Error('polling must be >= 0');\n}\nawait page.waitForFunction(fn, { polling });","typeGuard":"function isValidPolling(p: 'raf' | 'mutation' | number): boolean {\n  return typeof p === 'string' || (typeof p === 'number' && p >= 0);\n}","tryCatchPattern":"try {\n  await page.waitForFunction(fn, { polling });\n} catch (e) {\n  if (e instanceof Error && /non-positive interval/.test(e.message)) {\n    await page.waitForFunction(fn, { polling: 'raf' });\n  } else throw e;\n}","preventionTips":["Prefer 'raf' or 'mutation' polling unless you need a fixed cadence.","Don't reuse a timeout variable as the polling interval.","Clamp computed intervals: Math.max(0, interval)."],"tags":["waitforfunction","validation","polling","realm"],"backgroundTag":null,"analyzedSha":"d484e21c17f6023826fefdcdeeb553e04a7aaed8","analyzedAt":"2026-08-12T06:33:19.665Z","schemaVersion":2},"datasetVersion":"2026-08-12T13:17:24.610Z"}