chromeapi 0.0.8
chromeapi: ^0.0.8 copied to clipboard
Chrome Extension API wrapper
Chrome Extensions API
Features #
Project is WIP, starting with chrome.tabs
mostly implemented (methods, not events).
Prerequisites #
- Set permissions in
manifest.json
required to use specifc API's according found at Chrome Reference - If building with Flutter,
- Make the appropriate changes to the normal working directory/files.
- Examples:
manifest.json
(example: service workers)index.json
- Customize the build command
flutter build web --web-renderer html --csp
For reference on Building Chrome Extension using Flutter
- Examples:
- Make the appropriate changes to the normal working directory/files.
Usage #
Import the library, no use of js namespaces.
So to get chrome.tabs
import...
`import 'package:chromeapi/tabs.dart';
and as an example on getting the active tab, use query
...
Future<Tab> getActiveTab() async {
QueryInfo queryInfo = QueryInfo(active: true, lastFocusedWindow: true);
// Chrome library, not like JS namespaces
// `chrome.tabs.query` just `query` in this case
List<Tab> tabs = await query(queryInfo);
return tabs.singleWhere((tab) => tab.url != null && tab.url!.isNotEmpty);
}