{"record":{"id":"feaa77f650a1c243","repo":"GopeedLab/gopeed","slug":"page-not-found-feaa77","errorCode":null,"errorMessage":"page not found","messagePattern":"page not found","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/download/engine/webview/runtime.go","lineNumber":455,"sourceCode":"\t\tif err != nil {\n\t\t\treturn nil, false, err\n\t\t}\n\t\tif matched {\n\t\t\treturn value, true, nil\n\t\t}\n\t\tif time.Now().After(deadline) {\n\t\t\treturn nil, false, nil\n\t\t}\n\t\ttime.Sleep(pollInterval)\n\t}\n}\n\nfunc (r *Runtime) getPage(id string) (Page, error) {\n\tr.mu.Lock()\n\tdefer r.mu.Unlock()\n\tpage, ok := r.pages[id]\n\tif !ok {\n\t\treturn nil, fmt.Errorf(\"page not found\")\n\t}\n\treturn page, nil\n}\n\nfunc (r *Runtime) closePage(id string) error {\n\tr.mu.Lock()\n\tpage, ok := r.pages[id]\n\tif !ok {\n\t\tr.mu.Unlock()\n\t\treturn nil\n\t}\n\tdelete(r.pages, id)\n\tr.mu.Unlock()\n\treturn page.Close()\n}\n\nfunc parseOpenOptions(raw map[string]any) OpenOptions {\n\treturn OpenOptions{","sourceCodeStart":437,"sourceCodeEnd":473,"githubUrl":"https://github.com/GopeedLab/gopeed/blob/7b7327ffb30816273a74b142cccc0bc10c5a4c67/pkg/download/engine/webview/runtime.go#L437-L473","documentation":"Runtime.getPage looks the page up by id under a mutex and fails when the id is no longer registered. closePage deletes the id, so the classic cause is using a PageHandle after Close() was called (or after the runtime shut down its pages). Methods routed through page() — cookies, and any future page-scoped API — return this error.","triggerScenarios":"Calling page.GetCookies()/SetCookie(...) after await page.close(); keeping a handle in a long-lived map while a script closes the tab; runtime-wide Close() followed by use of a previously opened handle.","commonSituations":"Cleanup code running twice (deferred close plus explicit close) and then a final status read; automation scripts that close pages on navigation events but keep references for later checks.","solutions":["Track closed state in the caller and drop references after Close()","Re-open the page (runtime open/NewPage) if you still need it after closing","Guard double-close paths so lifecycle code runs exactly once"],"exampleFix":"// before\nawait page.close();\nawait page.setCookie({ name: 'sid', value: '1' }); // -> page not found\n// after\nawait page.setCookie({ name: 'sid', value: '1' });\nawait page.close();","handlingStrategy":"validation","validationCode":"// JS: track page lifecycle in the caller\nconst pages = new Map(); // id -> { handle, closed }\nasync function safeCookie(id, cookie) {\n  const p = pages.get(id);\n  if (!p || p.closed) throw new Error('page is closed; open it again');\n  return p.handle.setCookie(cookie);\n}","typeGuard":null,"tryCatchPattern":"try {\n  await page.getCookies();\n} catch (e) {\n  if (String(e).includes('page not found')) {\n    // page was closed elsewhere: re-open and rebuild state instead of retrying\n  }\n}","preventionTips":["Drop references to a handle immediately after Close()","Make close idempotent in caller code (flag + single execution)","After runtime shutdown, treat every previously opened handle as invalid"],"tags":["webview","lifecycle","page","browser-automation"],"backgroundTag":null,"analyzedSha":"7b7327ffb30816273a74b142cccc0bc10c5a4c67","analyzedAt":"2026-08-16T02:51:03.250Z","schemaVersion":2},"datasetVersion":"2026-08-16T03:17:38.424Z"}