|
8 | 8 |
|
9 | 9 | # [](#generating-fingerprints) Generating fingerprints
|
10 | 10 |
|
11 |
| -With the [Fingerprint generator](https://github.com/apify/fingerprint-generator) NPM package, you can easily generate a browser fingerprint. |
| 11 | +In [**Crawlee**](https://crawlee.dev), it's extremely easy to automatically generate fingerprints using the [**FingerprintOptions**](https://crawlee.dev/api/browser-pool/interface/FingerprintOptions) on a crawler. |
| 12 | + |
| 13 | +```JavaScript |
| 14 | +import { PlaywrightCrawler } from 'crawlee'; |
| 15 | + |
| 16 | +const crawler = new PlaywrightCrawler({ |
| 17 | + browserPoolOptions: { |
| 18 | + fingerprintOptions: { |
| 19 | + fingerprintGeneratorOptions: { |
| 20 | + browsers: [{ name: 'firefox', minVersion: 80 }], |
| 21 | + devices: ['desktop'], |
| 22 | + operatingSystems: ['windows'], |
| 23 | + }, |
| 24 | + }, |
| 25 | + }, |
| 26 | +}); |
| 27 | +``` |
| 28 | + |
| 29 | +> Note that Crawlee will automatically generate fingerprints for you with no configuration necessary, but the option to configure them yourself is still there within **browserPoolOptions**. |
| 30 | +
|
| 31 | +## [](#using-fingerprint-generator) Using the fingerprint-generator package |
| 32 | + |
| 33 | +Crawlee uses the [Fingerprint generator](https://github.com/apify/fingerprint-generator) NPM package to do its fingerprint generating magic. For maximum control outside of Crawlee, you can install it on its own. With this package, you can easily generate browser fingerprints. |
12 | 34 |
|
13 | 35 | > It is crucial to generate fingerprints for the specific browser and operating system being used to trick the protections successfully. For example, if you are trying to overcome protection locally with Firefox on a macOS system, you should generate fingerprints for Firefox and macOS to achieve the best results.
|
14 | 36 |
|
@@ -37,7 +59,7 @@ const generated = fingerprintGenerator.getFingerprint({
|
37 | 59 |
|
38 | 60 | ## [](#injecting-fingerprints) Injecting fingerprints
|
39 | 61 |
|
40 |
| -Once you've generated a fingerprint, it can be injected into the browser using the [Fingerprint injector](https://github.com/apify/fingerprint-injector) package. This tool allows you to inject fingerprints to browsers automated by Playwright or Puppeteer: |
| 62 | +Once you've manually generated a fingerprint using the **Fingerprint generator** package, it can be injected into the browser using [**fingerprint-injector**](https://github.com/apify/fingerprint-injector). This tool allows you to inject fingerprints into browsers automated by Playwright or Puppeteer: |
41 | 63 |
|
42 | 64 | ```JavaScript
|
43 | 65 | import FingerprintGenerator from 'fingerprint-generator';
|
@@ -90,3 +112,20 @@ await page.goto('https://google.com');
|
90 | 112 | ## Wrap up
|
91 | 113 |
|
92 | 114 | That's it for the **Mitigation** course for now, but be on the lookout for future lessons! We release lessons as we write them, and will be updating the Academy frequently, so be sure to check back every once in a while for new content! Alternatively, you can subscribe to our mailing list to get periodic updates on the Academy, as well as what Apify is up to.
|
| 115 | + |
| 116 | +## [](#generating-headers) Generating headers |
| 117 | + |
| 118 | +Headers are also used by websites to fingerprint users (or bots), so it might sometimes be necessary to generate some user-like headers to mitigate anti-scraping protections. Similarly with fingerprints, **Crawlee** automatically generates headers for you, but you can have full control by using the [**browser-headers-generator**](https://github.com/apify/browser-headers-generator) package. |
| 119 | + |
| 120 | +```JavaScript |
| 121 | +import BrowserHeadersGenerator from 'browser-headers-generator'; |
| 122 | + |
| 123 | +const browserHeadersGenerator = new BrowserHeadersGenerator({ |
| 124 | + operatingSystems: ['windows'], |
| 125 | + browsers: ['chrome'], |
| 126 | +}); |
| 127 | + |
| 128 | +await browserHeadersGenerator.initialize() |
| 129 | + |
| 130 | +const randomBrowserHeaders = await browserHeadersGenerator.getRandomizedHeaders() |
| 131 | +``` |
0 commit comments