feat: Change default search provider to DuckDuckGo and add custom headers for Google search requests
This commit is contained in:
parent
51804bc9ae
commit
8c0706aa7c
@ -6,7 +6,7 @@ const storage2 = new Storage({
|
|||||||
})
|
})
|
||||||
|
|
||||||
const TOTAL_SEARCH_RESULTS = 2
|
const TOTAL_SEARCH_RESULTS = 2
|
||||||
const DEFAULT_PROVIDER = "google"
|
const DEFAULT_PROVIDER = "duckduckgo"
|
||||||
|
|
||||||
const AVAILABLE_PROVIDERS = ["google", "duckduckgo"] as const
|
const AVAILABLE_PROVIDERS = ["google", "duckduckgo"] as const
|
||||||
|
|
||||||
|
@ -28,12 +28,23 @@ export const localGoogleSearch = async (query: string) => {
|
|||||||
const htmlString = await fetch(
|
const htmlString = await fetch(
|
||||||
`https://www.${baseGoogleDomain}/search?hl=en&q=` + query,
|
`https://www.${baseGoogleDomain}/search?hl=en&q=` + query,
|
||||||
{
|
{
|
||||||
signal: abortController.signal
|
signal: abortController.signal,
|
||||||
|
headers: {
|
||||||
|
"User-Agent": navigator.userAgent,
|
||||||
|
"Accept": "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8",
|
||||||
|
"Accept-Language": "en-US,en;q=0.5",
|
||||||
|
"Accept-Encoding": "gzip, deflate, br",
|
||||||
|
"DNT": "1",
|
||||||
|
"Connection": "keep-alive",
|
||||||
|
"Upgrade-Insecure-Requests": "1",
|
||||||
|
"Sec-Fetch-Dest": "document",
|
||||||
|
"Sec-Fetch-Mode": "navigate",
|
||||||
|
"Sec-Fetch-Site": "none",
|
||||||
|
"Sec-Fetch-User": "?1"
|
||||||
}
|
}
|
||||||
)
|
}
|
||||||
.then((response) => response.text())
|
).then((response) => response.text())
|
||||||
.catch()
|
.catch()
|
||||||
|
|
||||||
const parser = new DOMParser()
|
const parser = new DOMParser()
|
||||||
|
|
||||||
const doc = parser.parseFromString(htmlString, "text/html")
|
const doc = parser.parseFromString(htmlString, "text/html")
|
||||||
|
Loading…
x
Reference in New Issue
Block a user