📝 Update API documentation to ES6 [ci skip]

This commit is contained in:
Steve Kinney 2016-05-04 11:59:02 -06:00
parent 178496afe5
commit 5a9f28e034
28 changed files with 168 additions and 176 deletions

View file

@ -9,12 +9,12 @@ property of [`webContents`](web-contents.md) which is a property of
[`BrowserWindow`](browser-window.md).
```javascript
const BrowserWindow = require('electron').BrowserWindow;
const { BrowserWindow } = require('electron');
var win = new BrowserWindow({ width: 800, height: 600 });
let win = new BrowserWindow({ width: 800, height: 600 });
win.loadURL("http://github.com");
var ses = win.webContents.session;
const ses = win.webContents.session;
```
## Methods
@ -47,7 +47,7 @@ You can create a `Session` object in the `session` module:
```javascript
const session = require('electron').session;
var ses = session.fromPartition('persist:name');
const ses = session.fromPartition('persist:name');
```
### Instance Events
@ -66,9 +66,9 @@ Calling `event.preventDefault()` will cancel the download and `item` will not be
available from next tick of the process.
```javascript
session.defaultSession.on('will-download', function(event, item, webContents) {
session.defaultSession.on('will-download', (event, item, webContents) => {
event.preventDefault();
require('request')(item.getURL(), function(data) {
require('request')(item.getURL(), (data) => {
require('fs').writeFileSync('/somewhere', data);
});
});
@ -84,19 +84,19 @@ The `cookies` gives you ability to query and modify cookies. For example:
```javascript
// Query all cookies.
session.defaultSession.cookies.get({}, function(error, cookies) {
session.defaultSession.cookies.get({}, (error, cookies) => {
console.log(cookies);
});
// Query all cookies associated with a specific url.
session.defaultSession.cookies.get({ url : "http://www.github.com" }, function(error, cookies) {
session.defaultSession.cookies.get({ url : "http://www.github.com" }, (error, cookies) => {
console.log(cookies);
});
// Set a cookie with the given cookie data;
// may overwrite equivalent cookies if they exist.
var cookie = { url : "http://www.github.com", name : "dummy_name", value : "dummy" };
session.defaultSession.cookies.set(cookie, function(error) {
const cookie = { url : "http://www.github.com", name : "dummy_name", value : "dummy" };
session.defaultSession.cookies.set(cookie, (error) => {
if (error)
console.error(error);
});
@ -285,8 +285,8 @@ Calling `setCertificateVerifyProc(null)` will revert back to default certificate
verify proc.
```javascript
myWindow.webContents.session.setCertificateVerifyProc(function(hostname, cert, callback) {
if (hostname == 'github.com')
myWindow.webContents.session.setCertificateVerifyProc((hostname, cert, callback) => {
if (hostname === 'github.com')
callback(true);
else
callback(false);
@ -305,9 +305,9 @@ Sets the handler which can be used to respond to permission requests for the `se
Calling `callback(true)` will allow the permission and `callback(false)` will reject it.
```javascript
session.fromPartition(partition).setPermissionRequestHandler(function(webContents, permission, callback) {
session.fromPartition(partition).setPermissionRequestHandler((webContents, permission, callback) => {
if (webContents.getURL() === host) {
if (permission == "notifications") {
if (permission === "notifications") {
callback(false); // denied.
return;
}
@ -342,11 +342,11 @@ called with an `response` object when `listener` has done its work.
```javascript
// Modify the user agent for all requests to the following urls.
var filter = {
const filter = {
urls: ["https://*.github.com/*", "*://electron.github.io"]
};
session.defaultSession.webRequest.onBeforeSendHeaders(filter, function(details, callback) {
session.defaultSession.webRequest.onBeforeSendHeaders(filter, (details, callback) => {
details.requestHeaders['User-Agent'] = "MyAgent";
callback({cancel: false, requestHeaders: details.requestHeaders});
});