The agent that turns websites into APIs!
fix: address pr comments
kalil0321f12cf2557826
diff --git a/src/reverse_api/browser.py b/src/reverse_api/browser.pyindex b5adce8..d297950 100644--- a/src/reverse_api/browser.py+++ b/src/reverse_api/browser.py@@ -288,7 +288,7 @@ class ManualBrowser:if ((element.tagName === 'BUTTON' || element.role === 'button') && element.innerText) {const text = element.innerText.trim().substring(0, 30);if (text && !text.includes('\\n')) {- return 'button:has-text("' + text.replace(/"/g, '\\\\"') + '")';+ return 'button:has-text(' + JSON.stringify(text) + ')';}}@@ -296,7 +296,7 @@ class ManualBrowser:if (element.tagName === 'A' && element.innerText) {const text = element.innerText.trim().substring(0, 30);if (text && !text.includes('\\n')) {- return 'a:has-text("' + text.replace(/"/g, '\\\\"') + '")';+ return 'a:has-text(' + JSON.stringify(text) + ')';}}@@ -667,9 +667,12 @@ class ManualBrowser:console.print(" [dim]metadata synced[/dim]")if self.action_recorder:- actions_path = self.har_dir / "actions.json"- self.action_recorder.save(actions_path)- console.print(" [dim]actions saved[/dim]")+ try:+ actions_path = self.har_dir / "actions.json"+ self.action_recorder.save(actions_path)+ console.print(" [dim]actions saved[/dim]")+ except Exception as e:+ console.print(f" [yellow]warning: error saving actions: {e}[/yellow]")return self.har_pathdiff --git a/src/reverse_api/collector.py b/src/reverse_api/collector.pyindex 91347b4..21c52e8 100644--- a/src/reverse_api/collector.py+++ b/src/reverse_api/collector.py@@ -197,7 +197,7 @@ When complete, briefly summarize what was collected.sources: set[str] = set()if items_path.exists():- with open(items_path) as f:+ with open(items_path, encoding="utf-8") as f:for line in f:line = line.strip()if line:@@ -219,7 +219,7 @@ When complete, briefly summarize what was collected.# Export JSONjson_path = self._collected_dir / "data.json"- with open(json_path, "w") as f:+ with open(json_path, "w", encoding="utf-8") as f:json.dump(collected_items, f, indent=2)# Export CSV@@ -277,7 +277,7 @@ When complete, briefly summarize what was collected.# Sort keys for consistent column orderfieldnames = sorted(all_keys)- with open(csv_path, "w", newline="") as f:+ with open(csv_path, "w", newline="", encoding="utf-8") as f:writer = csv.DictWriter(f, fieldnames=fieldnames)writer.writeheader()for item in items:@@ -314,5 +314,5 @@ When complete, briefly summarize what was collected.for key in sorted(all_keys):readme_content += f"- `{key}`\n"- with open(readme_path, "w") as f:+ with open(readme_path, "w", encoding="utf-8") as f:f.write(readme_content)diff --git a/src/reverse_api/playwright_codegen.py b/src/reverse_api/playwright_codegen.pyindex bf001b9..7e547bc 100644--- a/src/reverse_api/playwright_codegen.py+++ b/src/reverse_api/playwright_codegen.py@@ -1,5 +1,6 @@"""Generates Playwright automation scripts from recorded actions."""+import jsonfrom typing import Listfrom .action_recorder import RecordedAction@@ -15,7 +16,6 @@ class PlaywrightCodeGenerator:def _clean_actions(self, actions: List[RecordedAction]) -> List[RecordedAction]:"""Clean up actions (deduplicate fills, remove redundant events)."""cleaned = []- last_fill_selector = Nonefor i, action in enumerate(actions):# For 'fill' actions on the same selector, only keep the last one@@ -84,7 +84,7 @@ class PlaywrightCodeGenerator:if self.start_url:lines.append(f' # Start URL')- lines.append(f' page.goto("{self.start_url}")')+ lines.append(f' page.goto({json.dumps(self.start_url)})')lines.append("")current_url = self.start_url@@ -92,21 +92,20 @@ class PlaywrightCodeGenerator:for action in self.actions:if action.type == "click":- lines.append(f" page.click('{action.selector}')")+ lines.append(f" page.click({json.dumps(action.selector)})")- elif action.type == "fill" and action.value:- # Escape quotes in value- value = action.value.replace('\"', '\\\"')- lines.append(f" page.fill('{action.selector}', \"{value}\")")+ elif action.type == "fill" and action.value is not None:+ # Use json.dumps to safely escape newlines, quotes, and backslashes+ lines.append(f" page.fill({json.dumps(action.selector)}, {json.dumps(action.value)})")elif action.type == "press":- lines.append(f" page.press('{action.selector}', '{action.value}')")+ lines.append(f" page.press({json.dumps(action.selector)}, {json.dumps(action.value)})")elif action.type == "navigate":# Skip if same as start URL or very similar (just different query params)nav_base = self._get_base_url(action.url)if nav_base != last_nav_base:- lines.append(f" page.goto('{action.url}')")+ lines.append(f" page.goto({json.dumps(action.url)})")last_nav_base = nav_baseelse:continue # Skip duplicate navigation, don't add delay