@@ -22,6 +22,7 @@ The API to get user profiles, submissions, and problems on LeetCode, with highly
2222
2323- [x] Customable GraphQL Query API.
2424- [x] Customable Rate Limiter. (Default: 20 req / 10 sec)
25+ - [x] Customable Fetcher.
2526
2627## Examples
2728
@@ -48,6 +49,48 @@ const leetcode = new LeetCode(credential);
4849console .log (await leetcode .submissions (100 , 0 ));
4950```
5051
52+ ### Use Custom Fetcher
53+
54+ You can use your own fetcher, for example, fetch through a real browser.
55+
56+ ``` typescript
57+ import { LeetCode , fetcher } from " leetcode-query" ;
58+ import { chromium } from " playwright-extra" ;
59+ import stealth from " puppeteer-extra-plugin-stealth" ;
60+
61+ // setup browser
62+ const _browser = chromium .use (stealth ()).launch ();
63+ const _page = _browser
64+ .then ((browser ) => browser .newPage ())
65+ .then (async (page ) => {
66+ await page .goto (" https://leetcode.com" );
67+ return page ;
68+ });
69+
70+ // use a custom fetcher
71+ fetcher .set (async (... args ) => {
72+ const page = await _page ;
73+
74+ const res = await page .evaluate (async (args ) => {
75+ const res = await fetch (... args );
76+ return {
77+ body: await res .text (),
78+ status: res .status ,
79+ statusText: res .statusText ,
80+ headers: Object .fromEntries (res .headers ),
81+ };
82+ }, args );
83+
84+ return new Response (res .body , res );
85+ });
86+
87+ // use as normal
88+ const lc = new LeetCode ();
89+ const daily = await lc .daily ();
90+ console .log (daily );
91+ await _browser .then ((browser ) => browser .close ());
92+ ```
93+
5194## Documentation
5295
5396Documentation for this package is available on < https://jacoblincool.github.io/LeetCode-Query/ > .
0 commit comments