anaclumos / bing-chat-for-all-browsers

Enable Bing ChatGPT on Chrome and Firefox
https://chrome.google.com/webstore/detail/bing-chat-for-all-browser/jofbglonpbndadajbafmmaklbfbkggpo
MIT License
1.49k stars 110 forks source link

Simplify the code & optimized firefox detection #112

Closed alescdb closed 1 year ago

alescdb commented 1 year ago

It should work with all browsers (including mobile) and solved #109

anaclumos commented 1 year ago

It is important to note that the Firefox Extension utilizes Manifest V2, which Chrome no longer supports. This means that V2-specific codes such as chrome.webRequest.onBeforeSendHeaders.addListener cannot be executed on Chrome. This code only runs on Firefox, albeit the confusing name.

alescdb commented 1 year ago

Firefox detection at runtime seems "useless" and can be done while transpiling ts (this will remote firefox specific code for chrome), e.g. :

Define a environment variable in webpack (chrome & fiorefox):

    new webpack.DefinePlugin({
      firefox: JSON.stringify(false),
    }),

And in background.ts :

declare var firefox : boolean | undefined;
  if (firefox) {
    console.log("Firefox !");
  } else {
    console.log("Chrome !");
  }

The transpiled js for firefox extension wil only contains :

console.log("Firefox !");

same for chrome :

console.log("Chrome !");
anaclumos commented 1 year ago

That optimization idea is fantastic!

Would it be possible for you to handle the Webpack implementation? I'm not very experienced with defining custom configurations.

alescdb commented 1 year ago

Done (sorry for the delay) :-)