fix: failed to exec web script

This commit is contained in:
徐聪
2025-06-24 23:02:35 +08:00
parent d926d908e0
commit ea6b0a6902
5 changed files with 60 additions and 4 deletions

View File

@@ -37,6 +37,7 @@ type CreateBrowserResponse struct {
type BrowserDriver struct {
urlPrefix *url.URL
Session *DriverSession
Device *BrowserDevice
}
type BrowserInfo struct {
@@ -96,6 +97,7 @@ func CreateBrowser(timeout int, width, height int) (browserInfo *BrowserInfo, er
func NewBrowserDriver(device *BrowserDevice) (driver *BrowserDriver, err error) {
log.Info().Msg("init NewBrowserDriver driver")
driver = new(BrowserDriver)
driver.Device = device
driver.urlPrefix = &url.URL{}
driver.urlPrefix.Host = BROWSER_LOCAL_ADDRESS
driver.urlPrefix.Scheme = "http"
@@ -597,7 +599,7 @@ func (wd *BrowserDriver) Clear(packageName string) error {
}
func (wd *BrowserDriver) GetDevice() IDevice {
return nil
return wd.Device
}
func (wd *BrowserDriver) ForegroundInfo() (app types.AppInfo, err error) {

View File

@@ -117,6 +117,7 @@ func (s *MCPServer4XTDriver) registerTools() {
s.registerTool(&ToolClosePopups{})
// PC/Web Tools
s.registerTool(&ToolWebLoginNoneUI{})
s.registerTool(&ToolSecondaryClick{})
s.registerTool(&ToolHoverBySelector{})
s.registerTool(&ToolTapBySelector{})

View File

@@ -63,7 +63,15 @@ func (t *ToolWebLoginNoneUI) Implement() server.ToolHandlerFunc {
}
func (t *ToolWebLoginNoneUI) ConvertActionToCallToolRequest(action option.MobileAction) (mcp.CallToolRequest, error) {
return BuildMCPCallToolRequest(t.Name(), map[string]any{}), nil
arguments := map[string]any{}
if textsSlice, ok := action.Params.([]interface{}); ok {
arguments["packageName"] = textsSlice[0].(string)
arguments["phoneNumber"] = textsSlice[1].(string)
arguments["captcha"] = textsSlice[2].(string)
arguments["password"] = textsSlice[3].(string)
}
return BuildMCPCallToolRequest(t.Name(), arguments), nil
}
// ToolSecondaryClick implements the secondary_click tool call.
@@ -216,7 +224,7 @@ func (t *ToolTapBySelector) Implement() server.ToolHandlerFunc {
}
// Tap by selector action logic
err = driverExt.TapBySelector(unifiedReq.Selector)
err = driverExt.TapBySelector(unifiedReq.Selector, option.WithIndex(unifiedReq.Index))
if err != nil {
return NewMCPErrorResponse(fmt.Sprintf("Tap by selector failed: %s", err.Error())), nil
}
@@ -233,6 +241,8 @@ func (t *ToolTapBySelector) ConvertActionToCallToolRequest(action option.MobileA
arguments := map[string]any{
"selector": selector,
}
// Extract options to arguments
extractActionOptionsToArguments(action.GetOptions(), arguments)
return BuildMCPCallToolRequest(t.Name(), arguments), nil
}
return mcp.CallToolRequest{}, fmt.Errorf("invalid tap by selector params: %v", action.Params)