Repository navigation
feat: preloads and nodeIntegration in iframes - #16425
Conversation
| const a = window.document.createElement('a') | ||
| const resolveURL = function (url) { | ||
| a.href = url | ||
| return a.href |
There was a problem hiding this comment.
this function can be replaced with the URL API
const resolveURL = function(url) {
return new URL(url, location.href).href
}There was a problem hiding this comment.
I'll follow up with this and other clean up referenced above. I want to keep this down to just the new code
| describe('renderer nodeSupportInSubFrames', () => { | ||
| const generateTests = (sandboxEnabled) => { | ||
| describe(`with sandbox ${sandboxEnabled ? 'enabled' : 'disabled'}`, () => { | ||
| let w |
There was a problem hiding this comment.
instead of this shared global, perhaps we could do something like
const withWindow = async (f) => {
const w = new BrowserWindow(...)
await f(w)
await closeWindow(w)
}
// later
it('something', async () => {
await withWindow(async (w) => {
// ...
})
})Or perhaps there's a nice way to do something like
it('something', withWindow(async () => {
// ...
}))mainly I don't like that the window is closed in the test after. That could result in test failures relating to teardown being misattributed.
There was a problem hiding this comment.
This is our current pattern, I like the idea of withWindow but I'd rather do that as a sweeping change rather than file-by-file for consitency 👍
| it('should load preload scripts in nested iframes', async () => { | ||
| const detailsPromise = emittedNTimes(remote.ipcMain, 'preload-ran', 3) | ||
| w.loadFile(path.resolve(__dirname, 'fixtures/sub-frames/frame-with-frame-container.html')) | ||
| const [event1, event2, event3] = await detailsPromise |
There was a problem hiding this comment.
Would it make sense to refactor these tests to fail rather than timeout if the preload doesn't get loaded?
There was a problem hiding this comment.
Yes, but that's hard to do without complicated IPC. A timeout in this case seemed the simplest (unfortunately) unless you have a good idea here
This feature has delibrately been built / implemented in such a way that it has minimum impact on existing apps / code-paths. Without enabling the new "nodeSupportInSubFrames" option basically none of this new code will be hit. The things that I believe need extra scrutiny are: * Introduction of `event.reply` for IPC events and usage of `event.reply` instead of `event.sender.send()` * Usage of `node::FreeEnvironment(env)` when the new option is enabled in order to avoid memory leaks. I have tested this quite a bit and haven't managed to cause a crash but it is still feature flagged behind the "nodeSupportInSubFrames" flag to avoid potential impact. Closes #10569 Closes #10401 Closes #11868 Closes #12505 Closes #14035
Co-Authored-By: MarshallOfSound <[email protected]>
1f3921f to
ad0f072
Compare
| })) | ||
| } | ||
|
|
||
| const wrapEventWithReply = (event) => { |
There was a problem hiding this comment.
these still don't "wrap" a thing?
There was a problem hiding this comment.
Ah right, will rename
|
Release Notes Persisted
|
* feat: add support for node / preloads in subframes This feature has delibrately been built / implemented in such a way that it has minimum impact on existing apps / code-paths. Without enabling the new "nodeSupportInSubFrames" option basically none of this new code will be hit. The things that I believe need extra scrutiny are: * Introduction of `event.reply` for IPC events and usage of `event.reply` instead of `event.sender.send()` * Usage of `node::FreeEnvironment(env)` when the new option is enabled in order to avoid memory leaks. I have tested this quite a bit and haven't managed to cause a crash but it is still feature flagged behind the "nodeSupportInSubFrames" flag to avoid potential impact. Closes #10569 Closes #10401 Closes #11868 Closes #12505 Closes #14035 * feat: add support preloads in subframes for sandboxed renderers * spec: add tests for new nodeSupportInSubFrames option * spec: fix specs for .reply and ._replyInternal for internal messages * chore: revert change to use flag instead of environment set size * chore: clean up subframe impl * chore: apply suggestions from code review Co-Authored-By: MarshallOfSound <[email protected]> * chore: clean up reply usage * chore: fix TS docs generation * chore: cleanup after rebase * chore: rename wrap to add in event fns
* feat: add support for node / preloads in subframes This feature has delibrately been built / implemented in such a way that it has minimum impact on existing apps / code-paths. Without enabling the new "nodeSupportInSubFrames" option basically none of this new code will be hit. The things that I believe need extra scrutiny are: * Introduction of `event.reply` for IPC events and usage of `event.reply` instead of `event.sender.send()` * Usage of `node::FreeEnvironment(env)` when the new option is enabled in order to avoid memory leaks. I have tested this quite a bit and haven't managed to cause a crash but it is still feature flagged behind the "nodeSupportInSubFrames" flag to avoid potential impact. Closes #10569 Closes #10401 Closes #11868 Closes #12505 Closes #14035 * feat: add support preloads in subframes for sandboxed renderers * spec: add tests for new nodeSupportInSubFrames option * spec: fix specs for .reply and ._replyInternal for internal messages * chore: revert change to use flag instead of environment set size * chore: clean up subframe impl * chore: apply suggestions from code review Co-Authored-By: MarshallOfSound <[email protected]> * chore: clean up reply usage * chore: fix TS docs generation * chore: cleanup after rebase * chore: rename wrap to add in event fns
|
|
Could the |
|
I answer the question myself. Here is the electron/lib/browser/api/web-contents.js Lines 287 to 289 in e78b902 So yes Here is how the error looks if there is no |
Description of Change
This adds support for running preload scripts and nodeIntegration in sub-frames (iframes)
Checklist
npm testpassesRelease Notes
Notes: Added support for running preload scripts and nodeIntegration in iframes