@monostate/node-scraper 1.0.1 → 1.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/index.js +12 -1
- package/package.json +1 -1
package/index.js
CHANGED
|
@@ -1,10 +1,17 @@
|
|
|
1
1
|
import fetch from 'node-fetch';
|
|
2
2
|
import { spawn } from 'child_process';
|
|
3
|
-
import puppeteer from 'puppeteer';
|
|
4
3
|
import fs from 'fs/promises';
|
|
5
4
|
import path from 'path';
|
|
6
5
|
import { fileURLToPath } from 'url';
|
|
7
6
|
|
|
7
|
+
let puppeteer = null;
|
|
8
|
+
try {
|
|
9
|
+
puppeteer = await import('puppeteer');
|
|
10
|
+
puppeteer = puppeteer.default || puppeteer;
|
|
11
|
+
} catch (e) {
|
|
12
|
+
// Puppeteer is optional
|
|
13
|
+
}
|
|
14
|
+
|
|
8
15
|
const __filename = fileURLToPath(import.meta.url);
|
|
9
16
|
const __dirname = path.dirname(__filename);
|
|
10
17
|
|
|
@@ -254,6 +261,10 @@ export class BNCASmartScraper {
|
|
|
254
261
|
async tryPuppeteer(url, config) {
|
|
255
262
|
this.stats.puppeteer.attempts++;
|
|
256
263
|
|
|
264
|
+
if (!puppeteer) {
|
|
265
|
+
throw new Error('Puppeteer is not available');
|
|
266
|
+
}
|
|
267
|
+
|
|
257
268
|
try {
|
|
258
269
|
if (!this.browser) {
|
|
259
270
|
this.browser = await puppeteer.launch({
|