wxyer / WebExtension.Net

A package for consuming WebExtensions API in a browser extension.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

WebExtension.Net

Nuget GitHub Workflow Status

A package for consuming WebExtensions API in a browser extension.

These API classes are generated based on the Mozilla documentation for WebExtension API.

How to use this package

This package can be consumed in two methods.

With Blazor (Recommended)

Create a browser extension using Blazor. Refer to the package Blazor.BrowserExtension to get started.

Without Blazor

Create a standard browser extension using JavaScript and load the WebAssembly manually. The .Net source code can be compiled into wasm using Mono.

  1. Install WebExtension.Net from Nuget.
  2. 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 using import from JavaScript code.
  3. 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.
  4. 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();

API References

Limitations

  • 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.*

Customize build

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.

About

A package for consuming WebExtensions API in a browser extension.

License:MIT License


Languages

Language:C# 98.3%Language:HTML 0.8%Language:JavaScript 0.5%Language:CSS 0.4%