-
-
Notifications
You must be signed in to change notification settings - Fork 43
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
9b351b3
commit 48e0933
Showing
3 changed files
with
63 additions
and
0 deletions.
There are no files selected for viewing
This file contains 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,28 @@ | ||
# Publishing the extension | ||
|
||
1. Run the `dotnet publish` command to publish the extension. | ||
0. The extension output is in the `bin/Release/net8.0/publish/browserextension` directory. | ||
0. The contents of this directory should be used when packing your extension. The contents can also be loaded unpacked the same way as the build output. | ||
|
||
## Packing the extension | ||
|
||
Typically the extension stores require that you pack your extension when submitting it to the store. | ||
Most of them requires just a simple zip format, where the zipped file is renamed with `.crx` extension. | ||
|
||
Refer to the guidance for the respective store for more details. | ||
|
||
- [Chrome Web Store](https://developer.chrome.com/docs/webstore/publish) | ||
- [Microsoft Edge Add-ons](https://learn.microsoft.com/en-us/microsoft-edge/extensions-chromium/publish/publish-extension) | ||
- [AMO (addons.mozilla.org)](https://extensionworkshop.com/documentation/publish/submitting-an-add-on/) | ||
- [Opera addons](https://dev.opera.com/extensions/publishing-guidelines/) | ||
- [Safari App Store](https://developer.apple.com/documentation/safariservices/safari_web_extensions/distributing_your_safari_web_extension) | ||
|
||
## Optimization | ||
|
||
Built in optimization has been done by this package to use Brotli compression by default, removing all the uncompressed files from the publish output to reduce the package size. | ||
|
||
If you would like to use AOT compilation, it is best to benchmark the size before and after using AOT compilation as your extension might end up having an increase in size. | ||
|
||
You can also enable IL trimming when publishing and disable unused features such as timezone support. | ||
|
||
Refer to [Blazor performance best practices](https://learn.microsoft.com/en-us/aspnet/core/blazor/performance?view=aspnetcore-8.0#minimize-app-download-size) documentation page for more information. |
File renamed without changes.
This file contains 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,35 @@ | ||
# Messaging between the contexts | ||
|
||
Comminucation between the different contexts are a common requirement, the way to achieve this depends on the source and the target context of the message. | ||
|
||
## Sending a message | ||
|
||
The `Runtime.SendMessage` API can be used from any context to send a message to all other instances except for Content Scripts. | ||
|
||
The `Tabs.SendMessage` API can be used from any context to send a message to all the instances in a tab, i.e. Content Scripts and extension iframes. | ||
|
||
Any object can be passed when invoking the API, so you can just create a message wrapper to include the metadata for the message, e.g. sender, intended recipient, timestamp, message type, payload, etc. | ||
|
||
|
||
## Receiving a message | ||
|
||
The `Runtime.OnMessage` API can be used from any context to receive a message. | ||
|
||
It is essential to be aware that there may be multiple instances receiving the same message, therefore you can use something to filter out noise messages, for example, having a property in the message object to indicate which context the message is intended for. | ||
|
||
The pages with listeners will only get the message if the page is active when the message is sent. | ||
However, for Background Worker that listens to `OnMessage` event, it will be activated if it is already idle when the message is sent. | ||
|
||
|
||
## Continuous Messaging | ||
|
||
The contexts can also use `Runtime.Connect` and `Tabs.Connect` to create a `Port` that you can use to continuously send and receive message to the target context. | ||
|
||
The recipient context should then use `Runtime.OnConnect` event to listen to port creation events and respond to messages on the `Port` object. | ||
|
||
|
||
# Reference | ||
|
||
- [Chrome for Developers](https://developer.chrome.com/docs/extensions/develop/concepts/messaging) | ||
- [MDN](https://developer.mozilla.org/en-US/docs/Mozilla/Add-ons/WebExtensions/API/runtime) | ||
- [Messaging Sample Project](https://github.com/mingyaulee/Blazor.BrowserExtension.Samples/tree/main/Messaging) |