Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
ulixee
GitHub Repository: ulixee/secret-agent
Path: blob/main/examples/plugin-echo-use.ts
1028 views
1
import { Agent } from 'secret-agent';
2
import Core from '@secret-agent/core';
3
import * as Path from 'path';
4
5
async function run() {
6
// For security, need to explicitly activate dynamic loading to allow Core to load a random path.
7
Core.allowDynamicPluginLoading = true;
8
await Core.start();
9
const agent = new Agent({ connectionToCore: { host: await Core.server.address } });
10
agent.use(Path.join(__dirname, 'plugin-echo-classes.js'));
11
/**
12
* Or install into Core and client
13
* Core.use(require('./plugin-echo-classes'));
14
* agent.use(require('./plugin-echo-classes'));
15
**/
16
17
await agent.goto('https://example.org/');
18
await agent.waitForPaintingStable();
19
const result = await agent.echo('Echo', 1, 2, 3, true);
20
console.log('Echo result', {
21
sent: ['Echo', 1, 2, 3, true],
22
result,
23
});
24
await agent.close();
25
}
26
27
run().catch(error => console.log(error));
28
29