Skip to content

Commit

Permalink
added kiosk mode
Browse files Browse the repository at this point in the history
added incognito mode
added Fullscreen mode
  • Loading branch information
leandroveronezi committed Jul 6, 2021
1 parent 4039329 commit 872ff37
Show file tree
Hide file tree
Showing 3 changed files with 97 additions and 34 deletions.
63 changes: 47 additions & 16 deletions browser.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package proton

import (
"bufio"
"encoding/base64"
"encoding/json"
"errors"
"fmt"
Expand Down Expand Up @@ -205,7 +206,7 @@ func (c *Browser) readLoop() {
}{}
json.Unmarshal(m.Params, &params)
if params.TargetID == c.target {
c.kill()
c.kill(true)
return
}
}
Expand Down Expand Up @@ -358,17 +359,6 @@ func (c *Browser) NetworkDisable() error {

}

/*
maxPostDataSize
func (c *Browser) NetworkEnable() error {
_, err := c.send("Network.enable", h{})
return err
}
*/

func (c *Browser) close() error {

_, err := c.send("Browser.close ", h{})
Expand All @@ -393,7 +383,7 @@ func (c *Browser) CaptureScreenshot(Parameters ScreenshotParameters) (string, er

}

func (c *Browser) kill() error {
func (c *Browser) kill(exited bool) error {

if c.ws != nil {

Expand All @@ -403,6 +393,10 @@ func (c *Browser) kill() error {

}

if exited {
return nil
}

// TODO: cancel all pending requests
if state := c.cmd.ProcessState; state == nil || !state.Exited() {

Expand All @@ -416,7 +410,7 @@ func (c *Browser) kill() error {
return err
}

//return c.cmd.Process.Kill()
return c.cmd.Process.Kill()
}

return nil
Expand Down Expand Up @@ -639,8 +633,9 @@ func (_this *Browser) Done() <-chan struct{} {
}

func (_this *Browser) Close() error {

// ignore err, as the chrome process might be already dead, when user close the window.
_this.kill()
_this.kill(false)
<-_this.done

if !_this.config.UserDataDirKeep {
Expand All @@ -654,10 +649,46 @@ func (_this *Browser) Close() error {

func (_this *Browser) genEmptyHtml() string {

template := `data:text/html,<!DOCTYPE html><html><head><title>{{title}}</title></head><body></body></html>`
template := `<!DOCTYPE html><html><head><title>{{title}}</title></head><body></body></html>`

/*
template := `
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>{{title}}</title>
<style>
body, html {
margin: 0;
padding: 0;
}
html,body{height:100%;overflow:hidden}body{background:linear-gradient(to left, #141E30, #243B55);transform:scale(1.2, 1.2)}body>div{border-radius:50%;border:1px solid #fff;transform-style:preserve-3d;transform:rotateX(80deg) rotateY(20deg);position:absolute;left:50%;top:50%;margin-left:-100px;margin-top:-100px}body>div:first-of-type:after{content:"";position:absolute;height:40px;width:40px;background:#fff;border-radius:50%;transform:rotateX(-80deg) rotateY(0);box-shadow:0 0 25px #fff;animation:nucleus_ 2s infinite linear;left:50%;top:50%;margin-top:-20px;margin-left:-20px}body>div:nth-of-type(2){transform:rotateX(-80deg) rotateY(20deg)}body>div:nth-of-type(2)>div,body>div:nth-of-type(2)>div:after{animation-delay:-.5s}body>div:nth-of-type(3){transform:rotateX(-70deg) rotateY(60deg)}body>div:nth-of-type(3)>div,body>div:nth-of-type(3)>div:after{animation-delay:-1s}body>div:nth-of-type(4){transform:rotateX(70deg) rotateY(60deg)}body>div:nth-of-type(4)>div,body>div:nth-of-type(4)>div:after{animation-delay:-1.5s}body>div>div{width:200px;height:200px;position:relative;transform-style:preserve-3d;animation:trail_ 2s infinite linear}body>div>div:after{content:"";position:absolute;top:-5px;box-shadow:0 0 12px #fff;left:50%;margin-left:-5px;width:5px;height:5px;border-radius:50%;background-color:#fff;animation:particle_ 2s infinite linear}@keyframes trail_{from{transform:rotateZ(0deg)}to{transform:rotateZ(360deg)}}@keyframes particle_{from{transform:rotateX(90deg) rotateY(0deg)}to{transform:rotateX(90deg) rotateY(-360deg)}}@keyframes nucleus_{0%, 100%{box-shadow:0 0 0 transparent}50%{box-shadow:0 0 25px #fff}}
</style>
</head>
<body>
<div>
<div></div>
</div>
<div>
<div></div>
</div>
<div>
<div></div>
</div>
<div>
<div></div>
</div>
</body></html>
`
*/

template = strings.ReplaceAll(template, "{{title}}", _this.config.Title)

template = "data:text/html;base64," + base64.StdEncoding.EncodeToString([]byte(template))

return template

}
28 changes: 17 additions & 11 deletions config.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,23 @@ const (
)

type Config struct {
Title string
Url string
Debug bool
UserDataDir string
UserDataDirKeep bool
Width int
Height int
WindowState WindowState
Flavor flavor
Args []string
BrowserBinary string
Title string
Url string
Debug bool
UserDataDir string
UserDataDirKeep bool
Width int
Height int
WindowState WindowState
StartFullscreen bool
Kiosk bool
KioskPrinting bool
Incognito bool
RestoreLastSession bool
SilentLaunch bool
Flavor flavor
Args []string
BrowserBinary string
}

var DefaultBrowserArgs = []string{
Expand Down
40 changes: 33 additions & 7 deletions gui.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,33 @@ func (_this *Browser) Run(conf ...Config) error {
}

if _this.config.Debug {
args = append(args, "--auto-open-devtools-for-tabs")
//args = append(args, "--auto-open-devtools-for-tabs")
//args = append(args, "--force-devtools-available")
}

if _this.config.StartFullscreen {
args = append(args, "--start-fullscreen")
}

if _this.config.Kiosk {
args = append(args, "--kiosk")
}

if _this.config.KioskPrinting {
args = append(args, "--kiosk-printing")
}

if _this.config.Incognito {
args = append(args, "--incognito")
args = append(args, "--start-in-incognito")
}

if _this.config.RestoreLastSession {
args = append(args, "--restore-last-session")
}

if _this.config.SilentLaunch {
args = append(args, "--silent-launch")
}

args = append(args, "--remote-debugging-port=0")
Expand Down Expand Up @@ -81,28 +107,28 @@ func (_this *Browser) makeBrowser() error {
re := regexp.MustCompile(`^DevTools listening on (ws://.*?)\r?\n$`)
m, err := readUntilMatch(pipe, re)
if err != nil {
_this.kill()
_this.kill(false)
return err
}
wsURL := m[1]

// Open a websocket
_this.ws, err = websocket.Dial(wsURL, "", "http://127.0.0.1")
if err != nil {
_this.kill()
_this.kill(false)
return err
}

// Find target and initialize session
_this.target, err = _this.findTarget()
if err != nil {
_this.kill()
_this.kill(false)
return err
}

_this.session, err = _this.startSession(_this.target)
if err != nil {
_this.kill()
_this.kill(false)
return err
}

Expand All @@ -119,7 +145,7 @@ func (_this *Browser) makeBrowser() error {
} {

if _, err := _this.send(method, args); err != nil {
_this.kill()
_this.kill(false)
_this.cmd.Wait()
return err
}
Expand All @@ -129,7 +155,7 @@ func (_this *Browser) makeBrowser() error {
if !contains(_this.config.Args, "--headless") {
win, err := _this.getWindowForTarget(_this.target)
if err != nil {
_this.kill()
_this.kill(false)
return err
}
_this.window = win.WindowID
Expand Down

0 comments on commit 872ff37

Please sign in to comment.