docs: add <webview> 'did-attach' event documentation (#29899)

This commit is contained in:
Milan Burda 2021-07-14 13:59:20 +02:00 committed by GitHub
parent 637ba48b42
commit c0995b8dff
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 24 additions and 0 deletions

View file

@ -710,6 +710,10 @@ Corresponds to the points in time when the spinner of the tab starts spinning.
Corresponds to the points in time when the spinner of the tab stops spinning. Corresponds to the points in time when the spinner of the tab stops spinning.
### Event: 'did-attach'
Fired when attached to the embedder web contents.
### Event: 'dom-ready' ### Event: 'dom-ready'
Fired when document in the given frame is loaded. Fired when document in the given frame is loaded.

View file

@ -182,6 +182,26 @@ describe('<webview> tag', function () {
}); });
}); });
describe('did-attach event', () => {
it('is emitted when a webview has been attached', async () => {
const w = new BrowserWindow({
webPreferences: {
webviewTag: true
}
});
await w.loadURL('about:blank');
const message = await w.webContents.executeJavaScript(`new Promise((resolve, reject) => {
const webview = new WebView()
webview.setAttribute('src', 'about:blank')
webview.addEventListener('did-attach', (e) => {
resolve('ok')
})
document.body.appendChild(webview)
})`);
expect(message).to.equal('ok');
});
});
describe('did-change-theme-color event', () => { describe('did-change-theme-color event', () => {
it('emits when theme color changes', async () => { it('emits when theme color changes', async () => {
const w = new BrowserWindow({ const w = new BrowserWindow({