- webContents·续5
- contents.enableDeviceEmulation(parameters)
- contents.disableDeviceEmulation()
- contents.sendInputEvent(inputEvent)
- contents.beginFrameSubscription([onlyDirty ,]callback)
- contents.endFrameSubscription()
- contents.startDrag(item)
- contents.savePage(fullPath, saveType)
- contents.showDefinitionForSelection() macOS
- contents.isOffscreen()
- contents.startPainting()
- contents.stopPainting()
- contents.isPainting()
- contents.setFrameRate(fps)
- contents.getFrameRate()
- contents.invalidate()
- contents.getWebRTCIPHandlingPolicy()
- contents.setWebRTCIPHandlingPolicy(policy)
- contents.getOSProcessId()
- contents.getProcessId()
- contents.takeHeapSnapshot(filePath)
- contents.setBackgroundThrottling(allowed)
- contents.getType()
- 实例属性
webContents·续5
You can also read frameId from all incoming IPC messages in the main process.
// In the main processipcMain.on('ping', (event) => { console.info('Message came from frameId:', event.frameId)})
contents.enableDeviceEmulation(parameters)
-
parameters Object
-
screenPosition String - Specify the screen type to emulate (default: desktop):
-
desktop - Desktop screen type.
-
mobile - Mobile screen type.
-
screenSize Size - Set the emulated screen size (screenPosition == mobile).
-
viewPosition Point - Position the view on the screen (screenPosition == mobile) (default: { x: 0, y: 0 }).
-
deviceScaleFactor Integer - Set the device scale factor (if zero defaults to original device scale factor) (default: 0).
-
viewSize Size - Set the emulated view size (empty means no override)
-
scale Float - Scale of emulated view inside available space (not in fit to view mode) (default: 1).
允许设备模拟给定参数。
contents.disableDeviceEmulation()
禁止webContents.enableDeviceEmulation允许的模拟设备
contents.sendInputEvent(inputEvent)
- inputEvent MouseInputEvent | MouseWheelInputEvent | KeyboardInputEvent
Sends an input event to the page. Note: The BrowserWindow containing the contents needs to be focused for sendInputEvent() to work.
contents.beginFrameSubscription([onlyDirty ,]callback)
-
onlyDirty Boolean (可选) - 默认值为 false.
-
callback Function
-
image NativeImage
-
dirtyRect Rectangle
Begin subscribing for presentation events and captured frames, the callback will be called with callback(image, dirtyRect) when there is a presentation event.
The image is an instance of NativeImage that stores the captured frame.
The dirtyRect is an object with x, y, width, height properties that describes which part of the page was repainted. If onlyDirty is set to true, image will only contain the repainted area. onlyDirty defaults to false.
contents.endFrameSubscription()
End subscribing for frame presentation events.
contents.startDrag(item)
-
item Object
-
file String[] | String - The path(s) to the file(s) being dragged.
-
icon NativeImage | String - The image must be non-empty on macOS.
Sets the item as dragging item for current drag-drop operation, file is the absolute path of the file to be dragged, and icon is the image showing under the cursor when dragging.
contents.savePage(fullPath, saveType)
-
fullPath String - The full file path.
-
saveType String - Specify the save type.
-
HTMLOnly - Save only the HTML of the page.
-
HTMLComplete - Save complete-html page.
-
MHTML - Save complete-html page as MHTML.
Returns Promise<void> - resolves if the page is saved.
const { BrowserWindow } = require('electron')let win = new BrowserWindow()win.loadURL('https://github.com')win.webContents.on('did-finish-load', async () => { win.webContents.savePage('/tmp/test.html', 'HTMLComplete').then(() => { console.log('Page was saved successfully.') }).catch(err => { console.log(err) })})
contents.showDefinitionForSelection() macOS
Shows pop-up dictionary that searches the selected word on the page.
contents.isOffscreen()
Returns Boolean - Indicates whether offscreen rendering is enabled.
contents.startPainting()
If offscreen rendering is enabled and not painting, start painting.
contents.stopPainting()
If offscreen rendering is enabled and painting, stop painting.
contents.isPainting()
Returns Boolean - If offscreen rendering is enabled returns whether it is currently painting.
contents.setFrameRate(fps)
- fps Integer
If offscreen rendering is enabled sets the frame rate to the specified number. Only values between 1 and 60 are accepted.
过时的
contents.getFrameRate()
Returns Integer - If offscreen rendering is enabled returns the current frame rate.
过时的
contents.invalidate()
Schedules a full repaint of the window this web contents is in.
If offscreen rendering is enabled invalidates the frame and generates a new one through the 'paint' event.
contents.getWebRTCIPHandlingPolicy()
Returns String - Returns the WebRTC IP Handling Policy.
contents.setWebRTCIPHandlingPolicy(policy)
-
policy String - Specify the WebRTC IP Handling Policy.
-
default - Exposes user’s public and local IPs. This is the default behavior. When this policy is used, WebRTC has the right to enumerate all interfaces and bind them to discover public interfaces.
-
default_public_interface_only - Exposes user’s public IP, but does not expose user’s local IP. When this policy is used, WebRTC should only use the default route used by http. This doesn’t expose any local addresses.
-
default_public_and_private_interfaces - Exposes user’s public and local IPs. When this policy is used, WebRTC should only use the default route used by http. This also exposes the associated default private address. Default route is the route chosen by the OS on a multi-homed endpoint.
-
disable_non_proxied_udp - Does not expose public or local IPs. When this policy is used, WebRTC should only use TCP to contact peers or servers unless the proxy server supports UDP.
Setting the WebRTC IP handling policy allows you to control which IPs are exposed via WebRTC. See BrowserLeaks for more details.
contents.getOSProcessId()
Returns Integer - The operating system pid of the associated renderer process.
contents.getProcessId()
Returns Integer - The Chromium internal pid of the associated renderer. Can be compared to the frameProcessId passed by frame specific navigation events (e.g. did-frame-navigate)
contents.takeHeapSnapshot(filePath)
- filePath String - Path to the output file.
Returns Promise<void> - Indicates whether the snapshot has been created successfully.
Takes a V8 heap snapshot and saves it to filePath.
contents.setBackgroundThrottling(allowed)
- allowed Boolean
Controls whether or not this WebContents will throttle animations and timers when the page becomes backgrounded. This also affects the Page Visibility API.
contents.getType()
Returns String - the type of the webContent. Can be backgroundPage, window, browserView, remote, webview or offscreen.
实例属性
contents.audioMuted
A Boolean property that determines whether this page is muted.
contents.userAgent
A String property that determines the user agent for this web page.
contents.zoomLevel
A Number property that determines the zoom level for this web contents.
The original size is 0 and each increment above or below represents zooming 20% larger or smaller to default limits of 300% and 50% of original size, respectively. The formula for this is scale := 1.2 ^ level.
contents.zoomFactor
A Number property that determines the zoom factor for this web contents.
The zoom factor is the zoom percent divided by 100, so 300% = 3.0.
contents.frameRate
An Integer property that sets the frame rate of the web contents to the specified number. Only values between 1 and 60 are accepted.
Only applicable if offscreen rendering is enabled.
contents.id Readonly
Integer类型,代表WebContents的唯一标识(unique ID)。
contents.session Readonly
A Session used by this webContents.
contents.hostWebContents Readonly
A WebContents instance that might own this WebContents.
contents.devToolsWebContents Readonly
A WebContents | null property that represents the of DevTools WebContents associated with a given WebContents.
Note: Users should never store this object because it may become null when the DevTools has been closed.
contents.debugger Readonly
A Debugger instance for this webContents.
