Compare commits
1 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
40f683a917 |
@@ -27,10 +27,6 @@ type Converter struct {
|
|||||||
func NewConverter(chromePath string) (*Converter, error) {
|
func NewConverter(chromePath string) (*Converter, error) {
|
||||||
var err error
|
var err error
|
||||||
|
|
||||||
if runtime.GOOS == "windows" {
|
|
||||||
hideConsole()
|
|
||||||
}
|
|
||||||
|
|
||||||
c := &Converter{chromePath: chromePath}
|
c := &Converter{chromePath: chromePath}
|
||||||
chromePath, err = c.getChromePath()
|
chromePath, err = c.getChromePath()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -42,13 +38,10 @@ func NewConverter(chromePath string) (*Converter, error) {
|
|||||||
chromedp.NoSandbox,
|
chromedp.NoSandbox,
|
||||||
chromedp.Headless,
|
chromedp.Headless,
|
||||||
chromedp.DisableGPU,
|
chromedp.DisableGPU,
|
||||||
chromedp.NoFirstRun,
|
|
||||||
chromedp.Flag("remote-debugging-port", "0"),
|
|
||||||
chromedp.Flag("disable-extensions", true),
|
|
||||||
chromedp.Flag("disable-software-rasterizer", true),
|
|
||||||
chromedp.Flag("disable-dev-shm-usage", true),
|
|
||||||
)
|
)
|
||||||
|
|
||||||
|
opts = append(opts, platformOptions())
|
||||||
|
|
||||||
var allocCtx context.Context
|
var allocCtx context.Context
|
||||||
allocCtx, c.cancel = chromedp.NewExecAllocator(context.Background(), opts...)
|
allocCtx, c.cancel = chromedp.NewExecAllocator(context.Background(), opts...)
|
||||||
c.ctx, c.cancel = chromedp.NewContext(allocCtx)
|
c.ctx, c.cancel = chromedp.NewContext(allocCtx)
|
||||||
|
|||||||
@@ -2,8 +2,9 @@
|
|||||||
|
|
||||||
package converter
|
package converter
|
||||||
|
|
||||||
// hideConsole does nothing on non-Windows systems
|
import "github.com/chromedp/chromedp"
|
||||||
func hideConsole() {
|
|
||||||
// macOS and Linux don't have the same "console window" concept
|
func platformOptions() chromedp.ExecAllocatorOption {
|
||||||
// that needs manual hiding at runtime like Windows.
|
// Returns a no-op option for Mac/Linux
|
||||||
|
return chromedp.NoSandbox
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,21 +3,18 @@
|
|||||||
package converter
|
package converter
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"os/exec"
|
||||||
"syscall"
|
"syscall"
|
||||||
|
|
||||||
|
"github.com/chromedp/chromedp"
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
func platformOptions() chromedp.ExecAllocatorOption {
|
||||||
kernel32 = syscall.NewLazyDLL("kernel32.dll")
|
return chromedp.ModifyCmdFunc(func(cmd *exec.Cmd) {
|
||||||
user32 = syscall.NewLazyDLL("user32.dll")
|
if cmd.SysProcAttr == nil {
|
||||||
getConsoleWindow = kernel32.NewProc("GetConsoleWindow")
|
cmd.SysProcAttr = &syscall.SysProcAttr{}
|
||||||
showWindow = user32.NewProc("ShowWindow")
|
}
|
||||||
)
|
cmd.SysProcAttr.HideWindow = true
|
||||||
|
cmd.SysProcAttr.CreationFlags = 0x08000000 // CREATE_NO_WINDOW
|
||||||
const SW_HIDE = 0
|
})
|
||||||
|
|
||||||
func hideConsole() {
|
|
||||||
hwnd, _, _ := getConsoleWindow.Call()
|
|
||||||
if hwnd != 0 {
|
|
||||||
showWindow.Call(hwnd, SW_HIDE)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -42,7 +42,7 @@ func TestConvertFiles(t *testing.T) {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
c, err := converter.NewConverter("./assets")
|
c, err := converter.NewConverter("assets/chrome-headless-shell/win64")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user