{"record":{"id":"1ba0354f35c6be88","repo":"grafana/k6","slug":"internal-error-while-initializing-frame-t-w","errorCode":null,"errorMessage":"internal error while initializing frame %T: %w","messagePattern":"internal error while initializing frame %T: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/js/modules/k6/browser/common/frame_session.go","lineNumber":573,"sourceCode":"\t\treqIntercept = true\n\t}\n\tif err := fs.updateRequestInterception(reqIntercept); err != nil {\n\t\treturn err\n\t}\n\n\tif err := fs.updateOffline(true); err != nil {\n\t\treturn err\n\t}\n\tif err := fs.updateHTTPCredentials(true); err != nil {\n\t\treturn err\n\t}\n\tif err := fs.updateEmulateMedia(); err != nil {\n\t\treturn err\n\t}\n\n\tfor _, action := range optActions {\n\t\tif err := action.Do(cdp.WithExecutor(fs.ctx, fs.session)); err != nil {\n\t\t\treturn fmt.Errorf(\"internal error while initializing frame %T: %w\", action, err)\n\t\t}\n\t}\n\n\treturn nil\n}\n\nfunc (fs *FrameSession) initRendererEvents() {\n\tfs.logger.Debugf(\"NewFrameSession:initEvents:initRendererEvents\",\n\t\t\"sid:%v tid:%v\", fs.session.ID(), fs.targetID)\n\n\tevents := []string{\n\t\tcdproto.EventLogEntryAdded,\n\t\tcdproto.EventPageFileChooserOpened,\n\t\tcdproto.EventPageFrameAttached,\n\t\tcdproto.EventPageFrameDetached,\n\t\tcdproto.EventPageFrameNavigated,\n\t\tcdproto.EventPageFrameRequestedNavigation,\n\t\tcdproto.EventPageFrameStartedLoading,","sourceCodeStart":555,"sourceCodeEnd":591,"githubUrl":"https://github.com/grafana/k6/blob/93accf6570dcd306ca5e99cc44c393ee3797761b/internal/js/modules/k6/browser/common/frame_session.go#L555-L591","documentation":"FrameSession.initOptions (frame_session.go:573) replays browser-context emulation settings onto each new frame session (viewport, device metrics, touch, media emulation, JS/CSP overrides, user agent, offline/credentials state — the accumulated optActions). If any single CDP action fails, the loop stops with the action's type (%T) wrapped in this error. The root cause is either an invalid emulation value accepted earlier but rejected by chromium, or a target that died during init.","triggerScenarios":"Setting multiple context options (viewport, deviceScaleFactor, isMobile, hasTouch, colorScheme, reducedMotion, media, userAgent) and opening a page whose target crashes or closes mid-init; some chromium builds reject unusual device metric combinations.","commonSituations":"Emulating mobile devices with hand-rolled option combinations, remote browsers with different emulation support, and resource-exhausted chromium dying during page setup.","solutions":["Read the wrapped %T type and inner error to identify which emulation action failed, then simplify that context option","Prefer a built-in device descriptor over hand-assembled viewport/touch/mobile combos","If the target is dying rather than rejecting, apply the same resource/stability fixes as for other init CDP errors"],"exampleFix":"// before\nconst ctx = browser.newContext({\n  viewport: { width: 375, height: 812 },\n  deviceScaleFactor: 3, isMobile: true, hasTouch: true,\n  userAgent: 'MyAgent',\n});\n\n// after — verify each emulation option against a stable target first\nconst ctx = browser.newContext({\n  viewport: { width: 375, height: 812 },\n  deviceScaleFactor: 3, isMobile: true, hasTouch: true,\n  userAgent:\n    'Mozilla/5.0 (iPhone; CPU iPhone OS 17_0 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/17.0 Mobile/15E148 Safari/604.1',\n});","handlingStrategy":"validation","validationCode":"function checkContextOpts(o = {}) {\n  if (o.viewport && !(Number.isInteger(o.viewport.width) && Number.isInteger(o.viewport.height))) {\n    throw new Error('viewport must have integer width/height');\n  }\n  if (o.userAgent !== undefined && typeof o.userAgent !== 'string') {\n    throw new Error('userAgent must be a string');\n  }\n  return o;\n}\nbrowser.newContext(checkContextOpts(cfg));","typeGuard":"interface Viewport { width: number; height: number }\nfunction isViewport(v: unknown): v is Viewport {\n  return !!v && typeof (v as Viewport).width === 'number' && typeof (v as Viewport).height === 'number';\n}","tryCatchPattern":"try {\n  browser.newContext(emulationOpts);\n  const page = browser.newPage();\n} catch (e) {\n  if (/internal error while initializing frame/i.test(String(e))) {\n    // read the wrapped action type; simplify/fix that context option and retry\n  }\n}","preventionTips":["Use built-in device descriptors instead of hand-rolled emulation combos","Change one emulation option at a time when a new combo starts failing"],"tags":["browser","emulation","context-options","cdp","device"],"backgroundTag":null,"analyzedSha":"93accf6570dcd306ca5e99cc44c393ee3797761b","analyzedAt":"2026-08-15T21:23:27.118Z","schemaVersion":2},"datasetVersion":"2026-08-16T03:17:38.424Z"}