Skip to content

Conversation

@SYM01
Copy link
Collaborator

@SYM01 SYM01 commented Dec 7, 2025

No description provided.

@gemini-code-assist
Copy link

Summary of Changes

Hello @SYM01, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request significantly enhances the 'Auto Switch' proxy mode by introducing intelligent, per-tab profile detection. It allows the extension to automatically identify and display the proxy profile being used for the active browser tab based on a set of configurable rules. This feature aims to provide users with greater transparency and control over their proxy settings in dynamic browsing environments.

Highlights

  • Per-Tab Profile Detection: Introduced a new mechanism to detect and apply specific proxy profiles for individual browser tabs when the 'Auto Switch' mode is active. This allows the extension to dynamically determine the most suitable proxy based on the current tab's URL.
  • Dynamic UI Feedback: Added a new UI component, AutoModeActionBar, to the extension's popup. This component displays the currently detected proxy profile for the active tab, providing immediate visual feedback to the user about which proxy is in use.
  • Enhanced Badge Indicator: The extension's badge indicator can now be updated on a per-tab basis, reflecting the proxy profile detected for the currently active tab. This improves clarity and user experience.
  • PAC Script Simulation: Implemented core PAC (Proxy Auto-Configuration) script functions like shExpMatch and isInNet directly within the extension. This enables robust evaluation of 'Auto Switch' rules (domain, URL, CIDR) without relying on external PAC script execution.
  • Web Request Statistics Service: A new WebRequestStatsService has been added to track web request activity, including failed requests and the detected profile for each tab. This service facilitates the new UI feedback and can be extended for future monitoring or debugging.
  • Browser API Integration: Extended the browser adapter layer to support new APIs for tab management (getActiveTab, onTabRemoved), inter-script messaging (onMessage, sendMessage), and more granular web request event listening (onWebRequestResponseStarted), which are crucial for the new detection capabilities.
  • Dependency Updates: Updated various project dependencies, including Sentry, VueUse, Acorn, Espree, ipaddr.js, Vue, Vue Router, Arco Design, Vite plugins, and TypeScript, ensuring the project uses recent and stable versions.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request introduces a new feature to display per-tab proxy usage statistics and detection information, particularly for 'auto-switch' proxy profiles. Key changes include adding activeTab permission to manifest.json, updating numerous dependencies in package.json, and introducing new internationalization messages for auto-mode detection. The core functionality involves refactoring browser adapter types and methods (src/adapters/base.ts, chrome.ts, firefox.ts, web.ts) to support per-tab badge updates, tab removal events, and inter-extension messaging. A new WebRequestStatsService is implemented in src/services/stats.ts to track failed requests and the currently detected proxy profile for each tab, utilizing a new pacSimulator.ts for PAC script evaluation logic. The background.ts script is updated to initialize this stats service, listen for web request events (response started, errors, tab removal), and dynamically update the browser action badge for specific tabs. A new AutoModeActionBar.vue component is added to the popup UI (PopupPage.vue) to display the detected proxy profile for the active tab when in auto-switch mode. Review comments highlight issues with the onWebRequestAuthRequired signature in base.ts and its implementations, suggesting a promise-based approach for better handling of async operations and fixing a critical proxy authentication bug. Additionally, several test cases in profile2config.test.ts are identified as having incorrect expectations regarding how findProfile should behave for non-auto and auto-switch profiles, and a setTimeout workaround in background.ts is flagged for needing a link to the relevant Chrome bug report. A block of commented-out mocking code in AutoModeActionBar.vue is also noted for removal.

Comment on lines 96 to +101
abstract onWebRequestAuthRequired(
callback: (
details: WebAuthenticationChallengeDetails,
callback?: (response: BlockingResponse) => void
) => void
asyncCallback?: (response: BlockingResponse) => void
) => BlockingResponse | undefined
): void;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

critical

The signature of onWebRequestAuthRequired is overly complex and attempts to support both Manifest V2 (callback-based) and V3 (promise-based) async models in a way that is causing bugs. A cleaner approach is to use a promise-based signature, which is supported in both modern Chrome and Firefox.

