Skip to content

Commit 1cf95e5

Browse files
Fix iframe size feedback loop on Linux/Windows (#54)
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 <[email protected]>
1 parent ff6f5f0 commit 1cf95e5

File tree

1 file changed

+12
-5
lines changed

1 file changed

+12
-5
lines changed

src/app.ts

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -745,18 +745,25 @@ 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 =
761+
window.innerWidth - document.documentElement.clientWidth;
762+
// Use max of rect (includes CSS transforms) and scroll dimensions (content overflow).
763+
const width = Math.ceil(
764+
Math.max(rect.width, el.scrollWidth) + scrollbarWidth,
765+
);
766+
const height = Math.ceil(Math.max(rect.height, el.scrollHeight));
760767
this.sendSizeChange({ width, height });
761768
});
762769
};

0 commit comments

Comments
 (0)