11import axios from 'axios' ;
22import handleError from './utils/handleError.js' ;
3+ import { isMockEnabled , getMockConfig } from './utils/mockConfig.js' ;
4+ import { getMockResponse } from './utils/mockResponse.js' ;
35
46/**
57 * Perform automated browser actions on a webpage using AI-powered agentic scraping.
@@ -11,6 +13,8 @@ import handleError from './utils/handleError.js';
1113 * @param {string } [userPrompt=null] - Prompt for AI extraction (required when aiExtraction=true)
1214 * @param {Object } [outputSchema=null] - Schema for structured data extraction (optional, used with aiExtraction=true)
1315 * @param {boolean } [aiExtraction=false] - Whether to use AI for data extraction from the scraped content
16+ * @param {Object } options - Optional configuration options
17+ * @param {boolean } options.mock - Override mock mode for this request
1418 * @returns {Promise<Object> } Response from the API containing request_id and initial status
1519 * @throws {Error } Will throw an error in case of an HTTP failure or invalid parameters.
1620 *
@@ -60,7 +64,19 @@ import handleError from './utils/handleError.js';
6064 * console.error('Error:', error.message);
6165 * }
6266 */
63- export async function agenticScraper ( apiKey , url , steps , useSession = true , userPrompt = null , outputSchema = null , aiExtraction = false ) {
67+ export async function agenticScraper ( apiKey , url , steps , useSession = true , userPrompt = null , outputSchema = null , aiExtraction = false , options = { } ) {
68+ const { mock = null } = options ;
69+
70+ // Check if mock mode is enabled
71+ const useMock = mock !== null ? mock : isMockEnabled ( ) ;
72+
73+ if ( useMock ) {
74+ console . log ( '🧪 Mock mode active. Returning stub for agenticScraper request' ) ;
75+ const mockConfig = getMockConfig ( ) ;
76+ const mockData = getMockResponse ( 'POST' , 'https://api.scrapegraphai.com/v1/agentic-scrapper' , mockConfig . customResponses , mockConfig . customHandler ) ;
77+ return mockData ;
78+ }
79+
6480 const endpoint = 'https://api.scrapegraphai.com/v1/agentic-scrapper' ;
6581 const headers = {
6682 'accept' : 'application/json' ,
@@ -166,7 +182,19 @@ export async function agenticScraper(apiKey, url, steps, useSession = true, user
166182 * allowing for complex interactions like form filling, clicking buttons,
167183 * and navigating through multi-step workflows with session management.
168184 */
169- export async function getAgenticScraperRequest ( apiKey , requestId ) {
185+ export async function getAgenticScraperRequest ( apiKey , requestId , options = { } ) {
186+ const { mock = null } = options ;
187+
188+ // Check if mock mode is enabled
189+ const useMock = mock !== null ? mock : isMockEnabled ( ) ;
190+
191+ if ( useMock ) {
192+ console . log ( '🧪 Mock mode active. Returning stub for getAgenticScraperRequest' ) ;
193+ const mockConfig = getMockConfig ( ) ;
194+ const mockData = getMockResponse ( 'GET' , `https://api.scrapegraphai.com/v1/agentic-scrapper/${ requestId } ` , mockConfig . customResponses , mockConfig . customHandler ) ;
195+ return mockData ;
196+ }
197+
170198 const endpoint = 'https://api.scrapegraphai.com/v1/agentic-scrapper/' + requestId ;
171199 const headers = {
172200 'accept' : 'application/json' ,
0 commit comments