fix: <webview> not working with Trusted Types (#27445)
This commit is contained in:
parent
949fd0728f
commit
4a5c5843c4
3 changed files with 22 additions and 4 deletions
|
@ -44,7 +44,9 @@ export class WebViewImpl {
|
||||||
// Create internal iframe element.
|
// Create internal iframe element.
|
||||||
this.internalElement = this.createInternalElement();
|
this.internalElement = this.createInternalElement();
|
||||||
const shadowRoot = this.webviewNode.attachShadow({ mode: 'open' });
|
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.setupWebViewAttributes();
|
||||||
this.viewInstanceId = getNextId();
|
this.viewInstanceId = getNextId();
|
||||||
shadowRoot.appendChild(this.internalElement);
|
shadowRoot.appendChild(this.internalElement);
|
||||||
|
|
|
@ -63,7 +63,6 @@ describe('<webview> tag', function () {
|
||||||
show: false,
|
show: false,
|
||||||
webPreferences: {
|
webPreferences: {
|
||||||
webviewTag: true,
|
webviewTag: true,
|
||||||
nodeIntegration: true,
|
|
||||||
sandbox: true
|
sandbox: true
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
@ -76,7 +75,6 @@ describe('<webview> tag', function () {
|
||||||
show: false,
|
show: false,
|
||||||
webPreferences: {
|
webPreferences: {
|
||||||
webviewTag: true,
|
webviewTag: true,
|
||||||
nodeIntegration: true,
|
|
||||||
contextIsolation: true
|
contextIsolation: true
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
@ -89,7 +87,6 @@ describe('<webview> tag', function () {
|
||||||
show: false,
|
show: false,
|
||||||
webPreferences: {
|
webPreferences: {
|
||||||
webviewTag: true,
|
webviewTag: true,
|
||||||
nodeIntegration: true,
|
|
||||||
contextIsolation: true,
|
contextIsolation: true,
|
||||||
sandbox: true
|
sandbox: true
|
||||||
}
|
}
|
||||||
|
@ -98,6 +95,17 @@ describe('<webview> tag', function () {
|
||||||
await emittedOnce(ipcMain, 'pong');
|
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 () => {
|
it('is disabled by default', async () => {
|
||||||
const w = new BrowserWindow({
|
const w = new BrowserWindow({
|
||||||
show: false,
|
show: false,
|
||||||
|
|
8
spec/fixtures/pages/webview-trusted-types.html
vendored
Normal file
8
spec/fixtures/pages/webview-trusted-types.html
vendored
Normal file
|
@ -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>
|
Loading…
Reference in a new issue