-
-
Notifications
You must be signed in to change notification settings - Fork 46
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
How to set the client plugin on the handler. #426
Comments
Can you share the code you tried to use? Did you try to make it the first command inside each dispatch on your agents? |
The code below is a function that generates a handler. async createHandler(options: AgentCreateOptions): Promise<CreateHandlerResult> {
const createOption: AgentCreateOptions = {
...AgentFactory.defaultCreateOptions,
...options,
};
const handler = new Handler({
host: process.env.coreServer,
maxConcurrency: 4,
});
if (createOption.headless) {
handler.defaultAgentOptions.showReplay = false;
handler.defaultAgentOptions.blockedResourceTypes = [
BlockedResourceType.BlockCssResources,
BlockedResourceType.BlockImages,
];
}
handler.defaultAgentOptions.userAgent = '~ chrome 87';
// this point handler agents set plugins
// like handler.use(ExecuteJsPlugin);
const agent = (await handler?.createAgent()) as Agent;
agent.use(ExecuteJsPlugin);
return { handler, agent };
} In fact, it is not very good to play agent.use every time in business logic. // ...
handler.dispatchAgent(async (agent) => {
// agent.use(ExecuteJsPlugin);
try {
const result = await this.brandPerfumes(agent, brandName);
perfumes.push(...result);
} catch (e) {
console.log(`${brandName} brand error:`, e);
}
}); |
Oh, I see. Your ticket is that you're requesting an ability to set a client plugin on the overall handler. Got it. Makes sense. BTW, this code is going to create an agent outside of the dispatch process. I don't think it's what you want - in case it wasn't just example code.
|
Right, that's what I wanted.
The code is generated separately by handler to use a single agent separately. I wrote the agent to set up the plugin and use it. |
How to set the client plugin on the handler.
Don't set it up inside the dispatchAgent.
Is there any way to create a handler?
The text was updated successfully, but these errors were encountered: