{"record":{"id":"89df33d17b4b1274","repo":"grafana/k6","slug":"wrong-polling-option-value-q-possible-values","errorCode":null,"errorMessage":"wrong polling option value: %q; possible values: \"raf\", \"mutation\" or number","messagePattern":"wrong polling option value: %q; possible values: \"raf\", \"mutation\" or number","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/js/modules/k6/browser/common/frame_options.go","lineNumber":671,"sourceCode":"\tobj := opts.ToObject(rt)\n\tfor _, k := range obj.Keys() {\n\t\tv := obj.Get(k)\n\t\tswitch k {\n\t\tcase \"timeout\":\n\t\t\to.Timeout = time.Duration(v.ToInteger()) * time.Millisecond\n\t\tcase \"polling\":\n\t\t\tswitch v.ExportType().Kind() {\n\t\t\tcase reflect.Int64:\n\t\t\t\to.Polling = PollingInterval\n\t\t\t\to.Interval = v.ToInteger()\n\t\t\tcase reflect.String:\n\t\t\t\tif p, ok := pollingTypeToID[v.ToString().String()]; ok {\n\t\t\t\t\to.Polling = p\n\t\t\t\t\tbreak\n\t\t\t\t}\n\t\t\t\tfallthrough\n\t\t\tdefault:\n\t\t\t\treturn fmt.Errorf(\"wrong polling option value: %q; \"+\n\t\t\t\t\t`possible values: \"raf\", \"mutation\" or number`, v)\n\t\t\t}\n\t\t}\n\t}\n\n\treturn nil\n}\n\nfunc NewFrameWaitForLoadStateOptions(defaultTimeout time.Duration) *FrameWaitForLoadStateOptions {\n\treturn &FrameWaitForLoadStateOptions{\n\t\tTimeout: defaultTimeout,\n\t}\n}\n\n// Parse parses the frame waitForLoadState options.\nfunc (o *FrameWaitForLoadStateOptions) Parse(ctx context.Context, opts sobek.Value) error {\n\trt := k6ext.Runtime(ctx)\n\tif !common.IsNullish(opts) {","sourceCodeStart":653,"sourceCodeEnd":689,"githubUrl":"https://github.com/grafana/k6/blob/93accf6570dcd306ca5e99cc44c393ee3797761b/internal/js/modules/k6/browser/common/frame_options.go#L653-L689","documentation":"FrameWaitForFunctionOptions.Parse (frame_options.go:671) inspects the JS type of the `polling` option of frame.waitForFunction(). Only an int64-like number (fixed millisecond interval) or one of the strings \"raf\"/\"mutation\" is accepted; every other type or string falls through to this error. The number must actually be a number in the JS value (e.g. a string \"100\" is rejected).","triggerScenarios":"frame.waitForFunction(fn, arg, { polling: 'requestAnimationFrame' }) (wrong alias), { polling: true }, { polling: 'every-100ms' }, or a stringified number { polling: '100' }. Passing options in the wrong argument position (second arg instead of third) can also surface unexpected types here.","commonSituations":"Translating Puppeteer's polling names (Puppeteer accepts only 'raf' or a number) or assuming any string constant works; also passing a config value that arrived as a string from JSON/env vars.","solutions":["Use { polling: 'raf' } or { polling: 'mutation' } or a plain number of milliseconds, e.g. { polling: 100 }","If the value comes from config, coerce it before calling: Number(x) when it is numeric","Verify the argument order: waitForFunction(pageFunction, arg, options)"],"exampleFix":"// before\nframe.waitForFunction(() => !!window.ready, {}, { polling: 'requestAnimationFrame' });\n\n// after\nframe.waitForFunction(() => !!window.ready, {}, { polling: 'raf' });\n// or a fixed interval:\nframe.waitForFunction(() => !!window.ready, {}, { polling: 100 });","handlingStrategy":"validation","validationCode":"function validPolling(v) {\n  if (v === undefined) return v; // default\n  if (typeof v === 'number' && Number.isFinite(v)) return v;\n  if (v === 'raf' || v === 'mutation') return v;\n  throw new Error('polling must be \"raf\", \"mutation\" or a number (ms)');\n}\nframe.waitForFunction(fn, arg, { ...opts, polling: validPolling(opts.polling) });","typeGuard":"function isPolling(v: unknown): v is 'raf' | 'mutation' | number {\n  return v === 'raf' || v === 'mutation' || (typeof v === 'number' && Number.isFinite(v));\n}","tryCatchPattern":null,"preventionTips":["Coerce config strings to numbers before use: Number(x)","Pass options as the third argument: waitForFunction(fn, arg, options)"],"tags":["browser","options","polling","waitforfunction","validation"],"backgroundTag":null,"analyzedSha":"93accf6570dcd306ca5e99cc44c393ee3797761b","analyzedAt":"2026-08-15T21:23:27.118Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}