diff --git a/internal/seleniumtest/seleniumtest.go b/internal/seleniumtest/seleniumtest.go index 41c6843..dc7ad84 100644 --- a/internal/seleniumtest/seleniumtest.go +++ b/internal/seleniumtest/seleniumtest.go @@ -23,7 +23,6 @@ import ( socks5 "github.com/armon/go-socks5" "github.com/blang/semver" - "github.com/chromedp/cdproto/browser" "github.com/go-auxiliaries/selenium" "github.com/go-auxiliaries/selenium/chrome" "github.com/go-auxiliaries/selenium/firefox" @@ -1804,35 +1803,8 @@ func testExecuteChromeDPCommand(t *testing.T, c Config) { t.Log(product) } -func testGenerateCDProtoContext(t *testing.T, c Config) { - caps := newTestCapabilities(t, c) - - wd, err := NewRemote(t, caps, c.Addr) - if err != nil { - t.Fatalf("newRemote(_, _) returned error: %v", err) - } - defer func() { - _ = wd.Quit() - }() - - version := browser.GetVersion() - - _, product, _, _, _, err := version.Do(wd.GenerateCDProtoContext(context.Background())) - - if err != nil { - t.Fatalf("cdproto execute error : %s", err.Error()) - } - - if strings.Index(product, "Chrome") > 0 { - t.Log(product) - } else { - t.Fatalf("invalid chrome version %s", product) - } -} - func RunChromeTests(t *testing.T, c Config) { // Chrome-specific tests. t.Run("Extension", runTest(testChromeExtension, c)) t.Run("ExecuteChromeDPCommand", runTest(testExecuteChromeDPCommand, c)) - t.Run("GenerateCDProtoContext", runTest(testGenerateCDProtoContext, c)) } diff --git a/remote.go b/remote.go index 26929ae..21ac387 100644 --- a/remote.go +++ b/remote.go @@ -5,7 +5,6 @@ package selenium import ( "bytes" - "context" "encoding/base64" "encoding/json" "errors" @@ -19,9 +18,6 @@ import ( "strings" "time" - "github.com/chromedp/cdproto/cdp" - "github.com/mailru/easyjson" - "github.com/blang/semver" "github.com/go-auxiliaries/selenium/firefox" "github.com/go-auxiliaries/selenium/log" @@ -1297,70 +1293,6 @@ func (wd *remoteWD) execChromeDPCommand(cmd string, params map[string]interface{ return reply.Value, nil } -// CDProtoExecutor execute Chrome DevTools Protocol command through cdproto -type CDProtoExecutor struct { - *remoteWD -} - -var _ cdp.Executor = (*CDProtoExecutor)(nil) - -// Execute executes a Chrome DevTools Protocol command. -// So that CDProtoExecutor can be executor for cdproto, -// refer to https://github.com/chromedp/cdproto/blob/master/cdp/types.go -func (e CDProtoExecutor) Execute(ctx context.Context, cmd string, params easyjson.Marshaler, res easyjson.Unmarshaler) (err error) { - if e.browser != "chrome" { - return fmt.Errorf("executing a Chrome DevTools command through cdproto is only supported in Chrome, not %s", e.browser) - } - - select { - case <-ctx.Done(): - return ctx.Err() - default: - } - - body := map[string]interface{}{"cmd": cmd} - - if params == nil { - // params can't be nil - body["params"] = make(map[string]string) - } else { - body["params"] = params - } - - data, err := json.Marshal(body) - if err != nil { - return - } - - response, err := e.execChromeDPCommandRaw(data) - if err != nil { - return - } - - reply := new(struct{ Value easyjson.Unmarshaler }) - reply.Value = res - - if err = json.Unmarshal(response, reply); err != nil { - debugLog("cdproto value parse error :%+v", res) - return - } - - debugLog("cdproto value return :%+v", res) - - return -} - -func (wd *remoteWD) generateCDProtoExecutor() cdp.Executor { - return CDProtoExecutor{wd} -} - -func (wd *remoteWD) GenerateCDProtoContext(ctx context.Context) context.Context { - if ctx == nil { - ctx = context.Background() - } - return cdp.WithExecutor(ctx, wd.generateCDProtoExecutor()) -} - func (wd *remoteWD) ExecuteChromeDPCommand(cmd string, params map[string]interface{}) (interface{}, error) { if wd.browser != "chrome" { return nil, fmt.Errorf("executing a Chrome DevTools command is only supported in Chrome, not %s", wd.browser) diff --git a/selenium.go b/selenium.go index 47d421e..5bc9d46 100644 --- a/selenium.go +++ b/selenium.go @@ -1,7 +1,6 @@ package selenium import ( - "context" "time" "github.com/go-auxiliaries/selenium/chrome" @@ -446,10 +445,6 @@ type WebDriver interface { // ExecuteChromeDPCommand executes a Chrome DevTools Protocol command. // See https://chromedevtools.github.io/devtools-protocol/ for available commands. ExecuteChromeDPCommand(cmd string, params map[string]interface{}) (interface{}, error) - // GenerateCDProtoContext generates context with an executor - // which can execute a Chrome DevTools Protocol command through cdproto. - // See https://github.com/chromedp/cdproto for usage information. - GenerateCDProtoContext(ctx context.Context) context.Context // ExecuteScript executes a script. ExecuteScript(script string, args []interface{}) (interface{}, error) // ExecuteScriptAsync asynchronously executes a script.