fix: dangling speculative frames (#45686)

* fix: dangling speculative frames

Co-authored-by: Samuel Maddock <smaddock@slack-corp.com>

* harden lifecycle state checks

Co-authored-by: Samuel Maddock <smaddock@slack-corp.com>

* feedback

Co-authored-by: Samuel Maddock <smaddock@slack-corp.com>

* add const

Co-authored-by: Samuel Maddock <smaddock@slack-corp.com>

---------

Co-authored-by: trop[bot] <37223003+trop[bot]@users.noreply.github.com>
Co-authored-by: Samuel Maddock <smaddock@slack-corp.com>
This commit is contained in:
trop[bot] 2025-02-18 21:04:36 -05:00 committed by GitHub
parent 497849bf66
commit 74c71dbb2d
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
6 changed files with 174 additions and 53 deletions

View file

@ -428,6 +428,47 @@ describe('webFrameMain module', () => {
crossOriginPromise = w.webContents.loadURL(server.crossOriginUrl);
await expect(unloadPromise).to.eventually.be.fulfilled();
});
// Skip test as we don't have an offline repro yet
it.skip('should not crash due to dangling frames', async () => {
w = new BrowserWindow({
show: false,
webPreferences: {
preload: path.join(subframesPath, 'preload.js')
}
});
// Persist frame references so WebFrameMain is initialized for each
const frames: Electron.WebFrameMain[] = [];
w.webContents.on('frame-created', (_event, details) => {
console.log('frame-created');
frames.push(details.frame!);
});
w.webContents.on('will-frame-navigate', (event) => {
console.log('will-frame-navigate', event);
frames.push(event.frame!);
});
// Load document with several speculative subframes
await w.webContents.loadURL('https://www.ezcater.com/delivery/pizza-catering');
// Test that no frame will crash due to a dangling render frame host
const crashTest = () => {
for (const frame of frames) {
expect(frame._lifecycleStateForTesting).to.not.equal('Speculative');
try {
expect(frame.url).to.be.a('string');
} catch {
// Exceptions from non-dangling frames are expected
}
}
};
crashTest();
w.webContents.destroy();
await setTimeout(1);
crashTest();
});
});
describe('webFrameMain.fromId', () => {