Disclosure: An AI assistant wrote this article for me, based on the code of my extension.
I was tired of doing the same thing on every Amazon search. Type the term, press Enter, click Prime, change the sort. Two clicks and a second page load, every time.
An extension can do this, but the obvious way is a bit ugly. A content script waits for the page, reads the URL, and redirects to a URL with the right parameters. That loads the page twice and shows the unsorted results for a moment.
So I did it earlier.
Rewrite the URL before the request
In Firefox, a background script can use webRequest.onBeforeRequest in blocking mode. It sees the navigation before anything is sent and can return a redirectUrl. The extension looks at a search URL like /s?k=usb+c+cable, adds the Prime facet to rh and the sort value to s, and returns the new URL. The browser sends only one request.
The permissions stay small: storage, webRequest, webRequestBlocking, plus host permissions for the Amazon sites. The request filter only matches search URLs (/s*) and only main frame navigations.
Which searches count
The harder part is not rewriting. It is deciding what not to rewrite.
- A search is "fresh" only when it has a keyword (
korfield-keywords) and noref=sr_*marker. When you click a filter, change the sort, or go to the next page on the results page, Amazon adds aref=sr_*marker, and the extension leaves that URL alone. - If the URL already has a sort value (
s), the extension keeps it. A shared link keeps its sort order. - If the URL already has a Prime facet, nothing is added a second time.
- A small loop guard stops a redirect if Amazon sends the user straight back to the same URL within five seconds.
Without these rules, the extension would fight the user. You would pick "Newest" and the extension would put "Lowest price" back.
Chrome and Edge
Chrome and Edge are on Manifest V3, and there is no blocking webRequest there. So the Chromium build works differently. It uses declarativeNetRequestWithHostAccess rules that send search navigations to a small local page. That page computes the target URL with the same shared rewrite code, installs a one-time rule for the tab, and redirects. webRequest is only used to watch, and an alarm cleans up old rules. The rewrite logic is shared, only the entry point changes. The permissions stay small: storage, declarativeNetRequestWithHostAccess, webRequest, alarms, plus the 19 Amazon hosts.
Where it breaks
Amazon changes its parameters and page layout now and then. A Prime facet that works today can change. A fallback content script handles a navigation the background script could not rewrite, and shows an optional notice. I cannot promise that it keeps working without updates.
Also, sorting by price low to high is not the same as the cheapest product. Amazon decides what appears in the results, and shipping is not part of the sort.
What I would still like to know
Does this work on your Amazon site? The Prime filter is set for all 19 Amazon sites, but I cannot test every one daily, so I would like to hear where it fails.
The code is MIT licensed and has no tracking. It is not affiliated with Amazon.
Repo: https://github.com/codingismynewgaming/prime-filter-price-sort-for-amazon
Firefox: https://addons.mozilla.org/en-US/firefox/addon/amazon-all-prime-sort-price/
Chrome: https://chromewebstore.google.com/detail/prime-filter-price-sort-f/bncbmleiffadkeekjdgcofccdbpmbldl
Edge: https://microsoftedge.microsoft.com/addons/detail/prime-filter-price-sort/mhndpkgjdillpomodinlbhicpocloemf
Top comments (0)