Commit c9f87350 authored by nextime's avatar nextime

Fix JavaScript null pointer error in regex match chaining

- Add proper null checking for chained .match() calls
- Prevent 'missing ) after argument list' error when second match returns null
- Improve error handling in malformed JSON response extraction
- This resolves the JavaScript syntax error in page.evaluate function
parent c101dd9f
......@@ -515,9 +515,12 @@ async def detect_json_response_with_id(page, container_selector, request_id, pro
// Try to extract just the response value if JSON parsing fails
const responseMatch = fixedJson.match(/"response"\\s*:\\s*"([^"\\\\]|\\\\.)*"/);
if (responseMatch && fixedJson.includes(requestId)) {
const responseValue = responseMatch[0].match(/"response"\\s*:\\s*"(.*)"/)[1];
console.log(`Extracted response from malformed JSON: ${responseValue.substring(0, 100)}...`);
return responseValue;
const valueMatch = responseMatch[0].match(/"response"\\s*:\\s*"(.*)"/);
if (valueMatch && valueMatch[1]) {
const responseValue = valueMatch[1];
console.log(`Extracted response from malformed JSON: ${responseValue.substring(0, 100)}...`);
return responseValue;
}
}
const jsonObj = JSON.parse(fixedJson);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment