diff --git a/chromeproxy/.vscode/launch.json b/chromeproxy/.vscode/launch.json index af71799..e7e40e2 100644 --- a/chromeproxy/.vscode/launch.json +++ b/chromeproxy/.vscode/launch.json @@ -9,6 +9,20 @@ "name": "Chrome Extension debugging", "port": 9222, "type": "chrome", + "runtimeArgs": [ + "--user-data-dir=/tmp/chromeproxy-userdata", + "--ignore-certificate-errors", + "--disable-dev-shm-usage", + "--mute-audio", + "--safebrowsing-disable-auto-update", + "--disable-gpu", + "--no-sandbox", + "--disable-blink-features=AutomationControlled", + "--disable-infobars", + "--allow-running-insecure-content", + "--disable-features=TranslateUI", + "--test-type", + ], "url": "http:/localhost:7123", "webRoot": "${workspaceFolder}" } diff --git a/chromeproxy/background/worker.js b/chromeproxy/background/worker.js index 3131934..b6d8d8b 100644 --- a/chromeproxy/background/worker.js +++ b/chromeproxy/background/worker.js @@ -2,7 +2,6 @@ var task_manager = { } - function GetTask(sender) { fetch(GetTaskUrl).then(function (response) { if (response.ok) { @@ -94,7 +93,7 @@ function Tell(sender, jnjectType) { chrome.webRequest.onBeforeRequest.addListener(function (details) { if (details.url.startsWith("http://eson.config")) { var params = new URLSearchParams(details.url) - GetTaskUrl = params.get("taskurl"); + UpdateHost(params.get("taskurl")) chrome.tabs.remove(details.tabId, function () { }); return { cancel: true }; } diff --git a/chromeproxy/base.js b/chromeproxy/base.js index c1f0fa5..f695d03 100644 --- a/chromeproxy/base.js +++ b/chromeproxy/base.js @@ -5,6 +5,13 @@ var GetTaskUrl = `${Host}/task/get`; var FinishTaskUrl = `${Host}/task/content`; var ErrorTaskUrl = `${Host}/task/error`; +function UpdateHost(host) { + Host = host + GetTaskUrl = `${Host}/task/get` + FinishTaskUrl = `${Host}/task/content` + ErrorTaskUrl = `${Host}/task/error` +} + const BackgroundMsgType = { NOTWANT: 'notwant', CONTENT: 'content', diff --git a/proxyserver/config.go b/proxyserver/config.go new file mode 100644 index 0000000..b6701b9 --- /dev/null +++ b/proxyserver/config.go @@ -0,0 +1,43 @@ +package main + +import ( + "os" + "os/exec" + + "gopkg.in/yaml.v2" +) + +var config = &Config{} + +func init() { + f, err := os.Open("config.yaml") + if err != nil { + panic(err) + } + dec := yaml.NewDecoder(f) + err = dec.Decode(config) + if err != nil { + panic(err) + } +} + +// Config 本地yaml配置对象 +type Config struct { + Server struct { + URI string `yaml:"uri"` + } `yaml:"server"` + + ChromeProxy struct { + Host string `yaml:"host"` + } `yaml:"chromeproxy"` +} + +func initChromeProxy() { + err := exec.Command("google-chrome", + "http://eson.config?taskurl="+config.ChromeProxy.Host, + "--user-data-dir=/tmp/chromeproxy-userdata", + ).Run() + if err != nil { + panic(err) + } +} diff --git a/proxyserver/config.yaml b/proxyserver/config.yaml new file mode 100644 index 0000000..496c8b1 --- /dev/null +++ b/proxyserver/config.yaml @@ -0,0 +1,5 @@ +server: + uri: "0.0.0.0:7123" +chromeproxy: + host: "http://localhost:7123" + \ No newline at end of file diff --git a/proxyserver/go.mod b/proxyserver/go.mod index 8df040e..e9f73f3 100644 --- a/proxyserver/go.mod +++ b/proxyserver/go.mod @@ -16,5 +16,5 @@ require ( golang.org/x/crypto v0.0.0-20201117144127-c1f2f97bffc9 // indirect golang.org/x/sys v0.0.0-20201119102817-f84b799fce68 // indirect google.golang.org/protobuf v1.25.0 // indirect - gopkg.in/yaml.v2 v2.3.0 // indirect + gopkg.in/yaml.v2 v2.3.0 ) diff --git a/proxyserver/main.go b/proxyserver/main.go index bed3c4c..37df02c 100644 --- a/proxyserver/main.go +++ b/proxyserver/main.go @@ -1,10 +1,12 @@ package main -import "github.com/gin-gonic/gin" +import ( + "github.com/gin-gonic/gin" +) var engine = gin.New() func main() { - engine.Run(":7123") - + initChromeProxy() + engine.Run(config.Server.URI) }