Skip to content

Commit d031221

Browse files
Fix iframe size feedback loop on Linux/Windows
Compensate for viewport scrollbar width in size change notifications. On Linux/Windows, scrollbars consume space from the content area, causing a feedback loop where the iframe progressively shrinks to zero. - Use window.innerWidth - clientWidth to detect scrollbar width - Use max of getBoundingClientRect (CSS transforms) and scroll dimensions (content overflow) to report accurate size 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
1 parent ff6f5f0 commit d031221

1 file changed

Lines changed: 9 additions & 5 deletions

File tree

src/app.ts

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -745,18 +745,22 @@ export class App extends Protocol<Request, Notification, Result> {
745745
*/
746746
setupSizeChangeNotifications() {
747747
let scheduled = false;
748+
748749
const sendBodySizeChange = () => {
749750
if (scheduled) {
750751
return;
751752
}
752753
scheduled = true;
753754
requestAnimationFrame(() => {
754755
scheduled = false;
755-
const rect = (
756-
document.body.parentElement ?? document.body
757-
).getBoundingClientRect();
758-
const width = Math.ceil(rect.width);
759-
const height = Math.ceil(rect.height);
756+
const el = document.body.parentElement ?? document.body;
757+
const rect = el.getBoundingClientRect();
758+
// Compensate for viewport scrollbar on Linux/Windows where scrollbars
759+
// consume space. window.innerWidth includes scrollbar, clientWidth excludes it.
760+
const scrollbarWidth = window.innerWidth - document.documentElement.clientWidth;
761+
// Use max of rect (includes CSS transforms) and scroll dimensions (content overflow).
762+
const width = Math.ceil(Math.max(rect.width, el.scrollWidth) + scrollbarWidth);
763+
const height = Math.ceil(Math.max(rect.height, el.scrollHeight));
760764
this.sendSizeChange({ width, height });
761765
});
762766
};

0 commit comments

Comments
 (0)