DuckDuckGo now makes POST requests for search#71
DuckDuckGo now makes POST requests for search#71spj2401Dev wants to merge 3 commits intoprem-k-r:mainfrom
Conversation
There was a problem hiding this comment.
Pull Request Overview
This PR modifies the search functionality to use POST requests specifically for DuckDuckGo searches instead of GET requests. This change addresses issue #60 by implementing a search method that DuckDuckGo supports, while maintaining GET requests for other search engines that don't support POST.
- Added a dedicated configuration object for DuckDuckGo with URL and parameter mapping
- Implemented a new
submitPostSearchfunction that creates and submits a hidden form for POST requests - Modified the search logic to route DuckDuckGo searches through the POST method while keeping other engines unchanged
Reviewed Changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| scripts/search.js | Added DuckDuckGo POST request configuration and implementation with form submission logic |
| CHANGELOG.md | Updated to document the change from GET to POST requests for DuckDuckGo searches |
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
|
@coderabbitai review |
This comment was marked as off-topic.
This comment was marked as off-topic.
|
Note Other AI code review bot(s) detectedCodeRabbit has detected other AI code review bot(s) in this pull request and will avoid duplicating their findings in the review comments. This may lead to a less comprehensive review. WalkthroughThis PR adds POST request support for DuckDuckGo searches, replacing the previous GET-based approach. A new configuration object and Changes
Sequence DiagramsequenceDiagram
participant User
participant performSearch
participant submitPostSearch
participant Browser
User->>performSearch: Initiate search with engine2 (DuckDuckGo)
alt DuckDuckGo (engine2)
performSearch->>submitPostSearch: Call with search term
submitPostSearch->>Browser: Create hidden form
Browser->>Browser: Set form action, method=POST
Browser->>Browser: Append hidden input with search term
Browser->>Browser: Submit form
else Other Engines (engine0, engine1)
performSearch->>Browser: Navigate via GET request
end
Browser->>User: Execute search
Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes
Possibly related issues
Poem
Pre-merge checks and finishing touches❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
✨ Finishing touches
🧪 Generate unit tests (beta)
Comment |
There was a problem hiding this comment.
Actionable comments posted: 0
🧹 Nitpick comments (1)
scripts/search.js (1)
238-255: Consider adding error handling for robustness.While the current implementation works correctly for the controlled use case, adding basic error handling and parameter validation would improve robustness.
Consider this enhancement:
function submitPostSearch(config, searchTerm) { + if (!config?.url || !config?.param) { + console.error("Invalid POST search configuration"); + return; + } + const form = document.createElement("form"); form.method = "POST"; form.action = config.url; form.style.display = "none"; const searchInput = document.createElement("input"); searchInput.type = "hidden"; searchInput.name = config.param; searchInput.value = searchTerm; form.appendChild(searchInput); document.body.appendChild(form); - form.submit(); - setTimeout(() => { - document.body.removeChild(form); - }, 0); + + try { + form.submit(); + setTimeout(() => { + document.body.removeChild(form); + }, 0); + } catch (error) { + console.error("Form submission failed:", error); + document.body.removeChild(form); + } }
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (2)
CHANGELOG.md(1 hunks)scripts/search.js(2 hunks)
🔇 Additional comments (4)
CHANGELOG.md (1)
67-67: LGTM!The changelog entry accurately describes the change and is properly formatted.
scripts/search.js (3)
25-29: LGTM!The configuration object provides a clean, maintainable approach for POST request handling. The structure allows for easy extension if other search engines support POST in the future.
227-229: LGTM!The routing logic correctly directs DuckDuckGo searches to the POST handler while maintaining existing GET behavior for other engines.
238-255: Implementation is correct.The hidden form submission technique is a standard approach for POST requests, and the
setTimeout(0)ensures the form is removed after submission completes.
prem-k-r
left a comment
There was a problem hiding this comment.
Hi @spj2401Dev, apologies for joining the PR late.
Could you help me understand what advantages this change provides? From my testing, even with DuckDuckGo set to POST, the search query still appears in the browser history.
|
It's not as big of a change. I think this gets mostly relevant if you are behind corporate proxies or you care for example about refere leaks. Otherwise this is not as interesting. |
📌 Description
Using this the Search button will use a POST request to search for DuckDuckGo.
The issue like described cannot be implemented as is to my knowlage as Google, Bing, etc... does not support POST requests
🎨 Visual Changes (Screenshots / Videos)
No visual changes made
🔗 Related Issues
Related to #60
This will probably need some discussing
✅ Checklist
Summary by CodeRabbit
Changed
Documentation
✏️ Tip: You can customize this high-level summary in your review settings.