8000 fix: <webview> not working with Trusted Types by trop[bot] · Pull Request #27464 · electron/electron · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

fix: <webview> not working with Trusted Types #27464

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

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion lib/renderer/web-view/web-view-impl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,9 @@ export class WebViewImpl {
// Create internal iframe element.
this.internalElement = this.createInternalElement();
const shadowRoot = this.webviewNode.attachShadow({ mode: 'open' });
shadowRoot.innerHTML = '<!DOCTYPE html><style type="text/css">:host { display: flex; }</style>';
const style = shadowRoot.ownerDocument.createElement('style');
style.textContent = ':host { display: flex; }';
shadowRoot.appendChild(style);
this.setupWebViewAttributes();
this.viewInstanceId = getNextId();
shadowRoot.appendChild(this.internalElement);
Expand Down
14 changes: 11 additions & 3 deletions spec-main/webview-spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,6 @@ describe('<webview> tag', function () {
show: false,
webPreferences: {
webviewTag: true,
nodeIntegration: true,
sandbox: true
}
});
Expand All @@ -76,7 +75,6 @@ describe('<webview> tag', function () {
show: false,
webPreferences: {
webviewTag: true,
nodeIntegration: true,
contextIsolation: true
}
});
Expand All @@ -89,7 +87,6 @@ describe('<webview> tag', function () {
show: false,
webPreferences: {
webviewTag: true,
nodeIntegration: true,
contextIsolation: true,
sandbox: true
}
Expand All @@ -98,6 +95,17 @@ describe('<webview> tag', function () {
await emittedOnce(ipcMain, 'pong');
});

it('works with Trusted Types', async () => {
const w = new BrowserWindow({
show: false,
webPreferences: {
webviewTag: true
}
});
w.loadFile(path.join(fixtures, 'pages', 'webview-trusted-types.html'));
await emittedOnce(ipcMain, 'pong');
});

it('is disabled by default', async () => {
const w = new BrowserWindow({
show: false,
Expand Down
8 changes: 8 additions & 0 deletions spec/fixtures/pages/webview-trusted-types.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<html>
<head>
<meta http-equiv="Content-Security-Policy" content="require-trusted-types-for 'script'; trusted-types *">
</head>
<body>
<webview preload="../module/isolated-ping.js" src="about:blank"/>
</body>
</html>
0