Skip to content
This repository has been archived by the owner on Jun 30, 2023. It is now read-only.

Refactored code broke it #6

Closed
rany2 opened this issue Feb 16, 2023 · 4 comments
Closed

Refactored code broke it #6

rany2 opened this issue Feb 16, 2023 · 4 comments

Comments

@rany2
Copy link

rany2 commented Feb 16, 2023

I reviewed https://github.com/anaclumos/bing-chat-for-all-browsers/blob/main/src/background.ts#L12-L13

Basically you set header.value to DESKTOP_UA and then check if it contains 'mobile', which will never happen because you set header.value to DESKTOP_UA.

@rany2
Copy link
Author

rany2 commented Feb 16, 2023

Suggested change:

chrome.webRequest.onBeforeSendHeaders.addListener(
  (details) => {
    const { requestHeaders } = details
    if (!requestHeaders) return undefined
    const newHeaders = requestHeaders.map((header) => {
      if (header.name.toLowerCase() === 'user-agent') {
        if (header.value?.toLowerCase().includes('mobile'))
          header.value = MOBILE_UA;
        else
          header.value = DESKTOP_UA;
      }
      return header
    })
    return { requestHeaders: newHeaders }
  },
  { urls: ['*://*.bing.com/*'] },
  ['blocking', 'requestHeaders']
)

@anaclumos
Copy link
Owner

Oh, what a newbie mistake. Will issue a fix right away.

@rany2
Copy link
Author

rany2 commented Feb 16, 2023

Thanks, I was confused for a second and thought it was my fault :)

@rany2 rany2 closed this as completed Feb 16, 2023
@rany2
Copy link
Author

rany2 commented Feb 16, 2023

Thanks!

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants