Merge remote-tracking branch 'upstream/master' into speedup-gpu
This commit is contained in:
commit
439ad94afe
85 changed files with 1592 additions and 757 deletions
|
@ -9,12 +9,13 @@ the [`BrowserWindow`](browser-window.md) object. An example of accessing the
|
|||
`webContents` object:
|
||||
|
||||
```javascript
|
||||
const {BrowserWindow} = require('electron');
|
||||
const {BrowserWindow} = require('electron')
|
||||
|
||||
let win = new BrowserWindow({width: 800, height: 1500});
|
||||
win.loadURL('http://github.com');
|
||||
let win = new BrowserWindow({width: 800, height: 1500})
|
||||
win.loadURL('http://github.com')
|
||||
|
||||
let contents = win.webContents;
|
||||
let contents = win.webContents
|
||||
console.log(contents)
|
||||
```
|
||||
|
||||
## Methods
|
||||
|
@ -22,7 +23,8 @@ let contents = win.webContents;
|
|||
These methods can be accessed from the `webContents` module:
|
||||
|
||||
```js
|
||||
const {webContents} = require('electron');
|
||||
const {webContents} = require('electron')
|
||||
console.log(webContents)
|
||||
```
|
||||
|
||||
### `webContents.getAllWebContents()`
|
||||
|
@ -437,6 +439,7 @@ first available device will be selected. `callback` should be called with
|
|||
cancel the request.
|
||||
|
||||
```javascript
|
||||
const {app, webContents} = require('electron')
|
||||
app.commandLine.appendSwitch('enable-web-bluetooth')
|
||||
|
||||
app.on('ready', () => {
|
||||
|
@ -508,8 +511,9 @@ e.g. the `http://` or `file://`. If the load should bypass http cache then
|
|||
use the `pragma` header to achieve it.
|
||||
|
||||
```javascript
|
||||
const options = {extraHeaders: 'pragma: no-cache\n'};
|
||||
webContents.loadURL(url, options);
|
||||
const {webContents} = require('electron')
|
||||
const options = {extraHeaders: 'pragma: no-cache\n'}
|
||||
webContents.loadURL('https://github.com', options)
|
||||
```
|
||||
|
||||
#### `contents.downloadURL(url)`
|
||||
|
@ -524,10 +528,12 @@ Initiates a download of the resource at `url` without navigating. The
|
|||
Returns URL of the current web page.
|
||||
|
||||
```javascript
|
||||
let win = new BrowserWindow({width: 800, height: 600});
|
||||
win.loadURL('http://github.com');
|
||||
const {BrowserWindow} = require('electron')
|
||||
let win = new BrowserWindow({width: 800, height: 600})
|
||||
win.loadURL('http://github.com')
|
||||
|
||||
let currentURL = win.webContents.getURL();
|
||||
let currentURL = win.webContents.getURL()
|
||||
console.log(currentURL)
|
||||
```
|
||||
|
||||
#### `contents.getTitle()`
|
||||
|
@ -661,6 +667,13 @@ Executes the editing command `cut` in web page.
|
|||
|
||||
Executes the editing command `copy` in web page.
|
||||
|
||||
### `contents.copyImageAt(x, y)`
|
||||
|
||||
* `x` Integer
|
||||
* `y` Integer
|
||||
|
||||
Copy the image at the given position to the clipboard.
|
||||
|
||||
#### `contents.paste()`
|
||||
|
||||
Executes the editing command `paste` in web page.
|
||||
|
@ -731,12 +744,13 @@ the request can be obtained by subscribing to
|
|||
Stops any `findInPage` request for the `webContents` with the provided `action`.
|
||||
|
||||
```javascript
|
||||
const {webContents} = require('electron')
|
||||
webContents.on('found-in-page', (event, result) => {
|
||||
if (result.finalUpdate)
|
||||
webContents.stopFindInPage('clearSelection');
|
||||
});
|
||||
if (result.finalUpdate) webContents.stopFindInPage('clearSelection')
|
||||
})
|
||||
|
||||
const requestId = webContents.findInPage('api');
|
||||
const requestId = webContents.findInPage('api')
|
||||
console.log(requestId)
|
||||
```
|
||||
|
||||
#### `contents.capturePage([rect, ]callback)`
|
||||
|
@ -802,7 +816,7 @@ The `callback` will be called with `callback(error, data)` on completion. The
|
|||
|
||||
By default, an empty `options` will be regarded as:
|
||||
|
||||
```javascript
|
||||
```
|
||||
{
|
||||
marginsType: 0,
|
||||
printBackground: false,
|
||||
|
@ -814,23 +828,22 @@ By default, an empty `options` will be regarded as:
|
|||
An example of `webContents.printToPDF`:
|
||||
|
||||
```javascript
|
||||
const {BrowserWindow} = require('electron');
|
||||
const fs = require('fs');
|
||||
const {BrowserWindow} = require('electron')
|
||||
const fs = require('fs')
|
||||
|
||||
let win = new BrowserWindow({width: 800, height: 600});
|
||||
win.loadURL('http://github.com');
|
||||
let win = new BrowserWindow({width: 800, height: 600})
|
||||
win.loadURL('http://github.com')
|
||||
|
||||
win.webContents.on('did-finish-load', () => {
|
||||
// Use default printing options
|
||||
win.webContents.printToPDF({}, (error, data) => {
|
||||
if (error) throw error;
|
||||
if (error) throw error
|
||||
fs.writeFile('/tmp/print.pdf', data, (error) => {
|
||||
if (error)
|
||||
throw error;
|
||||
console.log('Write PDF successfully.');
|
||||
});
|
||||
});
|
||||
});
|
||||
if (error) throw error
|
||||
console.log('Write PDF successfully.')
|
||||
})
|
||||
})
|
||||
})
|
||||
```
|
||||
|
||||
#### `contents.addWorkSpace(path)`
|
||||
|
@ -841,9 +854,11 @@ Adds the specified path to DevTools workspace. Must be used after DevTools
|
|||
creation:
|
||||
|
||||
```javascript
|
||||
const {BrowserWindow} = require('electron')
|
||||
let win = new BrowserWindow()
|
||||
win.webContents.on('devtools-opened', () => {
|
||||
win.webContents.addWorkSpace(__dirname);
|
||||
});
|
||||
win.webContents.addWorkSpace(__dirname)
|
||||
})
|
||||
```
|
||||
|
||||
#### `contents.removeWorkSpace(path)`
|
||||
|
@ -904,15 +919,16 @@ An example of sending messages from the main process to the renderer process:
|
|||
|
||||
```javascript
|
||||
// In the main process.
|
||||
let win = null;
|
||||
const {app, BrowserWindow} = require('electron')
|
||||
let win = null
|
||||
|
||||
app.on('ready', () => {
|
||||
win = new BrowserWindow({width: 800, height: 600});
|
||||
win.loadURL(`file://${__dirname}/index.html`);
|
||||
win = new BrowserWindow({width: 800, height: 600})
|
||||
win.loadURL(`file://${__dirname}/index.html`)
|
||||
win.webContents.on('did-finish-load', () => {
|
||||
win.webContents.send('ping', 'whoooooooh!');
|
||||
});
|
||||
});
|
||||
win.webContents.send('ping', 'whoooooooh!')
|
||||
})
|
||||
})
|
||||
```
|
||||
|
||||
```html
|
||||
|
@ -921,8 +937,8 @@ app.on('ready', () => {
|
|||
<body>
|
||||
<script>
|
||||
require('electron').ipcRenderer.on('ping', (event, message) => {
|
||||
console.log(message); // Prints "whoooooooh!"
|
||||
});
|
||||
console.log(message) // Prints 'whoooooooh!'
|
||||
})
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
|
@ -943,7 +959,7 @@ app.on('ready', () => {
|
|||
(screenPosition == mobile) (default: `{x: 0, y: 0}`)
|
||||
* `x` Integer - Set the x axis offset from top left corner
|
||||
* `y` Integer - Set the y axis offset from top left corner
|
||||
* `deviceScaleFactor` Integer - Set the device scale factor (if zero defaults to
|
||||
* `deviceScaleFactor` Float - Set the device scale factor (if zero defaults to
|
||||
original device scale factor) (default: `0`)
|
||||
* `viewSize` Object - Set the emulated view size (empty means no override)
|
||||
* `width` Integer - Set the emulated view width
|
||||
|
@ -1051,14 +1067,16 @@ the cursor when dragging.
|
|||
Returns true if the process of saving page has been initiated successfully.
|
||||
|
||||
```javascript
|
||||
win.loadURL('https://github.com');
|
||||
const {BrowserWindow} = require('electron')
|
||||
let win = new BrowserWindow()
|
||||
|
||||
win.loadURL('https://github.com')
|
||||
|
||||
win.webContents.on('did-finish-load', () => {
|
||||
win.webContents.savePage('/tmp/test.html', 'HTMLComplete', (error) => {
|
||||
if (!error)
|
||||
console.log('Save page successfully');
|
||||
});
|
||||
});
|
||||
if (!error) console.log('Save page successfully')
|
||||
})
|
||||
})
|
||||
```
|
||||
|
||||
#### `contents.showDefinitionForSelection()` _macOS_
|
||||
|
@ -1120,24 +1138,28 @@ Get the debugger instance for this webContents.
|
|||
Debugger API serves as an alternate transport for [remote debugging protocol][rdp].
|
||||
|
||||
```javascript
|
||||
const {BrowserWindow} = require('electron')
|
||||
let win = new BrowserWindow()
|
||||
|
||||
try {
|
||||
win.webContents.debugger.attach('1.1');
|
||||
} catch(err) {
|
||||
console.log('Debugger attach failed : ', err);
|
||||
};
|
||||
win.webContents.debugger.attach('1.1')
|
||||
} catch (err) {
|
||||
console.log('Debugger attach failed : ', err)
|
||||
}
|
||||
|
||||
win.webContents.debugger.on('detach', (event, reason) => {
|
||||
console.log('Debugger detached due to : ', reason);
|
||||
});
|
||||
console.log('Debugger detached due to : ', reason)
|
||||
})
|
||||
|
||||
win.webContents.debugger.on('message', (event, method, params) => {
|
||||
if (method === 'Network.requestWillBeSent') {
|
||||
if (params.request.url === 'https://www.github.com')
|
||||
win.webContents.debugger.detach();
|
||||
if (params.request.url === 'https://www.github.com') {
|
||||
win.webContents.debugger.detach()
|
||||
}
|
||||
}
|
||||
});
|
||||
})
|
||||
|
||||
win.webContents.debugger.sendCommand('Network.enable');
|
||||
win.webContents.debugger.sendCommand('Network.enable')
|
||||
```
|
||||
|
||||
### Instance Methods
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue