Commit c101dd9f authored by nextime's avatar nextime

Fix JavaScript syntax errors in page.evaluate regex patterns

- Replace inline regex literals with RegExp constructors for dynamic requestId
- Fix 'missing ) after argument list' error in JSON pattern matching
- Update all regex patterns to use proper RegExp constructor syntax
- Ensure proper string concatenation with requestId variable
- Fix jsonMatch pattern to use separate RegExp objects

This resolves the JavaScript syntax error that was causing
page.evaluate to fail during JSON response detection.
parent a5320424
...@@ -479,11 +479,11 @@ async def detect_json_response_with_id(page, container_selector, request_id, pro ...@@ -479,11 +479,11 @@ async def detect_json_response_with_id(page, container_selector, request_id, pro
// Look for JSON patterns with our unique ID // Look for JSON patterns with our unique ID
const jsonPatterns = [ const jsonPatterns = [
// Standard JSON object patterns // Standard JSON object patterns
/\{[^{}]*"id"\s*:\s*"[^"]*' + requestId + '[^"]*"[^{}]*"response"\s*:\s*"([^"\\\\]|\\\\.)*"[^{}]*\}/g, new RegExp('\\{[^{}]*"id"\\s*:\\s*"[^"]*' + requestId + '[^"]*"[^{}]*"response"\\s*:\\s*"([^"\\\\]|\\\\.)*"[^{}]*\\}', 'g'),
/\{[^{}]*"response"\s*:\s*"([^"\\\\]|\\\\.)*"[^{}]*"id"\s*:\s*"[^"]*' + requestId + '[^"]*"[^{}]*\}/g, new RegExp('\\{[^{}]*"response"\\s*:\\s*"([^"\\\\]|\\\\.)*"[^{}]*"id"\\s*:\\s*"[^"]*' + requestId + '[^"]*"[^{}]*\\}', 'g'),
// More flexible JSON patterns // More flexible JSON patterns
/\{[\\s\\S]*?"id"[\\s\\S]*?"' + requestId + '"[\\s\\S]*?"response"[\\s\\S]*?\}/g, new RegExp('\\{[\\s\\S]*?"id"[\\s\\S]*?"' + requestId + '"[\\s\\S]*?"response"[\\s\\S]*?\\}', 'g'),
/\{[\\s\\S]*?"response"[\\s\\S]*?"id"[\\s\\S]*?"' + requestId + '"[\\s\\S]*?\}/g, new RegExp('\\{[\\s\\S]*?"response"[\\s\\S]*?"id"[\\s\\S]*?"' + requestId + '"[\\s\\S]*?\\}', 'g'),
// Very flexible patterns for malformed JSON // Very flexible patterns for malformed JSON
new RegExp('\\{[\\s\\S]*?["\']id["\']\\s*:\\s*["\'][^"\']*' + requestId + '[^"\']*["\'][\\s\\S]*?["\']response["\']\\s*:\\s*["\']([\\s\\S]*?)["\'][\\s\\S]*?\\}', 'g'), new RegExp('\\{[\\s\\S]*?["\']id["\']\\s*:\\s*["\'][^"\']*' + requestId + '[^"\']*["\'][\\s\\S]*?["\']response["\']\\s*:\\s*["\']([\\s\\S]*?)["\'][\\s\\S]*?\\}', 'g'),
new RegExp('\\{[\\s\\S]*?["\']response["\']\\s*:\\s*["\']([\\s\\S]*?)["\'][\\s\\S]*?["\']id["\']\\s*:\\s*["\'][^"\']*' + requestId + '[^"\']*["\'][\\s\\S]*?\\}', 'g') new RegExp('\\{[\\s\\S]*?["\']response["\']\\s*:\\s*["\']([\\s\\S]*?)["\'][\\s\\S]*?["\']id["\']\\s*:\\s*["\'][^"\']*' + requestId + '[^"\']*["\'][\\s\\S]*?\\}', 'g')
...@@ -714,7 +714,9 @@ async def detect_json_response_with_id(page, container_selector, request_id, pro ...@@ -714,7 +714,9 @@ async def detect_json_response_with_id(page, container_selector, request_id, pro
console.log(`📄 Found element with potential JSON: ${text.substring(0, 150)}...`); console.log(`📄 Found element with potential JSON: ${text.substring(0, 150)}...`);
// Try to extract JSON from this text // Try to extract JSON from this text
const jsonMatch = text.match(/\{[^{}]*"id"[^{}]*"' + requestId + '"[^{}]*"response"[^{}]*\}|\{[^{}]*"response"[^{}]*"id"[^{}]*"' + requestId + '"[^{}]*\}/); const jsonPattern1 = new RegExp('\\{[^{}]*"id"[^{}]*"' + requestId + '"[^{}]*"response"[^{}]*\\}');
const jsonPattern2 = new RegExp('\\{[^{}]*"response"[^{}]*"id"[^{}]*"' + requestId + '"[^{}]*\\}');
const jsonMatch = text.match(jsonPattern1) || text.match(jsonPattern2);
if (jsonMatch && isCompleteValidJson(jsonMatch[0])) { if (jsonMatch && isCompleteValidJson(jsonMatch[0])) {
const jsonObj = JSON.parse(jsonMatch[0]); const jsonObj = JSON.parse(jsonMatch[0]);
console.log(`✅ Returning validated response from text for ID: ${jsonObj.id}`); console.log(`✅ Returning validated response from text for ID: ${jsonObj.id}`);
......
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