。
This commit is contained in:
		
							parent
							
								
									789a89f795
								
							
						
					
					
						commit
						174a471869
					
				
										
											Binary file not shown.
										
									
								
							@ -4,6 +4,7 @@ go 1.23.2
 | 
			
		||||
 | 
			
		||||
require (
 | 
			
		||||
	github.com/PuerkitoBio/goquery v1.10.2
 | 
			
		||||
	github.com/chromedp/chromedp v0.13.1
 | 
			
		||||
	github.com/gorilla/websocket v1.5.3
 | 
			
		||||
	github.com/ssgo/httpclient v1.7.8
 | 
			
		||||
	github.com/ssgo/log v1.7.7
 | 
			
		||||
@ -13,7 +14,13 @@ require (
 | 
			
		||||
 | 
			
		||||
require (
 | 
			
		||||
	github.com/andybalholm/cascadia v1.3.3 // indirect
 | 
			
		||||
	github.com/chromedp/cdproto v0.0.0-20250222051814-50c6cb17f10a // indirect
 | 
			
		||||
	github.com/chromedp/sysutil v1.1.0 // indirect
 | 
			
		||||
	github.com/go-json-experiment/json v0.0.0-20250211171154-1ae217ad3535 // indirect
 | 
			
		||||
	github.com/go-ole/go-ole v1.3.0 // indirect
 | 
			
		||||
	github.com/gobwas/httphead v0.1.0 // indirect
 | 
			
		||||
	github.com/gobwas/pool v0.2.1 // indirect
 | 
			
		||||
	github.com/gobwas/ws v1.4.0 // indirect
 | 
			
		||||
	github.com/gomodule/redigo v1.9.2 // indirect
 | 
			
		||||
	github.com/lufia/plan9stats v0.0.0-20240909124753-873cd0166683 // indirect
 | 
			
		||||
	github.com/power-devops/perfstat v0.0.0-20240221224432-82ca36839d55 // indirect
 | 
			
		||||
 | 
			
		||||
							
								
								
									
										27
									
								
								go/main.go
									
									
									
									
									
								
							
							
						
						
									
										27
									
								
								go/main.go
									
									
									
									
									
								
							@ -1,9 +1,12 @@
 | 
			
		||||
package main
 | 
			
		||||
 | 
			
		||||
import (
 | 
			
		||||
	"context"
 | 
			
		||||
	"github.com/chromedp/chromedp"
 | 
			
		||||
	"github.com/gorilla/websocket"
 | 
			
		||||
	"github.com/ssgo/log"
 | 
			
		||||
	"github.com/ssgo/s"
 | 
			
		||||
	"time"
 | 
			
		||||
)
 | 
			
		||||
 | 
			
		||||
var conn *websocket.Conn
 | 
			
		||||
@ -31,7 +34,29 @@ func main() {
 | 
			
		||||
			go onMessage(data)
 | 
			
		||||
		}
 | 
			
		||||
	}, "")
 | 
			
		||||
	s.Start()
 | 
			
		||||
	as := s.AsyncStart()
 | 
			
		||||
 | 
			
		||||
	// 1. 创建选项(禁用Headless模式以显示窗口)
 | 
			
		||||
	opts := append(chromedp.DefaultExecAllocatorOptions[:],
 | 
			
		||||
		chromedp.Flag("headless", false),   // 显示浏览器窗口
 | 
			
		||||
		chromedp.Flag("disable-gpu", true), // 某些环境需要禁用GPU
 | 
			
		||||
		chromedp.Flag("no-sandbox", true),  // 非沙盒模式
 | 
			
		||||
	)
 | 
			
		||||
 | 
			
		||||
	// 2. 初始化浏览器上下文
 | 
			
		||||
	ctx, cancel := chromedp.NewExecAllocator(context.Background(), opts...)
 | 
			
		||||
	defer cancel()
 | 
			
		||||
	ctx, cancel = chromedp.NewContext(ctx)
 | 
			
		||||
	defer cancel()
 | 
			
		||||
 | 
			
		||||
	// 3. 导航到网页并保持窗口打开(通过超时控制)
 | 
			
		||||
	url := "http://localhost:9000"
 | 
			
		||||
	if err := chromedp.Run(ctx,
 | 
			
		||||
		chromedp.Navigate(url),
 | 
			
		||||
		chromedp.Sleep(365*24*time.Hour), // 设置长期等待(避免立即退出)
 | 
			
		||||
	); err != nil {
 | 
			
		||||
		as.Stop()
 | 
			
		||||
	}
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func onMessage(data *Message) {
 | 
			
		||||
 | 
			
		||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user