{"record":{"id":"e09c1159165d3760","repo":"vitest-dev/vitest","slug":"cannot-find-iframe-element-this-is-a-bug-in-vites","errorCode":null,"errorMessage":"Cannot find iframe element. This is a bug in Vitest. Please, open a new issue with reproduction.","messagePattern":"Cannot find iframe element\\. This is a bug in Vitest\\. Please, open a new issue with reproduction\\.","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/browser/src/client/tester/tester-utils.ts","lineNumber":261,"sourceCode":"  }\n  options_ = options_ || {} as T\n  const currentTime = now()\n  const endTime = startTime + timeout\n  const remainingTime = Math.floor(endTime - currentTime)\n  // keep some buffer to process the timeout, but always hand the provider a\n  // positive value so it surfaces a descriptive, source-mapped locator error\n  // instead of letting the task timer win the race with a generic timeout;\n  // the buffer covers the provider->server->client round-trip of the rejection,\n  // which can exceed 100ms on loaded CI machines running several browsers\n  options_.timeout = Math.max(remainingTime - 250, 1)\n  return options_\n}\n\nexport function getIframeScale(): number {\n  const iframe = window.frameElement\n\n  if (!iframe) {\n    throw new Error(`Cannot find iframe element. This is a bug in Vitest. Please, open a new issue with reproduction.`)\n  }\n\n  // DOMMatrix parses the computed 2D transform matrix [a, b, c, d, e, f]\n  // `a` and `d` are the x and y scale factors - since we only apply uniform scaling, `a === d`\n  const scale = new DOMMatrix(getComputedStyle(iframe).transform).a\n\n  return scale\n}\n\nfunction escapeRegexForSelector(re: RegExp): string {\n  // Unicode mode does not allow \"identity character escapes\", so we do not escape and\n  // hope that it does not contain quotes and/or >> signs.\n  // https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Regular_expressions/Character_escape\n  // TODO: rework RE usages in internal selectors away from literal representation to json, e.g. {source,flags}.\n  if (re.unicode || (re as any).unicodeSets) {\n    return String(re)\n  }\n  // Even number of backslashes followed by the quote -> insert a backslash.","sourceCodeStart":243,"sourceCodeEnd":279,"githubUrl":"https://github.com/vitest-dev/vitest/blob/1fa9837ec26533512fdcad8baebf249771bd340a/packages/browser/src/client/tester/tester-utils.ts#L243-L279","documentation":"Thrown by `getIframeScale` when `window.frameElement` is null, i.e. the current execution context is the top-level window and not inside an `<iframe>`. The browser tester normally runs the test code inside an iframe so it can apply UI-scaling transforms; `getIframeScale` reads the iframe's computed `transform` to recover the scale factor. Finding no iframe means the tester's iframe embedding is broken — explicitly flagged as a Vitest bug.","triggerScenarios":"The browser tester's iframe embedding is bypassed or removed; `getIframeScale` is called from the top-level page rather than the tester iframe; a custom HTML shell that does not embed the tester in an iframe.","commonSituations":"Custom browser tester entry point; an upstream Vitest change that breaks iframe embedding; running tester internals outside the standard iframe.","solutions":["Use the standard Vitest browser tester HTML shell that embeds the runner in an iframe.","If you have customized the tester UI, restore the iframe element that hosts the test context.","Otherwise treat this as a Vitest bug: open an issue with a minimal reproduction."],"exampleFix":null,"handlingStrategy":"validation","validationCode":"// internal contract: this code must run inside the tester iframe\nif (!window.frameElement) {\n  throw new Error('getIframeScale must be called from within the tester iframe')\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Use the standard Vitest browser tester HTML shell that embeds the runner in an iframe.","Do not bypass or replace the iframe embedding.","Report regressions as Vitest bugs with a reproduction."],"tags":["internal","browser","iframe","scaling"],"backgroundTag":null,"analyzedSha":"1fa9837ec26533512fdcad8baebf249771bd340a","analyzedAt":"2026-08-11T16:11:39.638Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}