Skip to content

Commit

Permalink
Update api to latest tot
Browse files Browse the repository at this point in the history
  • Loading branch information
= committed Oct 16, 2024
1 parent 932677b commit 8ac64a5
Show file tree
Hide file tree
Showing 21 changed files with 65 additions and 170 deletions.
16 changes: 9 additions & 7 deletions v2/chrome_target.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,12 @@ package gcd

import (
"context"
"github.com/goccy/go-json"
"sync"
"sync/atomic"
"time"

"github.com/goccy/go-json"

"github.com/wirepair/gcd/v2/observer"

"github.com/wirepair/gcd/v2/gcdapi"
Expand Down Expand Up @@ -80,10 +81,11 @@ type ChromeTarget struct {
Browser *gcdapi.Browser
CacheStorage *gcdapi.CacheStorage
Cast *gcdapi.Cast
Console *gcdapi.Console // console API
CSS *gcdapi.CSS // CSS API
Database *gcdapi.Database // Database API
Debugger *gcdapi.Debugger // JS Debugger API
Console *gcdapi.Console // console API
CSS *gcdapi.CSS // CSS API
Database *gcdapi.Database // Database API
Debugger *gcdapi.Debugger // JS Debugger API
DeviceAccess *gcdapi.DeviceAccess
DeviceOrientation *gcdapi.DeviceOrientation // Device Orientation API
DOM *gcdapi.DOM // DOM API
DOMDebugger *gcdapi.DOMDebugger // DOM Debugger API
Expand Down Expand Up @@ -174,6 +176,7 @@ func (c *ChromeTarget) Init() {
c.CSS = gcdapi.NewCSS(c)
c.Database = gcdapi.NewDatabase(c)
c.Debugger = gcdapi.NewDebugger(c)
c.DeviceAccess = gcdapi.NewDeviceAccess(c)
c.DeviceOrientation = gcdapi.NewDeviceOrientation(c)
c.DOM = gcdapi.NewDOM(c)
c.DOMDebugger = gcdapi.NewDOMDebugger(c)
Expand Down Expand Up @@ -215,7 +218,7 @@ func (c *ChromeTarget) Init() {

// clean up this target
func (c *ChromeTarget) shutdown() {
if c.stopped == true {
if c.stopped {
return
}
c.stopped = true
Expand Down Expand Up @@ -389,7 +392,6 @@ func (c *ChromeTarget) dispatchWithTimeout(r chan<- *gcdmessage.Message, id int6
close(r)
return
}
return
}

// check target detached/crashed
Expand Down
2 changes: 1 addition & 1 deletion v2/examples/screenshot/screenshot.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ func main() {
wg.Add(1)
targets[i], err = debugger.NewTab()
if err != nil {
log.Fatalf("error getting targets")
log.Fatalf("error getting targets: %s", err)
}
page := targets[i].Page
page.Enable(ctx)
Expand Down
14 changes: 7 additions & 7 deletions v2/gcd.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,15 +28,15 @@ import (
"context"
"errors"
"fmt"
"github.com/goccy/go-json"
"io"
"io/ioutil"
"net/http"
"os"
"os/exec"
"sync"
"time"

"github.com/goccy/go-json"

"github.com/wirepair/gcd/v2/observer"

"github.com/wirepair/gcd/v2/gcdapi"
Expand Down Expand Up @@ -382,7 +382,7 @@ func (c *Gcd) getConnectableTargets() ([]*TargetInfo, error) {
}
defer resp.Body.Close()

body, errRead := ioutil.ReadAll(resp.Body)
body, errRead := io.ReadAll(resp.Body)
if errRead != nil {
return nil, &GcdBodyReadErr{Message: errRead.Error()}
}
Expand Down Expand Up @@ -421,7 +421,7 @@ func (c *Gcd) NewTab() (*ChromeTarget, error) {
}
defer resp.Body.Close()

body, errRead := ioutil.ReadAll(resp.Body)
body, errRead := io.ReadAll(resp.Body)
if errRead != nil {
return nil, &GcdBodyReadErr{Message: errRead.Error()}
}
Expand Down Expand Up @@ -451,7 +451,7 @@ func (c *Gcd) CloseTab(target *ChromeTarget) error {
return err
}
defer resp.Body.Close()
_, errRead := ioutil.ReadAll(resp.Body)
_, errRead := io.ReadAll(resp.Body)
return errRead
}

Expand All @@ -467,7 +467,7 @@ func (c *Gcd) ActivateTab(target *ChromeTarget) error {
return err
}
defer resp.Body.Close()
_, errRead := ioutil.ReadAll(resp.Body)
_, errRead := io.ReadAll(resp.Body)
return errRead
}

Expand All @@ -492,7 +492,7 @@ func (c *Gcd) probeDebugPort(endpoint string) {
c.readyChErr <- nil
return
case <-timeoutTicker.C:
c.readyChErr <- fmt.Errorf("Unable to contact debugger at %s after %v, gave up", c.apiEndpoint, c.timeout)
c.readyChErr <- fmt.Errorf("unable to contact debugger at %s after %v, gave up", c.apiEndpoint, c.timeout)
return
}
}
Expand Down
16 changes: 6 additions & 10 deletions v2/gcd_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import (
"context"
"flag"
"fmt"
"github.com/goccy/go-json"
"io/ioutil"
"net"
"net/http"
Expand All @@ -15,6 +14,8 @@ import (
"testing"
"time"

"github.com/goccy/go-json"

"github.com/wirepair/gcd/v2/gcdapi"
)

Expand Down Expand Up @@ -579,14 +580,11 @@ func TestNetworkIntercept(t *testing.T) {
testDefaultStartup(t, WithEventDebugging(), WithInternalDebugMessages(), WithLogger(&DebugLogger{}))
defer debugger.ExitProcess()

doneCh := make(chan error)

target, err := debugger.NewTab()
if err != nil {
t.Fatalf("error getting new tab: %s\n", err)
}

go testTimeoutListener(doneCh, 5, "timed out waiting for requestIntercepted")
ctx := context.Background()
if _, err := target.Fetch.Enable(ctx, []*gcdapi.FetchRequestPattern{
{
Expand All @@ -596,9 +594,8 @@ func TestNetworkIntercept(t *testing.T) {
}, false); err != nil {
t.Fatalf("error enabling fetch: %s", err)
}

continued := false
target.Subscribe("Fetch.requestPaused", func(target *ChromeTarget, payload []byte) {
close(doneCh)

pausedEvent := &gcdapi.FetchRequestPausedEvent{}
if err := json.Unmarshal(payload, pausedEvent); err != nil {
Expand All @@ -625,17 +622,16 @@ func TestNetworkIntercept(t *testing.T) {
Headers: fetchHeaders,
}
target.Fetch.ContinueRequestWithParams(ctx, p)
continued = true
})

params := &gcdapi.PageNavigateParams{Url: "http://www.example.com"}
_, _, _, err = target.Page.NavigateWithParams(testCtx, params)
if err != nil {
t.Fatalf("error navigating: %s\n", err)
}

err = <-doneCh
if err != nil {
t.Fatal(err)
if continued == false {
t.Fatal("failed to intercept and continue request")
}
}

Expand Down
1 change: 1 addition & 0 deletions v2/gcdapi/audits.go
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,7 @@ type AuditsInspectorIssue struct {
IssueId string `json:"issueId,omitempty"` // A unique id for this issue. May be omitted if no other entity (e.g. exception, CDP message, etc.) is referencing this issue.
}

//
type AuditsIssueAddedEvent struct {
Method string `json:"method"`
Params struct {
Expand Down
1 change: 1 addition & 0 deletions v2/gcdapi/database.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ type DatabaseError struct {
Code int `json:"code"` // Error code.
}

//
type DatabaseAddDatabaseEvent struct {
Method string `json:"method"`
Params struct {
Expand Down
4 changes: 4 additions & 0 deletions v2/gcdapi/domstorage.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ type DOMStorageStorageId struct {
IsLocalStorage bool `json:"isLocalStorage"` // Whether the storage is local storage (not session storage).
}

//
type DOMStorageDomStorageItemAddedEvent struct {
Method string `json:"method"`
Params struct {
Expand All @@ -25,6 +26,7 @@ type DOMStorageDomStorageItemAddedEvent struct {
} `json:"Params,omitempty"`
}

//
type DOMStorageDomStorageItemRemovedEvent struct {
Method string `json:"method"`
Params struct {
Expand All @@ -33,6 +35,7 @@ type DOMStorageDomStorageItemRemovedEvent struct {
} `json:"Params,omitempty"`
}

//
type DOMStorageDomStorageItemUpdatedEvent struct {
Method string `json:"method"`
Params struct {
Expand All @@ -43,6 +46,7 @@ type DOMStorageDomStorageItemUpdatedEvent struct {
} `json:"Params,omitempty"`
}

//
type DOMStorageDomStorageItemsClearedEvent struct {
Method string `json:"method"`
Params struct {
Expand Down
2 changes: 2 additions & 0 deletions v2/gcdapi/fedcm.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ type FedCmAccount struct {
PrivacyPolicyUrl string `json:"privacyPolicyUrl,omitempty"` //
}

//
type FedCmDialogShownEvent struct {
Method string `json:"method"`
Params struct {
Expand Down Expand Up @@ -60,6 +61,7 @@ func (c *FedCm) Enable(ctx context.Context, disableRejectionDelay bool) (*gcdmes
return c.EnableWithParams(ctx, &v)
}

//
func (c *FedCm) Disable(ctx context.Context) (*gcdmessage.ChromeResponse, error) {
return c.target.SendDefaultRequest(ctx, &gcdmessage.ParamRequest{Id: c.target.GetId(), Method: "FedCm.disable"})
}
Expand Down
53 changes: 0 additions & 53 deletions v2/gcdapi/gcdapi_test.go

This file was deleted.

5 changes: 5 additions & 0 deletions v2/gcdapi/heapprofiler.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ type HeapProfilerSamplingHeapProfile struct {
Samples []*HeapProfilerSamplingHeapProfileSample `json:"samples"` //
}

//
type HeapProfilerAddHeapSnapshotChunkEvent struct {
Method string `json:"method"`
Params struct {
Expand All @@ -54,6 +55,7 @@ type HeapProfilerLastSeenObjectIdEvent struct {
} `json:"Params,omitempty"`
}

//
type HeapProfilerReportHeapSnapshotProgressEvent struct {
Method string `json:"method"`
Params struct {
Expand Down Expand Up @@ -90,14 +92,17 @@ func (c *HeapProfiler) AddInspectedHeapObject(ctx context.Context, heapObjectId
return c.AddInspectedHeapObjectWithParams(ctx, &v)
}

//
func (c *HeapProfiler) CollectGarbage(ctx context.Context) (*gcdmessage.ChromeResponse, error) {
return c.target.SendDefaultRequest(ctx, &gcdmessage.ParamRequest{Id: c.target.GetId(), Method: "HeapProfiler.collectGarbage"})
}

//
func (c *HeapProfiler) Disable(ctx context.Context) (*gcdmessage.ChromeResponse, error) {
return c.target.SendDefaultRequest(ctx, &gcdmessage.ParamRequest{Id: c.target.GetId(), Method: "HeapProfiler.disable"})
}

//
func (c *HeapProfiler) Enable(ctx context.Context) (*gcdmessage.ChromeResponse, error) {
return c.target.SendDefaultRequest(ctx, &gcdmessage.ParamRequest{Id: c.target.GetId(), Method: "HeapProfiler.enable"})
}
Expand Down
2 changes: 2 additions & 0 deletions v2/gcdapi/layertree.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ type LayerTreeLayer struct {
StickyPositionConstraint *LayerTreeStickyPositionConstraint `json:"stickyPositionConstraint,omitempty"` // Sticky position constraint information
}

//
type LayerTreeLayerPaintedEvent struct {
Method string `json:"method"`
Params struct {
Expand All @@ -58,6 +59,7 @@ type LayerTreeLayerPaintedEvent struct {
} `json:"Params,omitempty"`
}

//
type LayerTreeLayerTreeDidChangeEvent struct {
Method string `json:"method"`
Params struct {
Expand Down
1 change: 1 addition & 0 deletions v2/gcdapi/memory.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ func (c *Memory) GetDOMCounters(ctx context.Context) (int, int, int, error) {
return chromeData.Result.Documents, chromeData.Result.Nodes, chromeData.Result.JsEventListeners, nil
}

//
func (c *Memory) PrepareForLeakDetection(ctx context.Context) (*gcdmessage.ChromeResponse, error) {
return c.target.SendDefaultRequest(ctx, &gcdmessage.ParamRequest{Id: c.target.GetId(), Method: "Memory.prepareForLeakDetection"})
}
Expand Down
2 changes: 2 additions & 0 deletions v2/gcdapi/network.go
Original file line number Diff line number Diff line change
Expand Up @@ -658,13 +658,15 @@ type NetworkReportingApiReportAddedEvent struct {
} `json:"Params,omitempty"`
}

//
type NetworkReportingApiReportUpdatedEvent struct {
Method string `json:"method"`
Params struct {
Report *NetworkReportingApiReport `json:"report"` //
} `json:"Params,omitempty"`
}

//
type NetworkReportingApiEndpointsChangedForOriginEvent struct {
Method string `json:"method"`
Params struct {
Expand Down
2 changes: 2 additions & 0 deletions v2/gcdapi/page.go
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,7 @@ type PageBackForwardCacheNotRestoredExplanationTree struct {
Children []*PageBackForwardCacheNotRestoredExplanationTree `json:"children"` // Array of children frame
}

//
type PageDomContentEventFiredEvent struct {
Method string `json:"method"`
Params struct {
Expand Down Expand Up @@ -381,6 +382,7 @@ type PageBackForwardCacheNotUsedEvent struct {
} `json:"Params,omitempty"`
}

//
type PageLoadEventFiredEvent struct {
Method string `json:"method"`
Params struct {
Expand Down
Loading

0 comments on commit 8ac64a5

Please sign in to comment.