Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Setting proxy for new tab in Firefox #157

Closed
t1m013y opened this issue Oct 1, 2024 · 6 comments · May be fixed by #170
Closed

Setting proxy for new tab in Firefox #157

t1m013y opened this issue Oct 1, 2024 · 6 comments · May be fixed by #170
Labels
app: Firefox Specific to Firefox area: tab-proxy Tab Proxy related issues done ✓ feature request New feature or request

Comments

@t1m013y
Copy link

t1m013y commented Oct 1, 2024

Please make it able to set proxy for new tab in Firefox. Currently I can't set proxy for new tab, I need to go to any website to do it (if I don't want someone to know I am visiting this website, I need to go to another website (e.g. google.com), then set proxy, then go to the target website).

@erosman erosman added feature request New feature or request app: Firefox Specific to Firefox area: tab-proxy Tab Proxy related issues labels Oct 1, 2024
@digletthat
Copy link

This is limited because setTabProxy checks if tab.url starts with https:// or http://. New blank tab has about:blank URL (at least in Firefox).

static setTabProxy(tab, pxy) {
// const [tab] = await browser.tabs.query({currentWindow: true, active: true});
switch (true) {
case !/https?:\/\/.+/.test(tab.url): // unacceptable URLs
case this.bypass(tab.url): // check local & global passthrough
return;
}

This also makes it impossible to set tab proxy for a page that failed to load in new tab because it's only available through proxy, one of these scenarios:

  • Open new tab
  • Enter URL of some page that is only available through proxy (i.e. inside internal network or somehow firewalled for other reasons)
  • Press Return in URL bar
  • Page fails to load
  • Press FoxyProxy toolbar button, select proxy, press "Set tab proxy" button
  • Try to load page again, page still does not load, proxy is not set

or:

  • Click a link (to a page that is available only through proxy) in existing page with middle mouse button or with control key to open it in new tab.
  • Page in new tab fails to load (it can be only opened through proxy)
  • Press FoxyProxy toolbar button, select proxy, press "Set tab proxy" button
  • Try to load page again, page still does not load, proxy is not set

In both cases, until page is loaded to some extent, tab.url attribute is still about:blank, so "set tab proxy" option does not work.

I tried to bypass that check in lines 225-229, it works, at least in Firefox and fixes described scenarios. Maybe it's safe to remove such check (remove whole switch statement) or to allow about:blank.

@erosman
Copy link
Collaborator

erosman commented Jan 4, 2025

Try this and see how it works

switch (true) { 
  case !/^(https?:\/\/.+|about:newtab)$/.test(tab.url): // unacceptable URLs 
  case this.bypass(tab.url):                            // check local & global passthrough 
    return; 
} 

@t1m013y
Copy link
Author

t1m013y commented Jan 4, 2025

When I enable proxy with some url opened and then press home button and it opens new tab in current tab, proxy is still enabled and I can open another url with proxy already enabled.

@digletthat
Copy link

digletthat commented Jan 4, 2025

Tried, it works, but in latest release (v8.9 tag). It does not work on master, where Proxy.onMessage for some reason is not called at all in new tab when selecting proxy in dropdown.

On v8.9 it works, but scenario with opening a link in new tab that I described above does not work because URL is about:blank in that case and about:newtab in "open new tab then enter URL" scenario.

So, this change worked for me:

diff --git a/src/content/on-request.js b/src/content/on-request.js
index 2c5922f..a131db0 100644
--- a/src/content/on-request.js
+++ b/src/content/on-request.js
@@ -228,7 +228,7 @@ export class OnRequest {
   static async setTabProxy(pxy) {
     const [tab] = await browser.tabs.query({currentWindow: true, active: true});
     switch (true) {
-      case !/https?:\/\/.+/.test(tab.url):                  // unacceptable URLs
+      case !/^(https?:\/\/.+|about:newtab|about:blank)$/.test(tab.url): // unacceptable URLs
       case this.bypass(tab.url):                            // check local & global passthrough
         return;
     }

Also tried it in Chrome, but seems that "set tab proxy" is not possible / not implemented in Chrome. I don't have Android devices to test Android Firefox extension.

@digletthat
Copy link

Found out that in main, popup code has its own check for acceptable tab url. After these changes it works for me on main:

diff --git a/src/content/on-request.js b/src/content/on-request.js
index d327f02..1f4853a 100644
--- a/src/content/on-request.js
+++ b/src/content/on-request.js
@@ -223,8 +223,8 @@ export class OnRequest {
   static setTabProxy(tab, pxy) {
     // const [tab] = await browser.tabs.query({currentWindow: true, active: true});
     switch (true) {
-      case !/https?:\/\/.+/.test(tab.url):                  // unacceptable URLs
-      case this.bypass(tab.url):                            // check local & global passthrough
+      case !/https?:\/\/.+|about:blank|about:newtab/.test(tab.url): // unacceptable URLs
+      case this.bypass(tab.url):                                    // check local & global passthrough
         return;
     }
 
diff --git a/src/content/popup.js b/src/content/popup.js
index 893e851..0ea0fbc 100644
--- a/src/content/popup.js
+++ b/src/content/popup.js
@@ -104,7 +104,7 @@ class Popup {
 
   static async checkTabProxy() {
     const [tab] = await browser.tabs.query({currentWindow: true, active: true});
-    if (!/https?:\/\/.+/.test(tab.url)) { return; }         // unacceptable URLs
+    if (!/https?:\/\/.+|about:blank|about:newtab/.test(tab.url)) { return; } // unacceptable URLs
 
     this.tab = tab;                                         // cache tab
     const item = await browser.runtime.sendMessage({id: 'getTabProxy'});

@erosman
Copy link
Collaborator

erosman commented Jan 9, 2025

It is done for v8.10

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
app: Firefox Specific to Firefox area: tab-proxy Tab Proxy related issues done ✓ feature request New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants