Browse Source

fix: webview.focus() should move page focus to webview (#14427)

Cheng Zhao 6 years ago
parent
commit
10176c71ff
2 changed files with 7 additions and 1 deletions
  1. 5 0
      lib/renderer/web-view/web-view.js
  2. 2 1
      spec/webview-spec.js

+ 5 - 0
lib/renderer/web-view/web-view.js

@@ -366,6 +366,11 @@ const registerWebViewElement = function () {
     return internal.webContents
   }
 
+  // Focusing the webview should move page focus to the underlying iframe.
+  proto.focus = function () {
+    this.contentWindow.focus()
+  }
+
   window.WebView = webFrame.registerEmbedderCustomElement('webview', {
     prototype: proto
   })

+ 2 - 1
spec/webview-spec.js

@@ -1302,8 +1302,9 @@ describe('<webview> tag', function () {
 
       await domReadySignal
 
+      // If this test fails, check if webview.focus() still works.
       const focusSignal = waitForEvent(webview, 'focus')
-      webview.contentWindow.focus()
+      webview.focus()
 
       await focusSignal
     })