-
Notifications
You must be signed in to change notification settings - Fork 16.2k
feat: service worker preload scripts for improved extensions support #44411
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
module.exports = require('./webpack.config.base')({ | ||
target: 'preload_realm', | ||
alwaysHasNode: false, | ||
wrapInitWithProfilingTimeout: true, | ||
wrapInitWithTryCatch: true | ||
}); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
## Class: IpcMainServiceWorker | ||
|
||
> Communicate asynchronously from the main process to service workers. | ||
|
||
Process: [Main](../glossary.md#main-process) | ||
|
||
> [!NOTE] | ||
> This API is a subtle variation of [`IpcMain`](ipc-main.md)—targeted for | ||
> communicating with service workers. For communicating with web frames, | ||
> consult the `IpcMain` documentation. | ||
|
||
<!-- TODO(samuelmaddock): refactor doc gen to allow generics to reduce duplication --> | ||
|
||
### Instance Methods | ||
|
||
#### `ipcMainServiceWorker.on(channel, listener)` | ||
|
||
* `channel` string | ||
* `listener` Function | ||
* `event` [IpcMainServiceWorkerEvent][ipc-main-service-worker-event] | ||
* `...args` any[] | ||
|
||
Listens to `channel`, when a new message arrives `listener` would be called with | ||
`listener(event, args...)`. | ||
|
||
#### `ipcMainServiceWorker.once(channel, listener)` | ||
|
||
* `channel` string | ||
* `listener` Function | ||
* `event` [IpcMainServiceWorkerEvent][ipc-main-service-worker-event] | ||
* `...args` any[] | ||
|
||
Adds a one time `listener` function for the event. This `listener` is invoked | ||
only the next time a message is sent to `channel`, after which it is removed. | ||
|
||
#### `ipcMainServiceWorker.removeListener(channel, listener)` | ||
|
||
* `channel` string | ||
* `listener` Function | ||
* `...args` any[] | ||
|
||
Removes the specified `listener` from the listener array for the specified | ||
`channel`. | ||
|
||
#### `ipcMainServiceWorker.removeAllListeners([channel])` | ||
|
||
* `channel` string (optional) | ||
|
||
Removes listeners of the specified `channel`. | ||
|
||
#### `ipcMainServiceWorker.handle(channel, listener)` | ||
|
||
* `channel` string | ||
* `listener` Function\<Promise\<any\> | any\> | ||
* `event` [IpcMainServiceWorkerInvokeEvent][ipc-main-service-worker-invoke-event] | ||
* `...args` any[] | ||
|
||
#### `ipcMainServiceWorker.handleOnce(channel, listener)` | ||
|
||
* `channel` string | ||
* `listener` Function\<Promise\<any\> | any\> | ||
* `event` [IpcMainServiceWorkerInvokeEvent][ipc-main-service-worker-invoke-event] | ||
* `...args` any[] | ||
|
||
Handles a single `invoke`able IPC message, then removes the listener. See | ||
`ipcMainServiceWorker.handle(channel, listener)`. | ||
|
||
#### `ipcMainServiceWorker.removeHandler(channel)` | ||
|
||
* `channel` string | ||
|
||
Removes any handler for `channel`, if present. | ||
|
||
[ipc-main-service-worker-event]:../api/structures/ipc-main-service-worker-event.md | ||
[ipc-main-service-worker-invoke-event]:../api/structures/ipc-main-service-worker-invoke-event.md |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
# IpcMainServiceWorkerEvent Object extends `Event` | ||
|
||
* `type` String - Possible values include `service-worker`. | ||
* `serviceWorker` [ServiceWorkerMain](../service-worker-main.md) _Readonly_ - The service worker that sent this message | ||
* `versionId` Number - The service worker version ID. | ||
* `session` Session - The [`Session`](../session.md) instance with which the event is associated. | ||
* `returnValue` any - Set this to the value to be returned in a synchronous message | ||
* `ports` [MessagePortMain](../message-port-main.md)[] - A list of MessagePorts that were transferred with this message | ||
* `reply` Function - A function that will send an IPC message to the renderer frame that sent the original message that you are currently handling. You should use this method to "reply" to the sent message in order to guarantee the reply will go to the correct process and frame. | ||
* `channel` string | ||
* `...args` any[] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
# IpcMainServiceWorkerInvokeEvent Object extends `Event` | ||
|
||
* `type` String - Possible values include `service-worker`. | ||
* `serviceWorker` [ServiceWorkerMain](../service-worker-main.md) _Readonly_ - The service worker that sent this message | ||
* `versionId` Number - The service worker version ID. | ||
* `session` Session - The [`Session`](../session.md) instance with which the event is associated. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
# PreloadScriptRegistration Object | ||
|
||
* `type` string - Context type where the preload script will be executed. | ||
Possible values include `frame`. | ||
Possible values include `frame` or `service-worker`. | ||
* `id` string (optional) - Unique ID of preload script. Defaults to a random UUID. | ||
* `filePath` string - Path of the script file. Must be an absolute path. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
# PreloadScript Object | ||
|
||
* `type` string - Context type where the preload script will be executed. | ||
Possible values include `frame`. | ||
Possible values include `frame` or `service-worker`. | ||
* `id` string - Unique ID of preload script. | ||
* `filePath` string - Path of the script file. Must be an absolute path. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.