Browse Source

fix: set setter of window.location

Cheng Zhao 6 years ago
parent
commit
fc4e10b6c0
2 changed files with 12 additions and 2 deletions
  1. 11 1
      lib/renderer/window-setup.js
  2. 1 1
      spec/chromium-spec.js

+ 11 - 1
lib/renderer/window-setup.js

@@ -103,7 +103,17 @@ function LocationProxy (ipcRenderer, guestId) {
 
 function BrowserWindowProxy (ipcRenderer, guestId) {
   this.closed = false
-  this.location = new LocationProxy(ipcRenderer, guestId)
+
+  const location = new LocationProxy(ipcRenderer, guestId)
+  defineProperty(this, 'location', {
+    get: function () {
+      return location
+    },
+    set: function (url) {
+      url = resolveURL(url)
+      return ipcRenderer.sendSync('ELECTRON_GUEST_WINDOW_MANAGER_WEB_CONTENTS_METHOD_SYNC', guestId, 'loadURL', url)
+    }
+  })
 
   ipcRenderer.once(`ELECTRON_GUEST_WINDOW_MANAGER_WINDOW_CLOSED_${guestId}`, () => {
     removeProxy(guestId)

+ 1 - 1
spec/chromium-spec.js

@@ -515,7 +515,7 @@ describe('chromium feature', () => {
       }
       app.once('browser-window-created', (event, window) => {
         window.webContents.once('did-finish-load', () => {
-          assert.strictEqual(b.location, targetURL)
+          assert.strictEqual(b.location.href, targetURL)
           b.close()
           done()
         })