This change is part of a fix for a critical bug in proxy authentication. Please see the related comments in src/background.ts, src/adapters/chrome.ts, and src/adapters/firefox.ts.

  abstract onWebRequestAuthRequired(
    callback: (
      details: WebAuthenticationChallengeDetails
    ) => Promise<BlockingResponse | undefined>
  ): void;

Comment on lines 109 to 120
onWebRequestAuthRequired(
callback: (
details: WebAuthenticationChallengeDetails,
callback?: (response: BlockingResponse) => void
) => void
asyncCallback?: (response: BlockingResponse) => void
) => BlockingResponse | undefined
): void {
browser.webRequest.onAuthRequired.addListener(
callback,
callback as any,
{ urls: ["<all_urls>"] },
["asyncBlocking"]
);
}

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

critical

Following the proposed change in base.ts to use a promise-based callback for onWebRequestAuthRequired, this implementation can be simplified. The asyncBlocking option allows the listener to return a promise, and the as any cast is no longer needed. This fixes a critical bug in proxy authentication.

  onWebRequestAuthRequired(
    callback: (
      details: WebAuthenticationChallengeDetails
    ) => Promise<BlockingResponse | undefined>
  ): void {
    browser.webRequest.onAuthRequired.addListener(
      callback,
      { urls: ["<all_urls>"] },
      ["asyncBlocking"]
    );
  }

Comment on lines 205 to 216
test("auto profile with domain rule match", async () => {
const profile = new ProfileConverter(profiles.autoProxy, profileLoader);
const url = new URL("https://test.example.com");
const result = await profile.findProfile(url);

// When a rule matches a proxy profile, findProfile on proxy returns undefined
// So it falls back to default profile
expect(result.profile).toBeDefined();
const config = await result.profile!.toProxyConfig();
expect(config.mode).toBe("direct"); // Falls back to default
expect(result.isConfident).toBe(true);
});

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

high

This test's expectation is incorrect based on the implementation of findProfile. When a rule in an auto-switch profile matches, findProfile should return the matched sub-profile, not fall back to the default profile. Here, https://test.example.com matches the *.example.com rule, which points to simpleProxy. The result should be the simpleProxy profile. The test incorrectly expects the direct (default) profile.

  test("auto profile with domain rule match", async () => {
    const profile = new ProfileConverter(profiles.autoProxy, profileLoader);
    const url = new URL("https://test.example.com");
    const result = await profile.findProfile(url);

    expect(result.profile).toBeDefined();
    expect(result.profile!.profile.profileID).toBe("simpleProxy");
    expect(result.isConfident).toBe(true);
  });

Comment on lines 462 to 471
test("proxy profile (non-auto) should return undefined", async () => {
const profile = new ProfileConverter(profiles.simpleProxy);
const url = new URL("https://example.com");
const result = await profile.findProfile(url);

// Proxy profiles are not handled by findProfile, should return undefined
expect(result.profile).toBeUndefined();
expect(result.isConfident).toBe(true);
});
});

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

high

This test has an incorrect expectation. The findProfile method is designed to find the terminal profile to use for a given URL. For a non-auto profile (like a simple proxy), it should return itself, as it is the terminal profile. The implementation correctly returns { profile: this, isConfident: true }. However, this test expects result.profile to be undefined. This test should be corrected to reflect the implementation's logic. Several other tests in this file seem to be based on this wrong assumption and should also be reviewed.

  test("proxy profile (non-auto) should return itself", async () => {
    const profile = new ProfileConverter(profiles.simpleProxy);
    const url = new URL("https://example.com");
    const result = await profile.findProfile(url);

    expect(result.profile).toBe(profile);
    expect(result.isConfident).toBe(true);
  });


if (ret.profile && ret.isConfident) {
const profile = ret.profile.profile;
setTimeout(() => setIndicator(profile, details.tabId), 50); // Sometimes the indicator doesn't update properly in Chrome, so we need to wait a bit.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

Using setTimeout with a magic number like 50 is a code smell and can lead to race conditions or flaky behavior. The comment mentions it's a workaround for a Chrome bug. For better maintainability, please add a link to the corresponding Chrome bug report. This will provide context for future developers and help track if/when the workaround can be removed.

Comment on lines +22 to +44
// mocking
// tabStats.value = {
// failedRequests: [],
// currentProfile: {
// profile: {
// profileID: "profile1",
// profileName: "Profile 1",
// proxyType: "proxy",
// color: "#000000",
// proxyRules: {
// default: {
// host: "127.0.0.1",
// port: 8080,
// },
// bypassList: [],
// },
// },
// isConfident: true,
// },
// tabID: props.currentTab.id,
// };
// console.log(tabStats.value);
};

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

