├── .gitattributes ├── .github └── workflows │ └── build_gcd_v2.yml ├── .gitignore ├── CHANGELOG.md ├── LICENSE ├── README.md ├── chrome_target.go ├── examples ├── events │ ├── events.go │ └── webdata │ │ ├── iframe.html │ │ ├── target.html │ │ └── top.html ├── getdoc │ └── getdoc.go ├── loadpage │ └── loadpage.go └── screenshot │ └── screenshot.go ├── gcd.go ├── gcd_test.go ├── gcdapi ├── accessibility.go ├── animation.go ├── applicationcache.go ├── audits.go ├── backgroundservice.go ├── browser.go ├── cachestorage.go ├── cast.go ├── console.go ├── css.go ├── database.go ├── debugger.go ├── deviceorientation.go ├── dom.go ├── domdebugger.go ├── domsnapshot.go ├── domstorage.go ├── emulation.go ├── fetch.go ├── headlessexperimental.go ├── heapprofiler.go ├── indexeddb.go ├── input.go ├── inspector.go ├── io.go ├── layertree.go ├── log.go ├── media.go ├── memory.go ├── network.go ├── overlay.go ├── page.go ├── performance.go ├── profiler.go ├── runtime.go ├── schema.go ├── security.go ├── serviceworker.go ├── storage.go ├── systeminfo.go ├── target.go ├── tethering.go ├── tracing.go ├── version.go ├── webaudio.go └── webauthn.go ├── gcdapigen ├── README.md ├── api_template.txt ├── build.sh ├── command.go ├── domain.go ├── downloader.go ├── event.go ├── gcdapigen.go ├── protocol.go ├── protocol.json ├── return.go ├── template_funcs.go ├── type.go ├── type_properties.go └── utils.go ├── gcdmessage └── gcdmessage.go ├── go.mod ├── go.sum ├── testdata ├── console_log.html ├── cookie.html └── extension │ ├── .gitignore │ ├── CHANGELOG.md │ ├── README.md │ ├── _locales │ ├── en │ │ └── messages.json │ └── en_GB │ │ └── messages.json │ ├── background.js │ ├── images │ ├── icon128.png │ ├── icon38-off.png │ ├── icon38-on.png │ └── icon48.png │ └── manifest.json ├── v2 ├── chrome_target.go ├── examples │ ├── events │ │ ├── events.go │ │ └── webdata │ │ │ ├── iframe.html │ │ │ ├── target.html │ │ │ └── top.html │ ├── getdoc │ │ └── getdoc.go │ ├── loadpage │ │ └── loadpage.go │ └── screenshot │ │ └── screenshot.go ├── gcd.go ├── gcd_test.go ├── gcdapi │ ├── accessibility.go │ ├── animation.go │ ├── audits.go │ ├── autofill.go │ ├── backgroundservice.go │ ├── bluetoothemulation.go │ ├── browser.go │ ├── cachestorage.go │ ├── cast.go │ ├── console.go │ ├── css.go │ ├── database.go │ ├── debugger.go │ ├── deviceaccess.go │ ├── deviceorientation.go │ ├── dom.go │ ├── domdebugger.go │ ├── domsnapshot.go │ ├── domstorage.go │ ├── emulation.go │ ├── eventbreakpoints.go │ ├── extensions.go │ ├── fedcm.go │ ├── fetch.go │ ├── filesystem.go │ ├── headlessexperimental.go │ ├── heapprofiler.go │ ├── indexeddb.go │ ├── input.go │ ├── inspector.go │ ├── io.go │ ├── layertree.go │ ├── log.go │ ├── media.go │ ├── memory.go │ ├── network.go │ ├── overlay.go │ ├── page.go │ ├── performance.go │ ├── performancetimeline.go │ ├── preload.go │ ├── profiler.go │ ├── pwa.go │ ├── runtime.go │ ├── schema.go │ ├── security.go │ ├── serviceworker.go │ ├── storage.go │ ├── systeminfo.go │ ├── target.go │ ├── tethering.go │ ├── tracing.go │ ├── version.go │ ├── webaudio.go │ └── webauthn.go ├── gcdapigen │ ├── README.md │ ├── api_template.txt │ ├── build.sh │ ├── command.go │ ├── domain.go │ ├── downloader.go │ ├── event.go │ ├── gcdapigen.go │ ├── protocol.go │ ├── protocol.json │ ├── return.go │ ├── template_funcs.go │ ├── type.go │ ├── type_properties.go │ └── utils.go ├── gcdmessage │ └── gcdmessage.go ├── go.mod ├── go.sum ├── logger.go ├── observer │ └── message_observer.go ├── testdata │ ├── console_log.html │ ├── cookie.html │ └── extension │ │ ├── .gitignore │ │ ├── CHANGELOG.md │ │ ├── README.md │ │ ├── _locales │ │ ├── en │ │ │ └── messages.json │ │ └── en_GB │ │ │ └── messages.json │ │ ├── background.js │ │ ├── images │ │ ├── icon128.png │ │ ├── icon38-off.png │ │ ├── icon38-on.png │ │ └── icon48.png │ │ └── manifest.json └── wsconn.go └── wsconn.go /.gitattributes: -------------------------------------------------------------------------------- 1 | # Auto detect text files and perform LF normalization 2 | * text=auto 3 | 4 | # Custom for Visual Studio 5 | *.cs diff=csharp 6 | *.sln merge=union 7 | *.csproj merge=union 8 | *.vbproj merge=union 9 | *.fsproj merge=union 10 | *.dbproj merge=union 11 | 12 | # Standard to msysgit 13 | *.doc diff=astextplain 14 | *.DOC diff=astextplain 15 | *.docx diff=astextplain 16 | *.DOCX diff=astextplain 17 | *.dot diff=astextplain 18 | *.DOT diff=astextplain 19 | *.pdf diff=astextplain 20 | *.PDF diff=astextplain 21 | *.rtf diff=astextplain 22 | *.RTF diff=astextplain 23 | -------------------------------------------------------------------------------- /.github/workflows/build_gcd_v2.yml: -------------------------------------------------------------------------------- 1 | on: [push, pull_request] 2 | name: Test 3 | jobs: 4 | test: 5 | runs-on: ubuntu-latest 6 | steps: 7 | - name: Install Go 8 | uses: actions/setup-go@v2 9 | with: 10 | go-version: 1.19.x 11 | - name: Install Packages 12 | run: | 13 | sudo apt-get -qq update 14 | sudo apt-get install -y build-essential curl 15 | echo -n "Determining latest build... " 16 | LATEST=`curl -s http://commondatastorage.googleapis.com/chromium-browser-snapshots/Linux_x64/LAST_CHANGE` 17 | echo "done!" 18 | echo "http://commondatastorage.googleapis.com/chromium-browser-snapshots/Linux_x64/$LATEST/chrome-linux.zip" 19 | echo -n "Downloading build for $LATEST... " 20 | curl -L http://commondatastorage.googleapis.com/chromium-browser-snapshots/Linux_x64/$LATEST/chrome-linux.zip -o chrome-linux.zip 21 | echo "done!" 22 | - name: Checkout code 23 | uses: actions/checkout@v2 24 | - name: Test 25 | run: | 26 | cd v2 && go test -v -race -p 1 ./... -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Windows image file caches 2 | Thumbs.db 3 | ehthumbs.db 4 | 5 | # Folder config file 6 | Desktop.ini 7 | 8 | # Recycle Bin used on file shares 9 | $RECYCLE.BIN/ 10 | 11 | # Windows Installer files 12 | *.cab 13 | *.msi 14 | *.msm 15 | *.msp 16 | 17 | # ========================= 18 | # Operating System Files 19 | # ========================= 20 | 21 | # OSX 22 | # ========================= 23 | 24 | .DS_Store 25 | .AppleDouble 26 | .LSOverride 27 | 28 | # Icon must ends with two \r. 29 | Icon 30 | 31 | 32 | # Thumbnails 33 | ._* 34 | 35 | # Files that might appear on external disk 36 | .Spotlight-V100 37 | .Trashes 38 | 39 | *.exe 40 | debug.log 41 | 42 | output 43 | 44 | gcdapigen/gcdapigen 45 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2021 isaac dawson 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in 13 | all copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 21 | THE SOFTWARE. -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | [](https://goreportcard.com/report/github.com/wirepair/gcd) 2 | 3 | # Google Chrome Debugger (GCD) 4 | 5 | This is primarly an auto-generated client library for communicating with a Google Chrome Browser over their [remote client debugger protocol](https://developer.chrome.com/devtools/docs/debugger-protocol). Note that their documentation is partially incorrect and does not contain a lot of the API calls that are actually available. 6 | 7 | Because I'm lazy and there are hundereds of different custom types and API methods, this library has been automatically generated using their [protocol.json](https://code.google.com/p/chromium/codesearch#chromium/src/third_party/WebKit/Source/devtools/protocol.json&q=protocol.json&sq=package:chromium&type=cs). 8 | 9 | The [gcdapigen](https://github.com/wirepair/gcd/tree/master/v2/gcdapigen) program was created to generate types, event types and commands for gcd. 10 | 11 | # Changelog 12 | 13 | See the [CHANGELOG](https://github.com/wirepair/gcd/tree/master/CHANGELOG.md). 14 | 15 | ## Dependencies 16 | 17 | gcd requires the [gcdapi](https://github.com/wirepair/gcd/tree/master/v2/gcdapi) and [gcdmessage](https://github.com/wirepair/gcd/tree/master/v2/gcdmessage) packages. gcdapi is the auto-generated API. gcdmessage is the glue between gcd and gcdapi so we can keep the packages clean. 18 | 19 | ## The API 20 | 21 | The API consists of of synchronous requests, asynchronous requests / events. Synchronous requests are handled by using non-buffered channels and methods can be called and will return once the value is available. Events are handled by subscribing the response method type and calling the API's "Enable()" such as: 22 | 23 | ```Go 24 | target, err := debugger.NewTab() 25 | if err != nil { 26 | log.Fatalf("error getting new tab: %s\n", err) 27 | } 28 | console := target.Console 29 | 30 | target.Subscribe("Console.messageAdded", func(target *ChromeTarget, v []byte) { 31 | 32 | msg := &gcdapi.ConsoleMessageAddedEvent{} 33 | err := json.Unmarshal(v, msg) 34 | if err != nil { 35 | log.Fatalf("error unmarshalling event data: %v\n", err) 36 | } 37 | log.Printf("METHOD: %s\n", msg.Method) 38 | eventData := msg.Params.Message 39 | log.Printf("Got event: %s\n", eventData) 40 | }) 41 | console.Enable() 42 | // recv events 43 | // console.Disable() 44 | ``` 45 | 46 | ## Usage 47 | 48 | For a full list of api methods, types, event types & godocs: [Documentation](https://godoc.org/github.com/wirepair/gcd/v2/gcdapi) 49 | 50 | ## Examples 51 | 52 | See [examples](https://github.com/wirepair/gcd/tree/master/v2/examples) 53 | 54 | ## Licensing 55 | 56 | The MIT License (MIT) 57 | 58 | Copyright (c) 2020 isaac dawson 59 | 60 | Permission is hereby granted, free of charge, to any person obtaining a copy 61 | of this software and associated documentation files (the "Software"), to deal 62 | in the Software without restriction, including without limitation the rights 63 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 64 | copies of the Software, and to permit persons to whom the Software is 65 | furnished to do so, subject to the following conditions: 66 | 67 | The above copyright notice and this permission notice shall be included in 68 | all copies or substantial portions of the Software. 69 | 70 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 71 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 72 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 73 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 74 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 75 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 76 | THE SOFTWARE. 77 | -------------------------------------------------------------------------------- /examples/events/events.go: -------------------------------------------------------------------------------- 1 | /* 2 | Example of using DebugEvents(true) to listen to various events being emitted by 3 | the Remote Chrome Debugger 4 | */ 5 | 6 | package main 7 | 8 | import ( 9 | "encoding/json" 10 | "flag" 11 | "fmt" 12 | "io/ioutil" 13 | "log" 14 | "net" 15 | "net/http" 16 | "os" 17 | "time" 18 | 19 | "github.com/wirepair/gcd" 20 | "github.com/wirepair/gcd/gcdapi" 21 | ) 22 | 23 | var ( 24 | testListener net.Listener 25 | testPath string 26 | testDir string 27 | testPort string 28 | testServerAddr string 29 | ) 30 | 31 | var testStartupFlags = []string{"--disable-new-tab-first-run", "--no-first-run", "--disable-popup-blocking"} 32 | 33 | func init() { 34 | flag.StringVar(&testPath, "chrome", "C:\\Program Files (x86)\\Google\\Chrome\\Application\\chrome.exe", "path to chrome") 35 | flag.StringVar(&testDir, "dir", "C:\\temp\\", "user directory") 36 | flag.StringVar(&testPort, "port", "9222", "Debugger port") 37 | } 38 | 39 | func main() { 40 | navigatedCh := make(chan struct{}) 41 | debugger := startGcd() 42 | defer debugger.ExitProcess() 43 | 44 | target := startTarget(debugger) 45 | 46 | // subscribe to page loaded event 47 | target.Subscribe("Page.loadEventFired", func(targ *gcd.ChromeTarget, payload []byte) { 48 | navigatedCh <- struct{}{} 49 | }) 50 | 51 | // navigate 52 | navigateParams := &gcdapi.PageNavigateParams{Url: testServerAddr + "top.html"} 53 | _, _, _, err := target.Page.NavigateWithParams(navigateParams) 54 | if err != nil { 55 | log.Fatalf("error: %s\n", err) 56 | } 57 | 58 | // wait for navigation to finish 59 | <-navigatedCh 60 | // get the document node 61 | doc, err := target.DOM.GetDocument(-1, true) 62 | if err != nil { 63 | log.Fatal(err) 64 | } 65 | 66 | // request child nodes, this will come in as DOM.setChildNode events 67 | for i := 0; i < 3; i++ { 68 | log.Printf("requesting child nodes...") 69 | _, err = target.DOM.RequestChildNodes(doc.NodeId, -1, true) 70 | if err != nil { 71 | log.Fatal(err) 72 | } 73 | time.Sleep(1 * time.Second) 74 | } 75 | 76 | target.Subscribe("DOM.setChildNodes", func(targ *gcd.ChromeTarget, payload []byte) { 77 | setNodes := &gcdapi.DOMSetChildNodesEvent{} 78 | err := json.Unmarshal(payload, setNodes) 79 | if err != nil { 80 | log.Fatalf("error decoding setChildNodes") 81 | } 82 | for _, x := range setNodes.Params.Nodes { 83 | if x.ContentDocument != nil { 84 | checkContentDocument(targ, x) 85 | } 86 | for _, v := range x.Children { 87 | if v.ContentDocument != nil { 88 | checkContentDocument(targ, v) 89 | } 90 | } 91 | } 92 | 93 | }) 94 | 95 | // wait for redirect 96 | //time.Sleep(5 * time.Second) 97 | 98 | // get iframe node id 99 | iframe, err := target.DOM.QuerySelector(doc.NodeId, "#iframe") 100 | if err != nil { 101 | log.Fatalf("error looking for frame") 102 | } 103 | 104 | log.Printf("iframe %d\n", iframe) 105 | time.Sleep(10 * time.Second) 106 | debugger.ExitProcess() 107 | os.RemoveAll(testDir) // remove new profile junk 108 | } 109 | 110 | func checkContentDocument(targ *gcd.ChromeTarget, v *gcdapi.DOMNode) { 111 | if v.ContentDocument != nil { 112 | iframeDocId := v.ContentDocument.NodeId 113 | targ.DOM.RequestChildNodes(iframeDocId, -1, true) 114 | //nodes, _ := targ.DOM.QuerySelectorAll(iframeDocId, "div") 115 | log.Printf("!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!got iframe nodes.\n") 116 | } else { 117 | log.Printf("got non iframe\n") 118 | } 119 | } 120 | 121 | func startGcd() *gcd.Gcd { 122 | testDir = testRandomDir() 123 | testPort = testRandomPort() 124 | testServer() // start test web server 125 | debugger := gcd.NewChromeDebugger() 126 | debugger.AddFlags(testStartupFlags) 127 | debugger.StartProcess(testPath, testDir, testPort) 128 | return debugger 129 | } 130 | 131 | func startTarget(debugger *gcd.Gcd) *gcd.ChromeTarget { 132 | target, err := debugger.NewTab() 133 | if err != nil { 134 | log.Fatalf("error getting new tab: %s\n", err) 135 | } 136 | target.DebugEvents(true) 137 | target.DOM.Enable() 138 | target.Console.Enable() 139 | target.Page.Enable() 140 | //target.Debugger.Enable() 141 | return target 142 | 143 | } 144 | 145 | func testServer() { 146 | testListener, _ = net.Listen("tcp", ":0") 147 | _, testServerPort, _ := net.SplitHostPort(testListener.Addr().String()) 148 | testServerAddr = fmt.Sprintf("http://localhost:%s/", testServerPort) 149 | go http.Serve(testListener, http.FileServer(http.Dir("webdata/"))) 150 | } 151 | 152 | func testRandomPort() string { 153 | l, err := net.Listen("tcp", ":0") 154 | if err != nil { 155 | log.Fatal(err) 156 | } 157 | _, randPort, _ := net.SplitHostPort(l.Addr().String()) 158 | l.Close() 159 | return randPort 160 | } 161 | 162 | func testRandomDir() string { 163 | dir, err := ioutil.TempDir(testDir, "autogcd") 164 | if err != nil { 165 | log.Fatalf("error getting temp dir: %s\n", err) 166 | } 167 | return dir 168 | } 169 | -------------------------------------------------------------------------------- /examples/events/webdata/iframe.html: -------------------------------------------------------------------------------- 1 | 2 |
3 |