Setting up a proxy for a specific url in chrome extension

老子叫甜甜 提交于 2021-02-11 14:44:09

问题


I'm working on a chrome extension where a button click would trigger a function that calls a specific url and gets back the response. This specific url needs to be accessed through a proxy. All other requests are handled normally. It seemed like pac file would fit the bill nicely, but there is one problem with it. The url that I need to access through a proxy has a path in in, like so:

https://www.myurl.com/segment-1/segment-2/segment-3

The PAC example I lifted from Chrome documentation is this:

        mode: "pac_script",
        pacScript: {
          data: "function FindProxyForURL(url, host) {\n" +
                "  if (host == 'foobar.com')\n" +
                "    return 'PROXY blackhole:80';\n" +
                "  return 'DIRECT';\n" +
                "}"
        }
      };

So I was hoping that I can examine the url parameter on every request and when mine is detected, I would return a proxy. The problem, however, lies in the fact that url argument in FindProxyForURL contains only domain part of the url, https://www.myurl.com in my case. I know it because I actually put alerts inside my FindProxyForURL code and logged the url and host values.

Is this a bug? As I was searching for documentation on PAC files, I found examples where url passed in is a full url, not the stripped one, like mine (https://findproxyforurl.com/example-pac-file/).

Thank you!

来源:https://stackoverflow.com/questions/60940832/setting-up-a-proxy-for-a-specific-url-in-chrome-extension

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!