TODO: 测试稳定性.

This commit is contained in:
eson 2020-11-20 18:24:42 +08:00
parent 94b01ccb0f
commit 4bf8705a8d
7 changed files with 76 additions and 6 deletions

View File

@ -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}"
}

View File

@ -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 };
}

View File

@ -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',

43
proxyserver/config.go Normal file
View File

@ -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)
}
}

5
proxyserver/config.yaml Normal file
View File

@ -0,0 +1,5 @@
server:
uri: "0.0.0.0:7123"
chromeproxy:
host: "http://localhost:7123"

View File

@ -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
)

View File

@ -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)
}