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.
TypeScript apifyautomationcrawlercrawlingheadlessheadless-chromejavascriptnodejsnpmplaywrightpuppeteerscraperscrapingtypescriptweb-crawlerweb-crawlingweb-scraping
Fix issue, add test
Ondra Urban902b4ca7b933
diff --git a/CHANGELOG.md b/CHANGELOG.mdindex 1699de4f4..20177bfb2 100644--- a/CHANGELOG.md+++ b/CHANGELOG.md@@ -1,3 +1,8 @@+xxx+===================+- Fixed an issue where an error would be thrown when `datasetLocal.getData()` was invoked+ with an overflowing offset. It now correctly returns an empty `Array`.+0.9.15 / 2018-11-30===================- Upgraded Puppeteer to 1.11.0diff --git a/src/dataset.js b/src/dataset.jsindex b460f1df7..6ce9b35aa 100644--- a/src/dataset.js+++ b/src/dataset.js@@ -584,11 +584,10 @@ export class DatasetLocal {*/_getItemIndexes(offset = 0, limit = this.counter) {if (limit === null) throw new Error('DatasetLocal must be initialize before calling this._getItemIndexes()!');-- return _.range(- offset + 1,- Math.min(offset + limit, this.counter) + 1,- );+ const start = offset + 1;+ const end = Math.min(offset + limit, this.counter) + 1;+ if (start > end) return [];+ return _.range(start, end);}/**diff --git a/test/dataset.js b/test/dataset.jsindex ca6882539..ef60f9af3 100644--- a/test/dataset.js+++ b/test/dataset.js@@ -107,6 +107,14 @@ describe('dataset', () => {count: 2,limit: 2,});++ expect(await dataset.getData({ offset: 10 })).to.be.eql({+ items: [],+ total: 4,+ offset: 10,+ count: 0,+ limit: LOCAL_GET_ITEMS_DEFAULT_LIMIT,+ });});it('getInfo() should work', async () => {