Skip to content

Crawlee—A web scraping and browser automation library for Node.js to build reliable crawlers. In JavaScript and TypeScript. Extract data for AI, LLMs, RAG, or GPTs. Download HTML, PDF, JPG, PNG, and other files from websites. Works with Puppeteer, Playwright, Cheerio, JSDOM, and raw HTTP. Both headful and headless mode. With proxy rotation.

Bugfix in Apify.utils.puppeteer.injectXxx functions

Jan Curne2cce6884808
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 3f168310c..9913b0efd 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -1,3 +1,7 @@
+0.5.31 / 2018-05-11
+===================
+- Bugfix in `Apify.utils.puppeteer.injectXxx` functions
+
0.5.30 / 2018-05-11
===================
- Puppeteer updated to v1.4.0
diff --git a/src/puppeteer_utils.js b/src/puppeteer_utils.js
index 0e46ea975..5a7d35579 100644
--- a/src/puppeteer_utils.js
+++ b/src/puppeteer_utils.js
@@ -1,5 +1,4 @@
import fs from 'fs';
-import path from 'path';
import Promise from 'bluebird';
import _ from 'underscore';
import { checkParamOrThrow } from 'apify-client/build/utils';
@@ -7,6 +6,9 @@ import { checkParamPrototypeOrThrow } from 'apify-shared/utilities';
import { RequestQueue, RequestQueueLocal } from './request_queue';
import Request from './request';
+const jqueryPath = require.resolve('jquery');
+const underscorePath = require.resolve('underscore');
+
const readFilePromised = Promise.promisify(fs.readFile);
/**
@@ -82,9 +84,8 @@ const injectFile = async (page, filePath) => {
const injectJQuery = (page) => {
checkParamOrThrow(page, 'page', 'Object');
- const scriptPath = path.resolve(path.join(__dirname, '../node_modules/jquery/dist/jquery.min.js'));
-
- return injectFile(page, scriptPath);
+ // TODO: For better performance we could use minimized version of the script
+ return injectFile(page, jqueryPath);
};
/**
@@ -99,9 +100,8 @@ const injectJQuery = (page) => {
const injectUnderscore = (page) => {
checkParamOrThrow(page, 'page', 'Object');
- const scriptPath = path.resolve(path.join(__dirname, '../node_modules/underscore/underscore-min.js'));
-
- return injectFile(page, scriptPath);
+ // TODO: For better performance we could use minimized version of the script
+ return injectFile(page, underscorePath);
};
/**