mirror of
https://github.com/FlareSolverr/FlareSolverr.git
synced 2025-06-08 12:35:30 +00:00
Fix request.post method and clean error traces
This commit is contained in:
parent
d16b982bb9
commit
c4f890f9a1
@ -124,9 +124,14 @@ async function resolveChallenge(params: V1Request, session: SessionsCacheItem):
|
||||
}
|
||||
|
||||
async function gotoPage(params: V1Request, page: Page): Promise<Response> {
|
||||
const response = await page.goto(params.url, { waitUntil: 'domcontentloaded' });
|
||||
if (params.method == 'POST') {
|
||||
let response: Response;
|
||||
if (params.method != 'POST') {
|
||||
response = await page.goto(params.url, {waitUntil: 'domcontentloaded'});
|
||||
|
||||
} else {
|
||||
// post hack
|
||||
// first request a page without cloudflare
|
||||
response = await page.goto("https://www.google.com", {waitUntil: 'domcontentloaded'});
|
||||
await page.setContent(
|
||||
`
|
||||
<!DOCTYPE html>
|
||||
@ -167,7 +172,11 @@ async function gotoPage(params: V1Request, page: Page): Promise<Response> {
|
||||
</html>
|
||||
`
|
||||
);
|
||||
await page.waitFor(2000);
|
||||
await page.waitFor(2000)
|
||||
try {
|
||||
await page.waitForNavigation({waitUntil: 'domcontentloaded', timeout: 2000})
|
||||
} catch (e) {}
|
||||
|
||||
}
|
||||
return response
|
||||
}
|
||||
@ -193,7 +202,7 @@ export async function browserRequest(params: V1Request): Promise<ChallengeResolu
|
||||
try {
|
||||
return await resolveChallengeWithTimeout(params, session)
|
||||
} catch (error) {
|
||||
throw Error("Unable to process browser request. Error: " + error)
|
||||
throw Error("Unable to process browser request. " + error)
|
||||
} finally {
|
||||
if (oneTimeSession) {
|
||||
await sessions.destroy(session.sessionId)
|
||||
|
@ -272,7 +272,7 @@ describe("Test '/v1' path", () => {
|
||||
|
||||
const apiResponse: V1ResponseSolution = response.body;
|
||||
expect(apiResponse.status).toBe("error");
|
||||
expect(apiResponse.message).toBe("Error: Unable to process browser request. Error: Error: NS_ERROR_PROXY_CONNECTION_REFUSED at https://www.google.com");
|
||||
expect(apiResponse.message).toBe("Error: Unable to process browser request. Error: NS_ERROR_PROXY_CONNECTION_REFUSED at https://www.google.com");
|
||||
});
|
||||
|
||||
test("Cmd 'request.get' should return fail with timeout", async () => {
|
||||
@ -286,7 +286,7 @@ describe("Test '/v1' path", () => {
|
||||
|
||||
const apiResponse: V1ResponseBase = response.body;
|
||||
expect(apiResponse.status).toBe("error");
|
||||
expect(apiResponse.message).toBe("Error: Unable to process browser request. Error: Error: Maximum timeout reached. maxTimeout=10 (ms)");
|
||||
expect(apiResponse.message).toBe("Error: Unable to process browser request. Error: Maximum timeout reached. maxTimeout=10 (ms)");
|
||||
expect(apiResponse.startTimestamp).toBeGreaterThan(1000);
|
||||
expect(apiResponse.endTimestamp).toBeGreaterThan(apiResponse.startTimestamp);
|
||||
expect(apiResponse.version).toBe(version);
|
||||
@ -302,7 +302,7 @@ describe("Test '/v1' path", () => {
|
||||
|
||||
const apiResponse: V1ResponseBase = response.body;
|
||||
expect(apiResponse.status).toBe("error");
|
||||
expect(apiResponse.message).toBe("Error: Unable to process browser request. Error: Error: NS_ERROR_UNKNOWN_HOST at https://www.google.combad");
|
||||
expect(apiResponse.message).toBe("Error: Unable to process browser request. Error: NS_ERROR_UNKNOWN_HOST at https://www.google.combad");
|
||||
});
|
||||
|
||||
test("Cmd 'request.get' should accept deprecated params", async () => {
|
||||
|
Loading…
x
Reference in New Issue
Block a user