{"record":{"id":"667dd8dea669038c","repo":"grafana/k6","slug":"evaluating-handle-of-q-unexpected-type-t","errorCode":null,"errorMessage":"evaluating handle of %q: unexpected type %T","messagePattern":"evaluating handle of %q: unexpected type %T","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/js/modules/k6/browser/common/frame.go","lineNumber":2314,"sourceCode":"\nfunc (f *Frame) evaluateHandleWithSelector(selector string, pageFunc string, args ...any) (JSHandleAPI, error) {\n\tf.log.Debugf(\"Frame:evaluateHandleWithSelector\", \"fid:%s furl:%q sel:%q\", f.ID(), f.URL(), selector)\n\n\tevaluateHandle := func(apiCtx context.Context, handle *ElementHandle) (any, error) {\n\t\treturn handle.EvaluateHandle(pageFunc, args...)\n\t}\n\n\tact := f.newAction(\n\t\tselector, DOMElementStateAttached, true, evaluateHandle, []string{}, false, withRetry, true, f.defaultTimeout(),\n\t)\n\tv, err := call(f.ctx, act, f.defaultTimeout())\n\tif err != nil {\n\t\treturn nil, errorFromDOMError(err)\n\t}\n\n\thandle, ok := v.(JSHandleAPI)\n\tif !ok {\n\t\treturn nil, fmt.Errorf(\"evaluating handle of %q: unexpected type %T\", selector, v)\n\t}\n\n\treturn handle, nil\n}\n\n// frameExecutionContext represents a JS execution context that belongs to Frame.\ntype frameExecutionContext interface {\n\t// adoptBackendNodeID adopts specified backend node into this execution\n\t// context from another execution context.\n\tadoptBackendNodeID(backendNodeID cdp.BackendNodeID) (*ElementHandle, error)\n\n\t// adoptElementHandle adopts the specified element handle into this\n\t// execution context from another execution context.\n\tadoptElementHandle(elementHandle *ElementHandle) (*ElementHandle, error)\n\n\t// eval evaluates the provided JavaScript within this execution context and\n\t// returns a value or handle.\n\teval(","sourceCodeStart":2296,"sourceCodeEnd":2332,"githubUrl":"https://github.com/grafana/k6/blob/93accf6570dcd306ca5e99cc44c393ee3797761b/internal/js/modules/k6/browser/common/frame.go#L2296-L2332","documentation":"Internal invariant violation in Frame.evaluateWithSelector's action pipeline: the action completed without error but its result could not be type-asserted to JSHandleAPI. evaluateHandle is supposed to wrap every CDP eval result in a handle, so reaching this branch means k6's own wrapping layer returned an unexpected Go type — effectively an internal k6 bug, not a user input error.","triggerScenarios":"Calling frame-level $eval/$$eval/evaluateHandle-style APIs (e.g. page.$eval) while the underlying action machinery hits an edge case (nil result boxed as a non-handle, race in the action channel). No specific user input is known to deterministically trigger it.","commonSituations":"Rare; appears as one-off reports during heavy parallel browser iterations or around navigation races; often alongside other execution-context errors in the same log.","solutions":["Upgrade k6 to the latest minor — check the k6-browser changelog for JSHandle wrapping fixes","Reproduce with a minimal script and --log-output to capture the type shown in the message (%T names the concrete Go type)","If stable, report at github.com/grafana/k6 with the script and the full error including the type name"],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":null,"typeGuard":"function isInternalTypeAssertion(e) {\n  return e instanceof Error && /unexpected type /.test(e.message);\n}","tryCatchPattern":"try {\n  await page.$eval('#x', (el) => el.value);\n} catch (e) {\n  if (isInternalTypeAssertion(e)) { /* log %T value and report to k6 */ }\n  throw e;\n}","preventionTips":["Pin and upgrade k6 versions deliberately","Report occurrences with full error text — this is an internal invariant"],"tags":["browser","internal","type-assertion","evaluate-handle"],"backgroundTag":null,"analyzedSha":"93accf6570dcd306ca5e99cc44c393ee3797761b","analyzedAt":"2026-08-15T21:23:27.118Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}