Skip to content

fix: don't execute preload scripts for internal <iframe> in <webview> when nodeIntegrationInSubFrames is enabled - #19260

Merged
zcbenz merged 1 commit into
masterfrom
miniak/webview-iframe-preload
Jul 17, 2019
Merged

zcbenz merged 1 commit into
masterfrom
miniak/webview-iframe-preload

Conversation

@miniak

@miniak miniak commented Jul 15, 2019 •

Copy link
Copy Markdown
Contributor

Description of Change

Fixes #18429.

The problem is that before the webContents is attached to the internal <iframe> inside of the <webview>, it's treated as a regular frame and the preload scripts are executed there.

Fix by checking v8Util.getHiddenValue(window.frameElement, 'internal') on context initialization, which is set by the <webview> implementation:

createInternalElement () {
const iframeElement = document.createElement('iframe')
iframeElement.style.flex = '1 1 auto'
iframeElement.style.width = '100%'
iframeElement.style.border = '0'
v8Util.setHiddenValue(iframeElement, 'internal', this)
return iframeElement
}

Checklist

Release Notes

Notes: Preload scripts for internal <iframe> in <webview> are not longer executed when nodeIntegrationInSubFrames is enabled.

@miniak miniak self-assigned this Jul 15, 2019
@electron-cation electron-cation Bot added the new-pr 🌱 PR opened recently label Jul 15, 2019
Comment thread shell/renderer/atom_renderer_client.cc Resolved
Comment thread shell/renderer/atom_renderer_client.cc Resolved
@miniak
miniak force-pushed the miniak/webview-iframe-preload branch 3 times, most recently from 5c37424 to 894703c Compare July 15, 2019 19:19
@miniak
miniak requested a review from MarshallOfSound July 15, 2019 19:30
@miniak
miniak force-pushed the miniak/webview-iframe-preload branch from 894703c to 6b19def Compare July 15, 2019 22:22
@miniak miniak changed the title fix: don't execute preload scripts for internal <iframe> in <webview> fix: don't execute preload scripts for internal <iframe> in <webview> when nodeIntegrationInSubFrames is enabled Jul 15, 2019
@miniak
miniak force-pushed the miniak/webview-iframe-preload branch 2 times, most recently from 6e41c14 to 756f6eb Compare July 15, 2019 23:20
@zcbenz

zcbenz commented Jul 16, 2019

Copy link
Copy Markdown
Contributor

The test is failing on Windows CI:

not ok 515 renderer nodeIntegrationInSubFrames with context isolation, webview on should correctly reply to the sub-frames with using event.reply
23533  Error: Timeout of 30000ms exceeded. For async tests and hooks, ensure "done()" is called; if returning a Promise, ensure it resolves. (C:\projects\src\electron\spec\api-subframe-spec.js)
23534      at Test.Runnable._timeoutError (C:\projects\src\electron\spec\node_modules\mocha\lib\runnable.js:440:10)
23535      at C:\projects\src\electron\spec\node_modules\mocha\lib\runnable.js:251:24
23536

@miniak
miniak force-pushed the miniak/webview-iframe-preload branch 3 times, most recently from c521176 to 4f1dcea Compare July 16, 2019 13:15
@miniak
miniak force-pushed the miniak/webview-iframe-preload branch from 4f1dcea to 1597f25 Compare July 16, 2019 13:29
@miniak

miniak commented Jul 16, 2019

Copy link
Copy Markdown
Contributor Author

@zcbenz I've fixed the tests

@electron-cation electron-cation Bot removed the new-pr 🌱 PR opened recently label Jul 16, 2019
@zcbenz
zcbenz merged commit d1c9f5e into master Jul 17, 2019
@release-clerk

release-clerk Bot commented Jul 17, 2019

Copy link
Copy Markdown

Release Notes Persisted

Preload scripts for internal <iframe> in <webview> are not longer executed when nodeIntegrationInSubFrames is enabled.

@zcbenz
zcbenz deleted the miniak/webview-iframe-preload branch July 17, 2019 00:13
@trop

trop Bot commented Jul 17, 2019

Copy link
Copy Markdown
Contributor

I was unable to backport this PR to "5-0-x" cleanly;
you will need to perform this backport manually.

@trop

trop Bot commented Jul 17, 2019

Copy link
Copy Markdown
Contributor

I was unable to backport this PR to "6-0-x" cleanly;
you will need to perform this backport manually.

@trop

trop Bot commented Jul 17, 2019

Copy link
Copy Markdown
Contributor

A maintainer has manually backported this PR to "6-0-x", please check out #19298

@trop

trop Bot commented Jul 17, 2019

Copy link
Copy Markdown
Contributor

A maintainer has manually backported this PR to "5-0-x", please check out #19299

@KochiyaOcean

KochiyaOcean commented Jul 17, 2019 •

Copy link
Copy Markdown

https://github.com/electron/electron/blob/master/docs/api/webview-tag.md#nodeintegrationinsubframes
The document still says All your preloads will load for every iframe. Is that behavior no longer occurs after this commit?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

nodeIntegrationInSubFrames webview attribute causes preload script to run multiple times

5 participants