foreign-sapphire
foreign-sapphire•2y ago

How to use InjectFile func of PlaywrightUtils?

I want to inject js file into chrome and use it to crawl the function in js file. Can you tell me the some Example to use InjectFile func?
https://crawlee.dev/api/playwright-crawler/namespace/playwrightUtils#injectFile
playwrightUtils | API | Crawlee
A namespace that contains various utilities for Playwright - the headless Chrome Node API. Example usage: ```javascript import { launchPlaywright, playwrightUtils } from 'crawlee'; // Navigate to https://www.example.com in Playwright with a POST request const browser = await launchPlaywright(); c...
2 Replies
Saurav Jain
Saurav Jain•2y ago
Hello @CherryPapa, someone from the team will reply soon. 😄
lemurio
lemurio•2y ago
hey, here's a very simple example:
await Actor.init();

const proxyConfiguration = await Actor.createProxyConfiguration();

const crawler = new PlaywrightCrawler({
proxyConfiguration,
requestHandler: async ({ injectFile }) => {
await injectFile('.path-to-file.js');
},
});

await crawler.run(['https://example.com']);

await Actor.exit();
await Actor.init();

const proxyConfiguration = await Actor.createProxyConfiguration();

const crawler = new PlaywrightCrawler({
proxyConfiguration,
requestHandler: async ({ injectFile }) => {
await injectFile('.path-to-file.js');
},
});

await crawler.run(['https://example.com']);

await Actor.exit();

Did you find this page helpful?