chore: update to standard 12
This commit is contained in:
parent
9e85bdb02c
commit
558fff69e7
198 changed files with 4455 additions and 2940 deletions
|
@ -10,9 +10,9 @@ You can also access the `session` of existing pages by using the `session`
|
|||
property of [`WebContents`](web-contents.md), or from the `session` module.
|
||||
|
||||
```javascript
|
||||
const {BrowserWindow} = require('electron')
|
||||
const { BrowserWindow } = require('electron')
|
||||
|
||||
let win = new BrowserWindow({width: 800, height: 600})
|
||||
let win = new BrowserWindow({ width: 800, height: 600 })
|
||||
win.loadURL('http://github.com')
|
||||
|
||||
const ses = win.webContents.session
|
||||
|
@ -59,7 +59,7 @@ Process: [Main](../glossary.md#main-process)
|
|||
You can create a `Session` object in the `session` module:
|
||||
|
||||
```javascript
|
||||
const {session} = require('electron')
|
||||
const { session } = require('electron')
|
||||
const ses = session.fromPartition('persist:name')
|
||||
console.log(ses.getUserAgent())
|
||||
```
|
||||
|
@ -80,7 +80,7 @@ Calling `event.preventDefault()` will cancel the download and `item` will not be
|
|||
available from next tick of the process.
|
||||
|
||||
```javascript
|
||||
const {session} = require('electron')
|
||||
const { session } = require('electron')
|
||||
session.defaultSession.on('will-download', (event, item, webContents) => {
|
||||
event.preventDefault()
|
||||
require('request')(item.getURL(), (data) => {
|
||||
|
@ -239,7 +239,7 @@ window.webContents.session.enableNetworkEmulation({
|
|||
})
|
||||
|
||||
// To emulate a network outage.
|
||||
window.webContents.session.enableNetworkEmulation({offline: true})
|
||||
window.webContents.session.enableNetworkEmulation({ offline: true })
|
||||
```
|
||||
|
||||
#### `ses.disableNetworkEmulation()`
|
||||
|
@ -272,11 +272,11 @@ Calling `setCertificateVerifyProc(null)` will revert back to default certificate
|
|||
verify proc.
|
||||
|
||||
```javascript
|
||||
const {BrowserWindow} = require('electron')
|
||||
const { BrowserWindow } = require('electron')
|
||||
let win = new BrowserWindow()
|
||||
|
||||
win.webContents.session.setCertificateVerifyProc((request, callback) => {
|
||||
const {hostname} = request
|
||||
const { hostname } = request
|
||||
if (hostname === 'github.com') {
|
||||
callback(0)
|
||||
} else {
|
||||
|
@ -303,7 +303,7 @@ Calling `callback(true)` will allow the permission and `callback(false)` will re
|
|||
To clear the handler, call `setPermissionRequestHandler(null)`.
|
||||
|
||||
```javascript
|
||||
const {session} = require('electron')
|
||||
const { session } = require('electron')
|
||||
session.fromPartition('some-partition').setPermissionRequestHandler((webContents, permission, callback) => {
|
||||
if (webContents.getURL() === 'some-host' && permission === 'notifications') {
|
||||
return callback(false) // denied.
|
||||
|
@ -329,7 +329,7 @@ Returning `true` will allow the permission and `false` will reject it.
|
|||
To clear the handler, call `setPermissionCheckHandler(null)`.
|
||||
|
||||
```javascript
|
||||
const {session} = require('electron')
|
||||
const { session } = require('electron')
|
||||
session.fromPartition('some-partition').setPermissionCheckHandler((webContents, permission) => {
|
||||
if (webContents.getURL() === 'some-host' && permission === 'notifications') {
|
||||
return false // denied
|
||||
|
@ -354,7 +354,7 @@ Dynamically sets whether to always send credentials for HTTP NTLM or Negotiate
|
|||
authentication.
|
||||
|
||||
```javascript
|
||||
const {session} = require('electron')
|
||||
const { session } = require('electron')
|
||||
// consider any url ending with `example.com`, `foobar.com`, `baz`
|
||||
// for integrated authentication.
|
||||
session.defaultSession.allowNTLMCredentialsForDomains('*example.com, *foobar.com, *baz')
|
||||
|
@ -441,14 +441,14 @@ A [WebRequest](web-request.md) object for this session.
|
|||
A [Protocol](protocol.md) object for this session.
|
||||
|
||||
```javascript
|
||||
const {app, session} = require('electron')
|
||||
const { app, session } = require('electron')
|
||||
const path = require('path')
|
||||
|
||||
app.on('ready', function () {
|
||||
const protocol = session.fromPartition('some-partition').protocol
|
||||
protocol.registerFileProtocol('atom', function (request, callback) {
|
||||
var url = request.url.substr(7)
|
||||
callback({path: path.normalize(`${__dirname}/${url}`)})
|
||||
callback({ path: path.normalize(`${__dirname}/${url}`) })
|
||||
}, function (error) {
|
||||
if (error) console.error('Failed to register protocol')
|
||||
})
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue