1. The Problem
I'm trying to create a browser extension in Dart. Currently, I'm using the webext
package, which basically emulates the typical JS environment in Dart.
In the main()
function of content.dart
file, I wish to manipulate the DOM. The document
variable is available and is of type HtmlDocument
, which comes from dart:html
. This is all well and good, but how would you create a testing harness with that, considering HtmlDocument
doesn't have a public constructor?
2. What I've tried so far
I've tried to use the parent of HtmlDocument
, i.e., Document
. Something like this for a custom HTML tag:
import 'dart:html';
void main() {
final Document document = Document();
document.registerElement(CustomElement.tag, CustomElement);
document.createElement(CustomElement.tag);
}
class CustomElement extends HtmlElement {
static const String tag = 'custom-tag';
factory CustomElement.created() => null;
}
But the Document
class doesn't have the necessary API and registering custom tags is not supported apparently — the supportsRegisterElement
getter gives me back false
, which might be related to Chrome or Dartium, I'm not sure.