fix: ensure iframe cleanup in getUntaintedPrototype on error or early return#1770
fix: ensure iframe cleanup in getUntaintedPrototype on error or early return#1770heathdutton wants to merge 1 commit into
Conversation
|
There was a problem hiding this comment.
Pull request overview
This PR fixes a resource leak where temporary iframes created to access untainted prototypes were not always properly cleaned up. The fix ensures the iframe is removed from the DOM in all exit paths.
Key Changes:
- Moved iframe variable declaration outside try block to make it accessible in finally block
- Replaced inline cleanup with a finally block that executes regardless of how the function exits
- Added safety check for parentNode existence before attempting removal
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
… iframe creation (#159) ## Summary - Adopts upstream rrweb [#1770](rrweb-io/rrweb#1770) and [#1802](rrweb-io/rrweb#1802) - **#1770**: Wraps untainted prototype iframe creation in `try/finally` so the iframe is always removed, even on early return (when `contentWindow` is null) or exception. Previously these iframes would leak into the DOM. - **#1802**: Moves `querySelector`/`querySelectorAll` from `testableAccessors` to `testableMethods` and switches helpers from `getUntaintedAccessor` to `getUntaintedMethod`. These are methods, not property accessors, so the accessor check (`getOwnPropertyDescriptor(...).get`) always failed, causing a throwaway iframe to be created every time just to get the untainted prototype. ## Why Both fixes are in `packages/utils/src/index.ts` and affect the same `getUntaintedPrototype` code path. #1770 prevents DOM pollution from leaked iframes. #1802 avoids unnecessary iframe creation on every querySelector/querySelectorAll call, which is a hot path during recording. ## Test plan - [ ] Verify no regressions in recording on pages with patched DOM prototypes (Angular apps) - [ ] Inspect DOM during recording to confirm no orphaned iframes from untainted prototype detection
Fixes #1627
The
getUntaintedPrototypefunction creates a temporary iframe to get clean prototypes, but fails to remove it when:contentWindowis null (early return)This adds a
finallyblock to ensure the iframe is always cleaned up.