Supercharge your AI agents with data from the web and beyond. Building the library for superintelligence. 🔥
TypeScript aiai-agentsai-crawlerai-scrapingai-searchcrawlerdata-extractionhtml-to-markdownllmmarkdownscraperscrapingweb-crawlerweb-dataweb-data-extractionweb-scraperweb-scrapingweb-searchwebscraping
fix(js-sdk): expose V2 methods on top-level Firecrawl prototype
Himadri M36eade48b674
diff --git a/apps/js-sdk/firecrawl/src/__tests__/unit/v2/prototype-discoverability.test.ts b/apps/js-sdk/firecrawl/src/__tests__/unit/v2/prototype-discoverability.test.tsnew file mode 100644index 000000000..bc61b4112--- /dev/null+++ b/apps/js-sdk/firecrawl/src/__tests__/unit/v2/prototype-discoverability.test.ts@@ -0,0 +1,42 @@+import { Firecrawl } from "../../../index";++describe("V2 prototype discoverability", () => {+ const app = new Firecrawl({ apiKey: "fc-test", apiUrl: "http://localhost:9" });++ it("exposes V2 methods on immediate Firecrawl prototype", () => {+ const names = Object.getOwnPropertyNames(Object.getPrototypeOf(app));++ expect(names).toEqual(+ expect.arrayContaining([+ "scrape",+ "search",+ "map",+ "crawl",+ "startCrawl",+ "getCrawlStatus",+ "batchScrape",+ "v1",+ ])+ );+ });++ it("preserves v1 getter on Firecrawl prototype", () => {+ const desc = Object.getOwnPropertyDescriptor(+ Object.getPrototypeOf(app),+ "v1"+ );+ expect(desc).toBeDefined();+ expect(desc!.get).toBeDefined();+ });++ it("exposed methods are callable with correct this binding", async () => {+ const spy = jest+ .spyOn(app, "scrape")+ .mockResolvedValue({ markdown: "ok" } as any);+ await app.scrape("https://example.com", { formats: ["markdown"] });+ expect(spy).toHaveBeenCalledWith("https://example.com", {+ formats: ["markdown"],+ });+ spy.mockRestore();+ });+});diff --git a/apps/js-sdk/firecrawl/src/index.ts b/apps/js-sdk/firecrawl/src/index.tsindex 3e66d6746..0af634da0 100644--- a/apps/js-sdk/firecrawl/src/index.ts+++ b/apps/js-sdk/firecrawl/src/index.ts@@ -43,5 +43,16 @@ export class Firecrawl extends V2 {}}+// Copy V2 method descriptors onto Firecrawl.prototype so that+// Object.getOwnPropertyNames(Object.getPrototypeOf(app)) includes them.+(function exposeV2MethodsOnTopLevel() {+ for (const name of Object.getOwnPropertyNames(V2.prototype)) {+ if (name === "constructor") continue;+ if (Object.prototype.hasOwnProperty.call(Firecrawl.prototype, name)) continue;+ const desc = Object.getOwnPropertyDescriptor(V2.prototype, name);+ if (desc) Object.defineProperty(Firecrawl.prototype, name, desc);+ }+})();+export default Firecrawl;