Skip to main content

ServiceWorkerMain

表示给定范围的脚本版本的服务工作线程实例。

¥An instance of a Service Worker representing a version of a script for a given scope.

进程:主进程

¥Process: Main

类:ServiceWorkerMain

¥Class: ServiceWorkerMain

进程:主进程
该类不是从 'electron' 模块导出的。它仅可用作 Electron API 中其他方法的返回值。

¥Process: Main
This class is not exported from the 'electron' module. It is only available as a return value of other methods in the Electron API.

实例方法

¥Instance Methods

serviceWorker.isDestroyed() 实验性的

¥serviceWorker.isDestroyed() Experimental

返回 boolean - 服务工作者是否已被销毁。

¥Returns boolean - Whether the service worker has been destroyed.

serviceWorker.send(channel, ...args) 实验性的

¥serviceWorker.send(channel, ...args) Experimental

  • channel 字符串

    ¥channel string

  • ...args 任何[]

    ¥...args any[]

通过 channel 向服务工作线程进程发送异步消息以及参数。参数将与 结构化克隆算法 一起序列化,就像 postMessage 一样,因此不会包含原型链。发送函数、Promise、Symbols、WeakMap 或 WeakSet 将引发异常。

¥Send an asynchronous message to the service worker process via channel, along with arguments. Arguments will be serialized with the Structured Clone Algorithm, just like postMessage, so prototype chains will not be included. Sending Functions, Promises, Symbols, WeakMaps, or WeakSets will throw an exception.

服务工作线程进程可以通过使用 ipcRenderer 模块监听 channel 来处理消息。

¥The service worker process can handle the message by listening to channel with the ipcRenderer module.

serviceWorker.startTask() 实验性的

¥serviceWorker.startTask() Experimental

返回 Object

¥Returns Object:

  • end 函数 - 任务结束时调用的方法。如果从未调用,服务将不会在空闲时终止。

    ¥end Function - Method to call when the task has ended. If never called, the service won't terminate while otherwise idle.

启动任务以保持服务工作线程处于活动状态直到结束。

¥Initiate a task to keep the service worker alive until ended.

实例属性

¥Instance Properties

serviceWorker.ipc 只读实验

¥serviceWorker.ipc Readonly Experimental

范围限定为服务工作线程的 IpcMainServiceWorker 实例。

¥An IpcMainServiceWorker instance scoped to the service worker.

serviceWorker.scope 只读实验

¥serviceWorker.scope Readonly Experimental

string 表示服务工作线程的范围 URL。

¥A string representing the scope URL of the service worker.

serviceWorker.scriptURL 只读实验

¥serviceWorker.scriptURL Readonly Experimental

一个表示 Service Worker 脚本 URL 的 string 函数。

¥A string representing the script URL of the service worker.

serviceWorker.versionId 只读实验

¥serviceWorker.versionId Readonly Experimental

number 表示服务工作线程脚本在其范围内的特定版本的 ID。

¥A number representing the ID of the specific version of the service worker script in its scope.