Worker constructor
Worker(
- Client client,
- String? url, {
- required void onConsoleApiCalled()?,
- required void onExceptionThrown()?,
Implementation
Worker(this.client, this.url,
{required void Function(
ConsoleAPICalledEventType, List<JsHandle>, StackTraceData?)?
onConsoleApiCalled,
required void Function(ExceptionThrownEvent)? onExceptionThrown}) {
var runtimeApi = RuntimeApi(client);
late JsHandle Function(RemoteObject) jsHandleFactory;
runtimeApi.onExecutionContextCreated.listen((event) {
var executionContext = ExecutionContext(client, event, null);
jsHandleFactory =
(remoteObject) => JsHandle(executionContext, remoteObject);
_executionContextCompleter.complete(executionContext);
});
runtimeApi.onConsoleAPICalled.listen((event) {
if (onConsoleApiCalled != null) {
onConsoleApiCalled(event.type, event.args.map(jsHandleFactory).toList(),
event.stackTrace);
}
});
runtimeApi.onExceptionThrown.listen((event) {
if (onExceptionThrown != null) {
onExceptionThrown(event);
}
});
runtimeApi.enable().catchError((e) {
// This might fail if the target is closed before we recieve all execution contexts.
});
}