Browse Source

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

Co-authored-by: Milan Burda <[email protected]>
trop[bot] 3 years ago
parent
commit
d98b2a760c
2 changed files with 24 additions and 0 deletions
  1. 4 0
      docs/api/webview-tag.md
  2. 20 0
      spec-main/webview-spec.ts

+ 4 - 0
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.

+ 20 - 0
spec-main/webview-spec.ts

@@ -184,6 +184,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', () => {
     it('emits when theme color changes', async () => {
       const w = new BrowserWindow({