Implement initial, experimental BrowserView API
Right now, `<webview>` is the only way to embed additional content in a
`BrowserWindow`. Unfortunately `<webview>` suffers from a [number of
problems](https://github.com/electron/electron/issues?utf8=%E2%9C%93&q=is%3Aissue%20is%3Aopen%20label%3Awebview%20).
To make matters worse, many of these are upstream Chromium bugs instead
of Electron-specific bugs.
For us at [Figma](https://www.figma.com), the main issue is very slow
performance.
Despite the upstream improvements to `<webview>` through the OOPIF work, it is
probable that there will continue to be `<webview>`-specific bugs in the
future.
Therefore, this introduces a `<webview>` alternative to called `BrowserView`,
which...
- is a thin wrapper around `api::WebContents` (so bugs in `BrowserView` will
likely also be bugs in `BrowserWindow` web contents)
- is instantiated in the main process like `BrowserWindow` (and unlike
`<webview>`, which lives in the DOM of a `BrowserWindow` web contents)
- needs to be added to a `BrowserWindow` to display something on the screen
This implements the most basic API. The API is expected to evolve and change in
the near future and has consequently been marked as experimental. Please do not
use this API in production unless you are prepared to deal with breaking
changes.
In the future, we will want to change the API to support multiple
`BrowserView`s per window. We will also want to consider z-ordering
auto-resizing, and possibly even nested views.
2017-04-11 17:47:30 +00:00
|
|
|
'use strict'
|
|
|
|
|
2018-06-17 22:56:04 +00:00
|
|
|
const chai = require('chai')
|
2018-11-08 15:57:28 +00:00
|
|
|
const ChildProcess = require('child_process')
|
2018-06-17 22:56:04 +00:00
|
|
|
const dirtyChai = require('dirty-chai')
|
2018-11-08 15:57:28 +00:00
|
|
|
const path = require('path')
|
|
|
|
const { emittedOnce } = require('./events-helpers')
|
2018-09-13 16:10:51 +00:00
|
|
|
const { closeWindow } = require('./window-helpers')
|
Implement initial, experimental BrowserView API
Right now, `<webview>` is the only way to embed additional content in a
`BrowserWindow`. Unfortunately `<webview>` suffers from a [number of
problems](https://github.com/electron/electron/issues?utf8=%E2%9C%93&q=is%3Aissue%20is%3Aopen%20label%3Awebview%20).
To make matters worse, many of these are upstream Chromium bugs instead
of Electron-specific bugs.
For us at [Figma](https://www.figma.com), the main issue is very slow
performance.
Despite the upstream improvements to `<webview>` through the OOPIF work, it is
probable that there will continue to be `<webview>`-specific bugs in the
future.
Therefore, this introduces a `<webview>` alternative to called `BrowserView`,
which...
- is a thin wrapper around `api::WebContents` (so bugs in `BrowserView` will
likely also be bugs in `BrowserWindow` web contents)
- is instantiated in the main process like `BrowserWindow` (and unlike
`<webview>`, which lives in the DOM of a `BrowserWindow` web contents)
- needs to be added to a `BrowserWindow` to display something on the screen
This implements the most basic API. The API is expected to evolve and change in
the near future and has consequently been marked as experimental. Please do not
use this API in production unless you are prepared to deal with breaking
changes.
In the future, we will want to change the API to support multiple
`BrowserView`s per window. We will also want to consider z-ordering
auto-resizing, and possibly even nested views.
2017-04-11 17:47:30 +00:00
|
|
|
|
2018-09-13 16:10:51 +00:00
|
|
|
const { remote } = require('electron')
|
|
|
|
const { BrowserView, BrowserWindow } = remote
|
Implement initial, experimental BrowserView API
Right now, `<webview>` is the only way to embed additional content in a
`BrowserWindow`. Unfortunately `<webview>` suffers from a [number of
problems](https://github.com/electron/electron/issues?utf8=%E2%9C%93&q=is%3Aissue%20is%3Aopen%20label%3Awebview%20).
To make matters worse, many of these are upstream Chromium bugs instead
of Electron-specific bugs.
For us at [Figma](https://www.figma.com), the main issue is very slow
performance.
Despite the upstream improvements to `<webview>` through the OOPIF work, it is
probable that there will continue to be `<webview>`-specific bugs in the
future.
Therefore, this introduces a `<webview>` alternative to called `BrowserView`,
which...
- is a thin wrapper around `api::WebContents` (so bugs in `BrowserView` will
likely also be bugs in `BrowserWindow` web contents)
- is instantiated in the main process like `BrowserWindow` (and unlike
`<webview>`, which lives in the DOM of a `BrowserWindow` web contents)
- needs to be added to a `BrowserWindow` to display something on the screen
This implements the most basic API. The API is expected to evolve and change in
the near future and has consequently been marked as experimental. Please do not
use this API in production unless you are prepared to deal with breaking
changes.
In the future, we will want to change the API to support multiple
`BrowserView`s per window. We will also want to consider z-ordering
auto-resizing, and possibly even nested views.
2017-04-11 17:47:30 +00:00
|
|
|
|
2018-09-13 16:10:51 +00:00
|
|
|
const { expect } = chai
|
2018-06-17 22:56:04 +00:00
|
|
|
chai.use(dirtyChai)
|
|
|
|
|
2017-10-27 00:11:12 +00:00
|
|
|
describe('BrowserView module', () => {
|
2018-11-27 01:39:03 +00:00
|
|
|
const fixtures = path.resolve(__dirname, 'fixtures')
|
|
|
|
|
2017-10-27 00:05:15 +00:00
|
|
|
let w = null
|
|
|
|
let view = null
|
Implement initial, experimental BrowserView API
Right now, `<webview>` is the only way to embed additional content in a
`BrowserWindow`. Unfortunately `<webview>` suffers from a [number of
problems](https://github.com/electron/electron/issues?utf8=%E2%9C%93&q=is%3Aissue%20is%3Aopen%20label%3Awebview%20).
To make matters worse, many of these are upstream Chromium bugs instead
of Electron-specific bugs.
For us at [Figma](https://www.figma.com), the main issue is very slow
performance.
Despite the upstream improvements to `<webview>` through the OOPIF work, it is
probable that there will continue to be `<webview>`-specific bugs in the
future.
Therefore, this introduces a `<webview>` alternative to called `BrowserView`,
which...
- is a thin wrapper around `api::WebContents` (so bugs in `BrowserView` will
likely also be bugs in `BrowserWindow` web contents)
- is instantiated in the main process like `BrowserWindow` (and unlike
`<webview>`, which lives in the DOM of a `BrowserWindow` web contents)
- needs to be added to a `BrowserWindow` to display something on the screen
This implements the most basic API. The API is expected to evolve and change in
the near future and has consequently been marked as experimental. Please do not
use this API in production unless you are prepared to deal with breaking
changes.
In the future, we will want to change the API to support multiple
`BrowserView`s per window. We will also want to consider z-ordering
auto-resizing, and possibly even nested views.
2017-04-11 17:47:30 +00:00
|
|
|
|
2017-10-27 00:05:15 +00:00
|
|
|
beforeEach(() => {
|
Implement initial, experimental BrowserView API
Right now, `<webview>` is the only way to embed additional content in a
`BrowserWindow`. Unfortunately `<webview>` suffers from a [number of
problems](https://github.com/electron/electron/issues?utf8=%E2%9C%93&q=is%3Aissue%20is%3Aopen%20label%3Awebview%20).
To make matters worse, many of these are upstream Chromium bugs instead
of Electron-specific bugs.
For us at [Figma](https://www.figma.com), the main issue is very slow
performance.
Despite the upstream improvements to `<webview>` through the OOPIF work, it is
probable that there will continue to be `<webview>`-specific bugs in the
future.
Therefore, this introduces a `<webview>` alternative to called `BrowserView`,
which...
- is a thin wrapper around `api::WebContents` (so bugs in `BrowserView` will
likely also be bugs in `BrowserWindow` web contents)
- is instantiated in the main process like `BrowserWindow` (and unlike
`<webview>`, which lives in the DOM of a `BrowserWindow` web contents)
- needs to be added to a `BrowserWindow` to display something on the screen
This implements the most basic API. The API is expected to evolve and change in
the near future and has consequently been marked as experimental. Please do not
use this API in production unless you are prepared to deal with breaking
changes.
In the future, we will want to change the API to support multiple
`BrowserView`s per window. We will also want to consider z-ordering
auto-resizing, and possibly even nested views.
2017-04-11 17:47:30 +00:00
|
|
|
w = new BrowserWindow({
|
|
|
|
show: false,
|
|
|
|
width: 400,
|
|
|
|
height: 400,
|
|
|
|
webPreferences: {
|
|
|
|
backgroundThrottling: false
|
|
|
|
}
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
2017-10-27 00:05:15 +00:00
|
|
|
afterEach(() => {
|
2017-04-12 21:52:07 +00:00
|
|
|
if (view) {
|
|
|
|
view.destroy()
|
|
|
|
view = null
|
|
|
|
}
|
|
|
|
|
2017-10-27 00:05:15 +00:00
|
|
|
return closeWindow(w).then(() => { w = null })
|
Implement initial, experimental BrowserView API
Right now, `<webview>` is the only way to embed additional content in a
`BrowserWindow`. Unfortunately `<webview>` suffers from a [number of
problems](https://github.com/electron/electron/issues?utf8=%E2%9C%93&q=is%3Aissue%20is%3Aopen%20label%3Awebview%20).
To make matters worse, many of these are upstream Chromium bugs instead
of Electron-specific bugs.
For us at [Figma](https://www.figma.com), the main issue is very slow
performance.
Despite the upstream improvements to `<webview>` through the OOPIF work, it is
probable that there will continue to be `<webview>`-specific bugs in the
future.
Therefore, this introduces a `<webview>` alternative to called `BrowserView`,
which...
- is a thin wrapper around `api::WebContents` (so bugs in `BrowserView` will
likely also be bugs in `BrowserWindow` web contents)
- is instantiated in the main process like `BrowserWindow` (and unlike
`<webview>`, which lives in the DOM of a `BrowserWindow` web contents)
- needs to be added to a `BrowserWindow` to display something on the screen
This implements the most basic API. The API is expected to evolve and change in
the near future and has consequently been marked as experimental. Please do not
use this API in production unless you are prepared to deal with breaking
changes.
In the future, we will want to change the API to support multiple
`BrowserView`s per window. We will also want to consider z-ordering
auto-resizing, and possibly even nested views.
2017-04-11 17:47:30 +00:00
|
|
|
})
|
|
|
|
|
2018-03-15 07:15:56 +00:00
|
|
|
describe('BrowserView.destroy()', () => {
|
|
|
|
it('does not throw', () => {
|
|
|
|
view = new BrowserView()
|
|
|
|
view.destroy()
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
|
|
|
describe('BrowserView.isDestroyed()', () => {
|
|
|
|
it('returns correct value', () => {
|
|
|
|
view = new BrowserView()
|
2018-06-17 22:56:04 +00:00
|
|
|
expect(view.isDestroyed()).to.be.false()
|
2018-03-15 07:15:56 +00:00
|
|
|
view.destroy()
|
2018-06-17 22:56:04 +00:00
|
|
|
expect(view.isDestroyed()).to.be.true()
|
2018-03-15 07:15:56 +00:00
|
|
|
})
|
|
|
|
})
|
|
|
|
|
2017-10-27 00:05:15 +00:00
|
|
|
describe('BrowserView.setBackgroundColor()', () => {
|
|
|
|
it('does not throw for valid args', () => {
|
2017-04-12 21:52:07 +00:00
|
|
|
view = new BrowserView()
|
Implement initial, experimental BrowserView API
Right now, `<webview>` is the only way to embed additional content in a
`BrowserWindow`. Unfortunately `<webview>` suffers from a [number of
problems](https://github.com/electron/electron/issues?utf8=%E2%9C%93&q=is%3Aissue%20is%3Aopen%20label%3Awebview%20).
To make matters worse, many of these are upstream Chromium bugs instead
of Electron-specific bugs.
For us at [Figma](https://www.figma.com), the main issue is very slow
performance.
Despite the upstream improvements to `<webview>` through the OOPIF work, it is
probable that there will continue to be `<webview>`-specific bugs in the
future.
Therefore, this introduces a `<webview>` alternative to called `BrowserView`,
which...
- is a thin wrapper around `api::WebContents` (so bugs in `BrowserView` will
likely also be bugs in `BrowserWindow` web contents)
- is instantiated in the main process like `BrowserWindow` (and unlike
`<webview>`, which lives in the DOM of a `BrowserWindow` web contents)
- needs to be added to a `BrowserWindow` to display something on the screen
This implements the most basic API. The API is expected to evolve and change in
the near future and has consequently been marked as experimental. Please do not
use this API in production unless you are prepared to deal with breaking
changes.
In the future, we will want to change the API to support multiple
`BrowserView`s per window. We will also want to consider z-ordering
auto-resizing, and possibly even nested views.
2017-04-11 17:47:30 +00:00
|
|
|
view.setBackgroundColor('#000')
|
|
|
|
})
|
|
|
|
|
2017-10-27 00:05:15 +00:00
|
|
|
it('throws for invalid args', () => {
|
2017-04-12 21:52:07 +00:00
|
|
|
view = new BrowserView()
|
2018-06-17 22:56:04 +00:00
|
|
|
expect(() => {
|
Implement initial, experimental BrowserView API
Right now, `<webview>` is the only way to embed additional content in a
`BrowserWindow`. Unfortunately `<webview>` suffers from a [number of
problems](https://github.com/electron/electron/issues?utf8=%E2%9C%93&q=is%3Aissue%20is%3Aopen%20label%3Awebview%20).
To make matters worse, many of these are upstream Chromium bugs instead
of Electron-specific bugs.
For us at [Figma](https://www.figma.com), the main issue is very slow
performance.
Despite the upstream improvements to `<webview>` through the OOPIF work, it is
probable that there will continue to be `<webview>`-specific bugs in the
future.
Therefore, this introduces a `<webview>` alternative to called `BrowserView`,
which...
- is a thin wrapper around `api::WebContents` (so bugs in `BrowserView` will
likely also be bugs in `BrowserWindow` web contents)
- is instantiated in the main process like `BrowserWindow` (and unlike
`<webview>`, which lives in the DOM of a `BrowserWindow` web contents)
- needs to be added to a `BrowserWindow` to display something on the screen
This implements the most basic API. The API is expected to evolve and change in
the near future and has consequently been marked as experimental. Please do not
use this API in production unless you are prepared to deal with breaking
changes.
In the future, we will want to change the API to support multiple
`BrowserView`s per window. We will also want to consider z-ordering
auto-resizing, and possibly even nested views.
2017-04-11 17:47:30 +00:00
|
|
|
view.setBackgroundColor(null)
|
2018-06-17 22:56:04 +00:00
|
|
|
}).to.throw(/conversion failure/)
|
Implement initial, experimental BrowserView API
Right now, `<webview>` is the only way to embed additional content in a
`BrowserWindow`. Unfortunately `<webview>` suffers from a [number of
problems](https://github.com/electron/electron/issues?utf8=%E2%9C%93&q=is%3Aissue%20is%3Aopen%20label%3Awebview%20).
To make matters worse, many of these are upstream Chromium bugs instead
of Electron-specific bugs.
For us at [Figma](https://www.figma.com), the main issue is very slow
performance.
Despite the upstream improvements to `<webview>` through the OOPIF work, it is
probable that there will continue to be `<webview>`-specific bugs in the
future.
Therefore, this introduces a `<webview>` alternative to called `BrowserView`,
which...
- is a thin wrapper around `api::WebContents` (so bugs in `BrowserView` will
likely also be bugs in `BrowserWindow` web contents)
- is instantiated in the main process like `BrowserWindow` (and unlike
`<webview>`, which lives in the DOM of a `BrowserWindow` web contents)
- needs to be added to a `BrowserWindow` to display something on the screen
This implements the most basic API. The API is expected to evolve and change in
the near future and has consequently been marked as experimental. Please do not
use this API in production unless you are prepared to deal with breaking
changes.
In the future, we will want to change the API to support multiple
`BrowserView`s per window. We will also want to consider z-ordering
auto-resizing, and possibly even nested views.
2017-04-11 17:47:30 +00:00
|
|
|
})
|
|
|
|
})
|
|
|
|
|
2017-10-27 00:05:15 +00:00
|
|
|
describe('BrowserView.setAutoResize()', () => {
|
|
|
|
it('does not throw for valid args', () => {
|
2017-04-12 21:52:07 +00:00
|
|
|
view = new BrowserView()
|
2017-04-12 11:40:31 +00:00
|
|
|
view.setAutoResize({})
|
|
|
|
view.setAutoResize({ width: true, height: false })
|
|
|
|
})
|
|
|
|
|
2017-10-27 00:05:15 +00:00
|
|
|
it('throws for invalid args', () => {
|
2017-04-12 21:52:07 +00:00
|
|
|
view = new BrowserView()
|
2018-06-17 22:56:04 +00:00
|
|
|
expect(() => {
|
2017-04-12 11:40:31 +00:00
|
|
|
view.setAutoResize(null)
|
2018-06-17 22:56:04 +00:00
|
|
|
}).to.throw(/conversion failure/)
|
2017-04-12 11:40:31 +00:00
|
|
|
})
|
|
|
|
})
|
|
|
|
|
2017-10-27 00:05:15 +00:00
|
|
|
describe('BrowserView.setBounds()', () => {
|
|
|
|
it('does not throw for valid args', () => {
|
2017-04-12 21:52:07 +00:00
|
|
|
view = new BrowserView()
|
Implement initial, experimental BrowserView API
Right now, `<webview>` is the only way to embed additional content in a
`BrowserWindow`. Unfortunately `<webview>` suffers from a [number of
problems](https://github.com/electron/electron/issues?utf8=%E2%9C%93&q=is%3Aissue%20is%3Aopen%20label%3Awebview%20).
To make matters worse, many of these are upstream Chromium bugs instead
of Electron-specific bugs.
For us at [Figma](https://www.figma.com), the main issue is very slow
performance.
Despite the upstream improvements to `<webview>` through the OOPIF work, it is
probable that there will continue to be `<webview>`-specific bugs in the
future.
Therefore, this introduces a `<webview>` alternative to called `BrowserView`,
which...
- is a thin wrapper around `api::WebContents` (so bugs in `BrowserView` will
likely also be bugs in `BrowserWindow` web contents)
- is instantiated in the main process like `BrowserWindow` (and unlike
`<webview>`, which lives in the DOM of a `BrowserWindow` web contents)
- needs to be added to a `BrowserWindow` to display something on the screen
This implements the most basic API. The API is expected to evolve and change in
the near future and has consequently been marked as experimental. Please do not
use this API in production unless you are prepared to deal with breaking
changes.
In the future, we will want to change the API to support multiple
`BrowserView`s per window. We will also want to consider z-ordering
auto-resizing, and possibly even nested views.
2017-04-11 17:47:30 +00:00
|
|
|
view.setBounds({ x: 0, y: 0, width: 1, height: 1 })
|
|
|
|
})
|
|
|
|
|
2017-10-27 00:05:15 +00:00
|
|
|
it('throws for invalid args', () => {
|
2017-04-12 21:52:07 +00:00
|
|
|
view = new BrowserView()
|
2018-06-17 22:56:04 +00:00
|
|
|
expect(() => {
|
Implement initial, experimental BrowserView API
Right now, `<webview>` is the only way to embed additional content in a
`BrowserWindow`. Unfortunately `<webview>` suffers from a [number of
problems](https://github.com/electron/electron/issues?utf8=%E2%9C%93&q=is%3Aissue%20is%3Aopen%20label%3Awebview%20).
To make matters worse, many of these are upstream Chromium bugs instead
of Electron-specific bugs.
For us at [Figma](https://www.figma.com), the main issue is very slow
performance.
Despite the upstream improvements to `<webview>` through the OOPIF work, it is
probable that there will continue to be `<webview>`-specific bugs in the
future.
Therefore, this introduces a `<webview>` alternative to called `BrowserView`,
which...
- is a thin wrapper around `api::WebContents` (so bugs in `BrowserView` will
likely also be bugs in `BrowserWindow` web contents)
- is instantiated in the main process like `BrowserWindow` (and unlike
`<webview>`, which lives in the DOM of a `BrowserWindow` web contents)
- needs to be added to a `BrowserWindow` to display something on the screen
This implements the most basic API. The API is expected to evolve and change in
the near future and has consequently been marked as experimental. Please do not
use this API in production unless you are prepared to deal with breaking
changes.
In the future, we will want to change the API to support multiple
`BrowserView`s per window. We will also want to consider z-ordering
auto-resizing, and possibly even nested views.
2017-04-11 17:47:30 +00:00
|
|
|
view.setBounds(null)
|
2018-06-17 22:56:04 +00:00
|
|
|
}).to.throw(/conversion failure/)
|
|
|
|
expect(() => {
|
Implement initial, experimental BrowserView API
Right now, `<webview>` is the only way to embed additional content in a
`BrowserWindow`. Unfortunately `<webview>` suffers from a [number of
problems](https://github.com/electron/electron/issues?utf8=%E2%9C%93&q=is%3Aissue%20is%3Aopen%20label%3Awebview%20).
To make matters worse, many of these are upstream Chromium bugs instead
of Electron-specific bugs.
For us at [Figma](https://www.figma.com), the main issue is very slow
performance.
Despite the upstream improvements to `<webview>` through the OOPIF work, it is
probable that there will continue to be `<webview>`-specific bugs in the
future.
Therefore, this introduces a `<webview>` alternative to called `BrowserView`,
which...
- is a thin wrapper around `api::WebContents` (so bugs in `BrowserView` will
likely also be bugs in `BrowserWindow` web contents)
- is instantiated in the main process like `BrowserWindow` (and unlike
`<webview>`, which lives in the DOM of a `BrowserWindow` web contents)
- needs to be added to a `BrowserWindow` to display something on the screen
This implements the most basic API. The API is expected to evolve and change in
the near future and has consequently been marked as experimental. Please do not
use this API in production unless you are prepared to deal with breaking
changes.
In the future, we will want to change the API to support multiple
`BrowserView`s per window. We will also want to consider z-ordering
auto-resizing, and possibly even nested views.
2017-04-11 17:47:30 +00:00
|
|
|
view.setBounds({})
|
2018-06-17 22:56:04 +00:00
|
|
|
}).to.throw(/conversion failure/)
|
Implement initial, experimental BrowserView API
Right now, `<webview>` is the only way to embed additional content in a
`BrowserWindow`. Unfortunately `<webview>` suffers from a [number of
problems](https://github.com/electron/electron/issues?utf8=%E2%9C%93&q=is%3Aissue%20is%3Aopen%20label%3Awebview%20).
To make matters worse, many of these are upstream Chromium bugs instead
of Electron-specific bugs.
For us at [Figma](https://www.figma.com), the main issue is very slow
performance.
Despite the upstream improvements to `<webview>` through the OOPIF work, it is
probable that there will continue to be `<webview>`-specific bugs in the
future.
Therefore, this introduces a `<webview>` alternative to called `BrowserView`,
which...
- is a thin wrapper around `api::WebContents` (so bugs in `BrowserView` will
likely also be bugs in `BrowserWindow` web contents)
- is instantiated in the main process like `BrowserWindow` (and unlike
`<webview>`, which lives in the DOM of a `BrowserWindow` web contents)
- needs to be added to a `BrowserWindow` to display something on the screen
This implements the most basic API. The API is expected to evolve and change in
the near future and has consequently been marked as experimental. Please do not
use this API in production unless you are prepared to deal with breaking
changes.
In the future, we will want to change the API to support multiple
`BrowserView`s per window. We will also want to consider z-ordering
auto-resizing, and possibly even nested views.
2017-04-11 17:47:30 +00:00
|
|
|
})
|
|
|
|
})
|
|
|
|
|
2017-10-27 00:05:15 +00:00
|
|
|
describe('BrowserWindow.setBrowserView()', () => {
|
|
|
|
it('does not throw for valid args', () => {
|
2017-04-12 21:52:07 +00:00
|
|
|
view = new BrowserView()
|
Implement initial, experimental BrowserView API
Right now, `<webview>` is the only way to embed additional content in a
`BrowserWindow`. Unfortunately `<webview>` suffers from a [number of
problems](https://github.com/electron/electron/issues?utf8=%E2%9C%93&q=is%3Aissue%20is%3Aopen%20label%3Awebview%20).
To make matters worse, many of these are upstream Chromium bugs instead
of Electron-specific bugs.
For us at [Figma](https://www.figma.com), the main issue is very slow
performance.
Despite the upstream improvements to `<webview>` through the OOPIF work, it is
probable that there will continue to be `<webview>`-specific bugs in the
future.
Therefore, this introduces a `<webview>` alternative to called `BrowserView`,
which...
- is a thin wrapper around `api::WebContents` (so bugs in `BrowserView` will
likely also be bugs in `BrowserWindow` web contents)
- is instantiated in the main process like `BrowserWindow` (and unlike
`<webview>`, which lives in the DOM of a `BrowserWindow` web contents)
- needs to be added to a `BrowserWindow` to display something on the screen
This implements the most basic API. The API is expected to evolve and change in
the near future and has consequently been marked as experimental. Please do not
use this API in production unless you are prepared to deal with breaking
changes.
In the future, we will want to change the API to support multiple
`BrowserView`s per window. We will also want to consider z-ordering
auto-resizing, and possibly even nested views.
2017-04-11 17:47:30 +00:00
|
|
|
w.setBrowserView(view)
|
|
|
|
})
|
|
|
|
|
2017-10-27 00:05:15 +00:00
|
|
|
it('does not throw if called multiple times with same view', () => {
|
2017-04-12 21:52:07 +00:00
|
|
|
view = new BrowserView()
|
Implement initial, experimental BrowserView API
Right now, `<webview>` is the only way to embed additional content in a
`BrowserWindow`. Unfortunately `<webview>` suffers from a [number of
problems](https://github.com/electron/electron/issues?utf8=%E2%9C%93&q=is%3Aissue%20is%3Aopen%20label%3Awebview%20).
To make matters worse, many of these are upstream Chromium bugs instead
of Electron-specific bugs.
For us at [Figma](https://www.figma.com), the main issue is very slow
performance.
Despite the upstream improvements to `<webview>` through the OOPIF work, it is
probable that there will continue to be `<webview>`-specific bugs in the
future.
Therefore, this introduces a `<webview>` alternative to called `BrowserView`,
which...
- is a thin wrapper around `api::WebContents` (so bugs in `BrowserView` will
likely also be bugs in `BrowserWindow` web contents)
- is instantiated in the main process like `BrowserWindow` (and unlike
`<webview>`, which lives in the DOM of a `BrowserWindow` web contents)
- needs to be added to a `BrowserWindow` to display something on the screen
This implements the most basic API. The API is expected to evolve and change in
the near future and has consequently been marked as experimental. Please do not
use this API in production unless you are prepared to deal with breaking
changes.
In the future, we will want to change the API to support multiple
`BrowserView`s per window. We will also want to consider z-ordering
auto-resizing, and possibly even nested views.
2017-04-11 17:47:30 +00:00
|
|
|
w.setBrowserView(view)
|
|
|
|
w.setBrowserView(view)
|
|
|
|
w.setBrowserView(view)
|
|
|
|
})
|
|
|
|
})
|
2017-06-21 23:21:28 +00:00
|
|
|
|
2017-10-27 18:44:41 +00:00
|
|
|
describe('BrowserWindow.getBrowserView()', () => {
|
|
|
|
it('returns the set view', () => {
|
|
|
|
view = new BrowserView()
|
|
|
|
w.setBrowserView(view)
|
2018-06-17 22:56:04 +00:00
|
|
|
expect(view.id).to.not.be.null()
|
|
|
|
|
2018-10-02 01:56:31 +00:00
|
|
|
const view2 = w.getBrowserView()
|
2018-06-17 22:56:04 +00:00
|
|
|
expect(view2.webContents.id).to.equal(view.webContents.id)
|
2017-10-27 18:44:41 +00:00
|
|
|
})
|
|
|
|
|
|
|
|
it('returns null if none is set', () => {
|
2018-10-02 01:56:31 +00:00
|
|
|
const view = w.getBrowserView()
|
2018-06-17 22:56:04 +00:00
|
|
|
expect(view).to.be.null()
|
2017-10-27 18:44:41 +00:00
|
|
|
})
|
|
|
|
})
|
|
|
|
|
2018-12-22 01:49:26 +00:00
|
|
|
describe('BrowserWindow.addBrowserView()', () => {
|
|
|
|
it('does not throw for valid args', () => {
|
|
|
|
let view1 = new BrowserView()
|
|
|
|
w.addBrowserView(view1)
|
|
|
|
let view2 = new BrowserView()
|
|
|
|
w.addBrowserView(view2)
|
|
|
|
view1.destroy()
|
|
|
|
view1 = null
|
|
|
|
view2.destroy()
|
|
|
|
view2 = null
|
|
|
|
})
|
|
|
|
it('does not throw if called multiple times with same view', () => {
|
|
|
|
view = new BrowserView()
|
|
|
|
w.addBrowserView(view)
|
|
|
|
w.addBrowserView(view)
|
|
|
|
w.addBrowserView(view)
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
|
|
|
describe('BrowserWindow.removeBrowserView()', () => {
|
|
|
|
it('does not throw if called multiple times with same view', () => {
|
|
|
|
view = new BrowserView()
|
|
|
|
w.addBrowserView(view)
|
|
|
|
w.removeBrowserView(view)
|
|
|
|
w.removeBrowserView(view)
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
|
|
|
describe('BrowserWindow.getBrowserViews()', () => {
|
|
|
|
it('returns same views as was added', () => {
|
|
|
|
let view1 = new BrowserView()
|
|
|
|
w.addBrowserView(view1)
|
|
|
|
let view2 = new BrowserView()
|
|
|
|
w.addBrowserView(view2)
|
|
|
|
|
|
|
|
expect(view1.id).to.be.not.null()
|
|
|
|
const views = w.getBrowserViews()
|
2019-05-20 17:04:18 +00:00
|
|
|
expect(views).to.have.lengthOf(2)
|
2018-12-22 01:49:26 +00:00
|
|
|
expect(views[0].webContents.id).to.equal(view1.webContents.id)
|
|
|
|
expect(views[1].webContents.id).to.equal(view2.webContents.id)
|
|
|
|
|
|
|
|
view1.destroy()
|
|
|
|
view1 = null
|
|
|
|
view2.destroy()
|
|
|
|
view2 = null
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
2017-10-27 00:05:15 +00:00
|
|
|
describe('BrowserView.webContents.getOwnerBrowserWindow()', () => {
|
|
|
|
it('points to owning window', () => {
|
2017-06-21 23:21:28 +00:00
|
|
|
view = new BrowserView()
|
2018-06-17 22:56:04 +00:00
|
|
|
expect(view.webContents.getOwnerBrowserWindow()).to.be.null()
|
|
|
|
|
2017-06-21 23:21:28 +00:00
|
|
|
w.setBrowserView(view)
|
2018-06-17 22:56:04 +00:00
|
|
|
expect(view.webContents.getOwnerBrowserWindow()).to.equal(w)
|
|
|
|
|
2017-06-21 23:21:28 +00:00
|
|
|
w.setBrowserView(null)
|
2018-06-17 22:56:04 +00:00
|
|
|
expect(view.webContents.getOwnerBrowserWindow()).to.be.null()
|
2017-06-21 23:21:28 +00:00
|
|
|
})
|
|
|
|
})
|
2017-07-24 03:32:30 +00:00
|
|
|
|
2017-10-27 00:05:15 +00:00
|
|
|
describe('BrowserView.fromId()', () => {
|
|
|
|
it('returns the view with given id', () => {
|
2017-07-24 03:32:30 +00:00
|
|
|
view = new BrowserView()
|
|
|
|
w.setBrowserView(view)
|
2018-06-17 22:56:04 +00:00
|
|
|
expect(view.id).to.not.be.null()
|
|
|
|
|
2018-10-02 01:56:31 +00:00
|
|
|
const view2 = BrowserView.fromId(view.id)
|
2018-06-17 22:56:04 +00:00
|
|
|
expect(view2.webContents.id).to.equal(view.webContents.id)
|
2017-07-24 03:32:30 +00:00
|
|
|
})
|
|
|
|
})
|
2017-11-23 01:06:14 +00:00
|
|
|
|
|
|
|
describe('BrowserView.fromWebContents()', () => {
|
|
|
|
it('returns the view with given id', () => {
|
|
|
|
view = new BrowserView()
|
|
|
|
w.setBrowserView(view)
|
2018-06-17 22:56:04 +00:00
|
|
|
expect(view.id).to.not.be.null()
|
|
|
|
|
2018-10-02 01:56:31 +00:00
|
|
|
const view2 = BrowserView.fromWebContents(view.webContents)
|
2018-06-17 22:56:04 +00:00
|
|
|
expect(view2.webContents.id).to.equal(view.webContents.id)
|
2017-11-23 01:06:14 +00:00
|
|
|
})
|
|
|
|
})
|
|
|
|
|
|
|
|
describe('BrowserView.getAllViews()', () => {
|
|
|
|
it('returns all views', () => {
|
|
|
|
view = new BrowserView()
|
|
|
|
w.setBrowserView(view)
|
2018-06-17 22:56:04 +00:00
|
|
|
expect(view.id).to.not.be.null()
|
2017-11-23 01:06:14 +00:00
|
|
|
|
|
|
|
const views = BrowserView.getAllViews()
|
2018-06-17 22:56:04 +00:00
|
|
|
expect(views).to.be.an('array').that.has.lengthOf(1)
|
|
|
|
expect(views[0].webContents.id).to.equal(view.webContents.id)
|
2017-11-23 01:06:14 +00:00
|
|
|
})
|
|
|
|
})
|
2018-11-08 15:57:28 +00:00
|
|
|
|
|
|
|
describe('new BrowserView()', () => {
|
|
|
|
it('does not crash on exit', async () => {
|
2018-11-27 01:39:03 +00:00
|
|
|
const appPath = path.join(fixtures, 'api', 'leak-exit-browserview.js')
|
2018-11-08 15:57:28 +00:00
|
|
|
const electronPath = remote.getGlobal('process').execPath
|
|
|
|
const appProcess = ChildProcess.spawn(electronPath, [appPath])
|
|
|
|
const [code] = await emittedOnce(appProcess, 'close')
|
|
|
|
expect(code).to.equal(0)
|
|
|
|
})
|
|
|
|
})
|
2018-11-27 01:39:03 +00:00
|
|
|
|
|
|
|
describe('window.open()', () => {
|
|
|
|
it('works in BrowserView', (done) => {
|
|
|
|
view = new BrowserView()
|
|
|
|
w.setBrowserView(view)
|
|
|
|
view.webContents.once('new-window', (e, url, frameName, disposition, options, additionalFeatures) => {
|
|
|
|
e.preventDefault()
|
2019-05-20 17:04:18 +00:00
|
|
|
expect(url).to.equal('http://host/')
|
|
|
|
expect(frameName).to.equal('host')
|
|
|
|
expect(additionalFeatures[0]).to.equal('this-is-not-a-standard-feature')
|
2018-11-27 01:39:03 +00:00
|
|
|
done()
|
|
|
|
})
|
|
|
|
view.webContents.loadFile(path.join(fixtures, 'pages', 'window-open.html'))
|
|
|
|
})
|
|
|
|
})
|
Implement initial, experimental BrowserView API
Right now, `<webview>` is the only way to embed additional content in a
`BrowserWindow`. Unfortunately `<webview>` suffers from a [number of
problems](https://github.com/electron/electron/issues?utf8=%E2%9C%93&q=is%3Aissue%20is%3Aopen%20label%3Awebview%20).
To make matters worse, many of these are upstream Chromium bugs instead
of Electron-specific bugs.
For us at [Figma](https://www.figma.com), the main issue is very slow
performance.
Despite the upstream improvements to `<webview>` through the OOPIF work, it is
probable that there will continue to be `<webview>`-specific bugs in the
future.
Therefore, this introduces a `<webview>` alternative to called `BrowserView`,
which...
- is a thin wrapper around `api::WebContents` (so bugs in `BrowserView` will
likely also be bugs in `BrowserWindow` web contents)
- is instantiated in the main process like `BrowserWindow` (and unlike
`<webview>`, which lives in the DOM of a `BrowserWindow` web contents)
- needs to be added to a `BrowserWindow` to display something on the screen
This implements the most basic API. The API is expected to evolve and change in
the near future and has consequently been marked as experimental. Please do not
use this API in production unless you are prepared to deal with breaking
changes.
In the future, we will want to change the API to support multiple
`BrowserView`s per window. We will also want to consider z-ordering
auto-resizing, and possibly even nested views.
2017-04-11 17:47:30 +00:00
|
|
|
})
|