{"record":{"id":"b68c46935c9be3fb","repo":"grafana/k6","slug":"updateviewport-should-be-called-only-in-the-main-f","errorCode":null,"errorMessage":"updateViewport should be called only in the main frame. (sid:%v tid:%v)","messagePattern":"updateViewport should be called only in the main frame\\. \\(sid:(.+?) tid:(.+?)\\)","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/js/modules/k6/browser/common/frame_session.go","lineNumber":1231,"sourceCode":"}\n\nfunc (fs *FrameSession) updateRequestInterception(enable bool) error {\n\tfs.logger.Debugf(\"NewFrameSession:updateRequestInterception\",\n\t\t\"sid:%v tid:%v on:%v\",\n\t\tfs.session.ID(),\n\t\tfs.targetID, enable)\n\n\treturn fs.networkManager.setRequestInterception(enable)\n}\n\nfunc (fs *FrameSession) updateViewport() error {\n\tfs.logger.Debugf(\"NewFrameSession:updateViewport\", \"sid:%v tid:%v\", fs.session.ID(), fs.targetID)\n\n\t// other frames don't have viewports and,\n\t// this method shouldn't be called for them.\n\t// this is just a sanity check.\n\tif !fs.isMainFrame() {\n\t\terr := fmt.Errorf(\"updateViewport should be called only in the main frame.\"+\n\t\t\t\" (sid:%v tid:%v)\", fs.session.ID(), fs.targetID)\n\t\tpanic(err)\n\t}\n\n\topts := fs.page.browserCtx.opts\n\temulatedSize := fs.page.emulatedSize\n\tif emulatedSize == nil {\n\t\treturn nil\n\t}\n\tviewport := emulatedSize.Viewport\n\tscreen := emulatedSize.Screen\n\n\torientation := emulation.ScreenOrientation{\n\t\tAngle: 0.0,\n\t\tType:  emulation.OrientationTypePortraitPrimary,\n\t}\n\tif viewport.Width > viewport.Height {\n\t\torientation.Angle = 90.0","sourceCodeStart":1213,"sourceCodeEnd":1249,"githubUrl":"https://github.com/grafana/k6/blob/94169daab29df52c1ed2ee0549657a577666b855/internal/js/modules/k6/browser/common/frame_session.go#L1213-L1249","documentation":"A deliberate internal sanity-check sentinel: updateViewport applies device metrics only to the top-level page target, and this error is returned when the method is invoked on a FrameSession whose target is an iframe or another out-of-process child frame (isMainFrame() is false). It signals a k6-internal misuse of the API, not anything the user's script can directly control; session and target IDs are included for debugging.","triggerScenarios":"Thrown at internal/js/modules/k6/browser/common/frame_session.go:1231 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Do not attempt viewport operations on child frames — call viewport-related APIs (setViewportSize, emulateMedia size) on the page object","Report the issue with the session/target IDs if it occurs during normal page usage, as it indicates a bug in k6's frame session lifecycle","Update to a newer k6 version where frame-session handling for iframes has been fixed"],"exampleFix":null,"handlingStrategy":"validation","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"94169daab29df52c1ed2ee0549657a577666b855","analyzedAt":"2026-08-18T03:05:52.393Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}