A package for consuming WebExtensions API in a browser extension.
These API classes are generated based on the Mozilla documentation for WebExtension API.
This package can be consumed in two methods.
Create a browser extension using Blazor. Refer to the package Blazor.BrowserExtension to get started.
Create a standard browser extension using JavaScript and load the WebAssembly manually. The .Net source code can be compiled into wasm using Mono.
- Install
WebExtension.Net
from Nuget. - A JavaScript file will be added to your project at the path
wwwroot/WebExtensionScripts/WebExtensionNet.js
. This.js
file needs to be included in your application, either by using a<script>
element in HTML or usingimport
from JavaScript code. - Import the WebExtension polyfill by Mozilla for cross browser compatibility. This polyfill helps to convert the callback based Chrome extensions API to a Promise based API for asynchronous functions.
- Consume the WebExtension API by creating an instance of
WebExtensionApi
as shown below.
// iJsRuntime is an instance of MonoWebAssemblyJSRuntime
var webExtensionJsRuntime = new WebExtensionJSRuntime(iJsRuntime);
var webExtensionApi = new WebExtensionApi(webExtensionJsRuntime);
var manifest = await webExtensionApi.Runtime.GetManifest();
- For callback functions with more than one parameter, only the first callback parameter is returned right now.
- Parameter callback is not supported.
- The browser extension API namespaces that are enabled at the moment is 11 out of a total of 60.
- Event listener is not supported.
Function invocation on returned object is not supported.Since v0.2.*
The following MSBuild properties can be specified in your project file or when running dotnet build
command.
Property | Default value | Description |
---|---|---|
WebExtensionAssetsPath | wwwroot | The root folder where the JavaScript file should be added as link. |
IncludeWebExtensionAssets | true | If set to false, the JavaScript file will not be added as to the project. |