patch: fix(upgrade) bing client (#505)

This commit is contained in:
josc146
2023-09-06 23:52:28 +08:00
parent 97c04c2464
commit e71ee74c6d
9 changed files with 288 additions and 123 deletions
+30
View File
@@ -0,0 +1,30 @@
import Browser from 'webextension-polyfill'
/**
* @param {RequestInfo|URL} input
* @param {RequestInit=} init
* @returns {Promise<Response>}
*/
export function fetchBg(input, init) {
return new Promise((resolve, reject) => {
Browser.runtime
.sendMessage({
type: 'FETCH',
data: { input, init },
})
.then((messageResponse) => {
const [response, error] = messageResponse
if (response === null) {
reject(error)
} else {
const body = response.body ? new Blob([response.body]) : undefined
resolve(
new Response(body, {
status: response.status,
statusText: response.statusText,
}),
)
}
})
})
}