New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: preloads and nodeIntegration in iframes #16425
Conversation
@@ -26,7 +26,7 @@ | |||
const { defineProperty, defineProperties } = Object | |||
|
|||
// Helper function to resolve relative url. | |||
const a = window.top.document.createElement('a') | |||
const a = window.document.createElement('a') | |||
const resolveURL = function (url) { | |||
a.href = url | |||
return a.href |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice work!
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 <samuel.r.attard@gmail.com>
1f3921f
to
ad0f072
Compare
lib/browser/api/web-contents.js
Outdated
@@ -330,6 +342,22 @@ WebContents.prototype.loadFile = function (filePath, options = {}) { | |||
})) | |||
} | |||
|
|||
const wrapEventWithReply = (event) => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
these still don't "wrap" a thing?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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 <samuel.r.attard@gmail.com> * 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 <samuel.r.attard@gmail.com> * 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 test
passesRelease Notes
Notes: Added support for running preload scripts and nodeIntegration in iframes