{"record":{"id":"e7706afabe3657ac","repo":"JuliusBrussee/caveman","slug":"browser-function-returned-no-result-object","errorCode":null,"errorMessage":"browser function returned no result object","messagePattern":"browser function returned no result object","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"browse/cdp.go","lineNumber":418,"sourceCode":"\tvar exception *runtime.ExceptionDetails\n\tif err := chromedp.Run(ctx, chromedp.ActionFunc(func(actionCtx context.Context) error {\n\t\tobj, err := dom.ResolveNode().WithBackendNodeID(cdp.BackendNodeID(target.BackendDOMNodeID)).Do(actionCtx)\n\t\tif err != nil {\n\t\t\treturn err\n\t\t}\n\t\tif obj == nil {\n\t\t\treturn errors.New(\"resolve node returned no object\")\n\t\t}\n\t\tres, exception, err = runtime.CallFunctionOn(fn).WithObjectID(obj.ObjectID).Do(actionCtx)\n\t\treturn err\n\t})); err != nil {\n\t\treturn nil, err\n\t}\n\tif exception != nil {\n\t\treturn nil, errors.New(\"browser function threw\")\n\t}\n\tif res == nil {\n\t\treturn nil, errors.New(\"browser function returned no result object\")\n\t}\n\treturn res, nil\n}\n\nfunc jsString(s string) string {\n\tb, _ := json.Marshal(s)\n\treturn string(b)\n}\n\nfunc DefaultUserDataDir(home string) string {\n\tif home == \"\" {\n\t\tif h, err := os.UserHomeDir(); err == nil {\n\t\t\thome = filepath.Join(h, \".caveman\")\n\t\t}\n\t}\n\tif home == \"\" {\n\t\treturn \"\"\n\t}","sourceCodeStart":400,"sourceCodeEnd":436,"githubUrl":"https://github.com/JuliusBrussee/caveman/blob/27d5a3981a347890211bb1bf2439e5c821a63bc9/browse/cdp.go#L400-L436","documentation":"Returned by callOnNodeRaw() when runtime.CallFunctionOn completes without error and without an exception but yields a nil result RemoteObject. Distinct from 'browser function threw' (exception present) and from decodeBoolObject's 'browser returned no result object' (higher up); here the raw evaluation path got nothing back, which happens when the function returns undefined or the context is torn down around the call. The driver fails closed rather than nil-deref.","triggerScenarios":"An on-node evaluation whose function implicitly returns undefined (missing return statement), or a call racing context destruction so Chrome drops the result silently.","commonSituations":"Custom probe functions written as statements instead of expressions forgetting to return; eval helpers reused from console (where undefined results are normal) pasted into act paths; navigation racing the eval.","solutions":["Make the injected function explicitly return a value (return document.activeElement !== this; not just the comparison as a statement body that gets dropped).","If the function already returns, re-snapshot and retry once — a torn-down context can swallow results.","Test the function body standalone via eval on the same node to confirm it produces a value."],"exampleFix":"// before — function body has no return\n`function(){ this.focus(); }`\n\n// after\n`function(){ this.focus(); return document.activeElement === this; }`","handlingStrategy":"type-guard","validationCode":"// Go: when writing injected functions, always return a value\n// bad:  function(){ this.focus(); }\n// good: function(){ this.focus(); return document.activeElement === this; }","typeGuard":"func hasResult(res *runtime.RemoteObject) (*runtime.RemoteObject, error) {\n    if res == nil {\n        return nil, errors.New(\"browser function returned no result object\")\n    }\n    return res, nil\n}","tryCatchPattern":"// Go\nres, err := d.callOnNodeRaw(ctx, target, fn)\nif err != nil {\n    if strings.Contains(err.Error(), \"returned no result object\") {\n        // likely undefined return: fix fn to return, then one retry after re-snapshot\n        return fixFnAndRetry(ctx, target, fn)\n    }\n    return nil, err\n}","preventionTips":["Every function string passed to callOnNode/callOnNodeRaw must end in an explicit `return`.","Nil-check the RemoteObject on every CDP result path; Chrome can return nil without error.","Validate injected JS in an eval tool first when porting console snippets."],"tags":["browser","cdp","javascript","nil-safety","race"],"backgroundTag":null,"analyzedSha":"27d5a3981a347890211bb1bf2439e5c821a63bc9","analyzedAt":"2026-08-15T09:26:11.751Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}