This block of commented-out code seems to be for mocking/testing purposes. It should be removed before merging the pull request to keep the codebase clean.

@SYM01 SYM01 merged commit 1ae0b96 into develop Dec 7, 2025
6 checks passed
SYM01 added a commit that referenced this pull request Dec 7, 2025
* update github action

* minor change to System profile

* Build(deps): Bump nanoid from 3.3.7 to 3.3.8 (#21)

Bumps [nanoid](https://github.com/ai/nanoid) from 3.3.7 to 3.3.8.
- [Release notes](https://github.com/ai/nanoid/releases)
- [Changelog](https://github.com/ai/nanoid/blob/main/CHANGELOG.md)
- [Commits](ai/nanoid@3.3.7...3.3.8)

---
updated-dependencies:
- dependency-name: nanoid
  dependency-type: indirect
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>

* Avoid blocking 401 authentication request (#22) (#23)

* fix 401 issue (#22)

* enablle github action on develop branch

* Support Firefox (#18)

* Adapt firefox
* support firefore auto publish
* support firefox, and optimized UX

* [i18n] Updates for file public/_locales/en/messages.json (#25)

* [i18n] Translate messages.json in pt_BR

100% reviewed source file: 'messages.json'
on 'pt_BR'.

* [i18n] Translate messages.json in zh_CN

100% reviewed source file: 'messages.json'
on 'zh_CN'.

* [i18n] Translate messages.json in zh_TW

100% reviewed source file: 'messages.json'
on 'zh_TW'.

* [i18n] Translate messages.json in pt_BR

100% reviewed source file: 'messages.json'
on 'pt_BR'.

* update English i18n msg

---------

Co-authored-by: transifex-integration[bot] <43880903+transifex-integration[bot]@users.noreply.github.com>
Co-authored-by: SYM01 <33443792+SYM01@users.noreply.github.com>

* sentry integration (#29)

* [WIP] support exporting

* [WIP] support import/export settings (#7)

* Support import/export profiles and close #7 (#30)

* implemented an utility to export/import settings

* optimized description

* [i18n] Updates for file public/_locales/en/messages.json (#32)

* [i18n] Translate messages.json in pt_BR

100% reviewed source file: 'messages.json'
on 'pt_BR'.

* [i18n] Translate messages.json in zh_TW

100% reviewed source file: 'messages.json'
on 'zh_TW'.

* [i18n] Translate messages.json in zh_CN

100% reviewed source file: 'messages.json'
on 'zh_CN'.

---------

Co-authored-by: transifex-integration[bot] <43880903+transifex-integration[bot]@users.noreply.github.com>

* fix an import issue (#33) (#35)

* optimized sentry release

* Optimize Development Flow  (#37)

* [WIP] support chrome auto deploy

* finalize Chrome auto deploy

* npm audit fix

* npm audit fix

* UX improvement and close #28 (#38)

* minor bug fixed

* improve UX and close #28

* use the same CIDR validator as PAC script

* [i18n] Updates for file public/_locales/en/messages.json (#40)

* [i18n] Translate messages.json in pt_BR

100% reviewed source file: 'messages.json'
on 'pt_BR'.

* [i18n] Translate messages.json in zh_TW

100% reviewed source file: 'messages.json'
on 'zh_TW'.

* [i18n] Translate messages.json in zh_CN

100% reviewed source file: 'messages.json'
on 'zh_CN'.

---------

Co-authored-by: transifex-integration[bot] <43880903+transifex-integration[bot]@users.noreply.github.com>

* Support Authentication in Auto Switch Profiles, fixing #34 (#45)

* update deps

* fix the auth issue in auto switch profiles

* fix typo

* Support Profile Detection for the Auto Profiles (#42) (#50)

* [WIP] Reflect current profile when using auto profile (#42)

* Show detected profile in the popup

* simplify test cases

---------

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Co-authored-by: transifex-integration[bot] <43880903+transifex-integration[bot]@users.noreply.github.com>
SYM01 added a commit that referenced this pull request Dec 7, 2025
* update github action

* minor change to System profile

* Build(deps): Bump nanoid from 3.3.7 to 3.3.8 (#21)

Bumps [nanoid](https://github.com/ai/nanoid) from 3.3.7 to 3.3.8.
- [Release notes](https://github.com/ai/nanoid/releases)
- [Changelog](https://github.com/ai/nanoid/blob/main/CHANGELOG.md)
- [Commits](ai/nanoid@3.3.7...3.3.8)

---
updated-dependencies:
- dependency-name: nanoid
  dependency-type: indirect
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>

* Avoid blocking 401 authentication request (#22) (#23)

* fix 401 issue (#22)

* enablle github action on develop branch

* Support Firefox (#18)

* Adapt firefox
* support firefore auto publish
* support firefox, and optimized UX

* [i18n] Updates for file public/_locales/en/messages.json (#25)

* [i18n] Translate messages.json in pt_BR

100% reviewed source file: 'messages.json'
on 'pt_BR'.

* [i18n] Translate messages.json in zh_CN

100% reviewed source file: 'messages.json'
on 'zh_CN'.

* [i18n] Translate messages.json in zh_TW

100% reviewed source file: 'messages.json'
on 'zh_TW'.

* [i18n] Translate messages.json in pt_BR

100% reviewed source file: 'messages.json'
on 'pt_BR'.

* update English i18n msg

---------

Co-authored-by: transifex-integration[bot] <43880903+transifex-integration[bot]@users.noreply.github.com>
Co-authored-by: SYM01 <33443792+SYM01@users.noreply.github.com>

* sentry integration (#29)

* [WIP] support exporting

* [WIP] support import/export settings (#7)

* Support import/export profiles and close #7 (#30)

* implemented an utility to export/import settings

* optimized description

* [i18n] Updates for file public/_locales/en/messages.json (#32)

* [i18n] Translate messages.json in pt_BR

100% reviewed source file: 'messages.json'
on 'pt_BR'.

* [i18n] Translate messages.json in zh_TW

100% reviewed source file: 'messages.json'
on 'zh_TW'.

* [i18n] Translate messages.json in zh_CN

100% reviewed source file: 'messages.json'
on 'zh_CN'.

---------

Co-authored-by: transifex-integration[bot] <43880903+transifex-integration[bot]@users.noreply.github.com>

* fix an import issue (#33) (#35)

* optimized sentry release

* Optimize Development Flow  (#37)

* [WIP] support chrome auto deploy

* finalize Chrome auto deploy

* npm audit fix

* npm audit fix

* UX improvement and close #28 (#38)

* minor bug fixed

* improve UX and close #28

* use the same CIDR validator as PAC script

* [i18n] Updates for file public/_locales/en/messages.json (#40)

* [i18n] Translate messages.json in pt_BR

100% reviewed source file: 'messages.json'
on 'pt_BR'.

* [i18n] Translate messages.json in zh_TW

100% reviewed source file: 'messages.json'
on 'zh_TW'.

* [i18n] Translate messages.json in zh_CN

100% reviewed source file: 'messages.json'
on 'zh_CN'.

---------

Co-authored-by: transifex-integration[bot] <43880903+transifex-integration[bot]@users.noreply.github.com>

* Support Authentication in Auto Switch Profiles, fixing #34 (#45)

* update deps

* fix the auth issue in auto switch profiles

* fix typo

* Support Profile Detection for the Auto Profiles (#42) (#50)

* [WIP] Reflect current profile when using auto profile (#42)

* Show detected profile in the popup

* simplify test cases

* [i18n] Updates for file public/_locales/en/messages.json (#52)

* [i18n] Translate messages.json in zh_TW

100% reviewed source file: 'messages.json'
on 'zh_TW'.

* [i18n] Translate messages.json in zh_CN

100% reviewed source file: 'messages.json'
on 'zh_CN'.

* [i18n] Translate messages.json in pt_BR

100% reviewed source file: 'messages.json'
on 'pt_BR'.

---------

Co-authored-by: transifex-integration[bot] <43880903+transifex-integration[bot]@users.noreply.github.com>

---------

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Co-authored-by: transifex-integration[bot] <43880903+transifex-integration[bot]@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants