From e0a65e7330d37c01193193de072422d5a1f1c79d Mon Sep 17 00:00:00 2001 From: Milan Burda Date: Fri, 25 Jun 2021 22:33:33 +0200 Subject: [PATCH] docs: add 'did-attach' event documentation --- docs/api/webview-tag.md | 4 ++++ spec-main/webview-spec.ts | 20 ++++++++++++++++++++ 2 files changed, 24 insertions(+) diff --git a/docs/api/webview-tag.md b/docs/api/webview-tag.md index d6a4c2b657f33..b1317fc6d015d 100644 --- a/docs/api/webview-tag.md +++ b/docs/api/webview-tag.md @@ -718,6 +718,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. +### Event: 'did-attach' + +Fired when attached to the embedder web contents. + ### Event: 'dom-ready' Fired when document in the given frame is loaded. diff --git a/spec-main/webview-spec.ts b/spec-main/webview-spec.ts index 5d576e48e2623..ef5e21c8e6edf 100644 --- a/spec-main/webview-spec.ts +++ b/spec-main/webview-spec.ts @@ -184,6 +184,26 @@ describe(' 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', () => { it('emits when theme color changes', async () => { const w = new BrowserWindow({