console
This commit is contained in:
@@ -726,3 +726,81 @@ func (c *Client) DownloadFileFromContainer(containerPath, localPath string) erro
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// GetConsoleLogs retrieves console logs from a tab
|
||||
// If tabID is empty, the current tab will be used
|
||||
// If clear is true, the logs will be cleared after retrieval
|
||||
func (c *Client) GetConsoleLogs(tabID string, clear bool) ([]map[string]interface{}, error) {
|
||||
params := map[string]string{}
|
||||
|
||||
// Only include tab ID if it's provided
|
||||
if tabID != "" {
|
||||
params["tab"] = tabID
|
||||
}
|
||||
|
||||
// Add clear flag if specified
|
||||
if clear {
|
||||
params["clear"] = "true"
|
||||
}
|
||||
|
||||
resp, err := c.SendCommand("console-logs", params)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
if !resp.Success {
|
||||
return nil, fmt.Errorf("failed to get console logs: %s", resp.Error)
|
||||
}
|
||||
|
||||
// Convert response data to slice of console logs
|
||||
logs, ok := resp.Data.([]interface{})
|
||||
if !ok {
|
||||
return nil, fmt.Errorf("unexpected response data type")
|
||||
}
|
||||
|
||||
result := make([]map[string]interface{}, len(logs))
|
||||
for i, log := range logs {
|
||||
logMap, ok := log.(map[string]interface{})
|
||||
if !ok {
|
||||
return nil, fmt.Errorf("unexpected log entry format")
|
||||
}
|
||||
result[i] = logMap
|
||||
}
|
||||
|
||||
return result, nil
|
||||
}
|
||||
|
||||
// ExecuteConsoleCommand executes a command in the browser console
|
||||
// If tabID is empty, the current tab will be used
|
||||
// timeout is in seconds, 0 means no timeout
|
||||
func (c *Client) ExecuteConsoleCommand(tabID, command string, timeout int) (string, error) {
|
||||
params := map[string]string{
|
||||
"command": command,
|
||||
}
|
||||
|
||||
// Only include tab ID if it's provided
|
||||
if tabID != "" {
|
||||
params["tab"] = tabID
|
||||
}
|
||||
|
||||
// Add timeout if specified
|
||||
if timeout > 0 {
|
||||
params["timeout"] = strconv.Itoa(timeout)
|
||||
}
|
||||
|
||||
resp, err := c.SendCommand("console-command", params)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
|
||||
if !resp.Success {
|
||||
return "", fmt.Errorf("failed to execute console command: %s", resp.Error)
|
||||
}
|
||||
|
||||
result, ok := resp.Data.(string)
|
||||
if !ok {
|
||||
return "", fmt.Errorf("unexpected response data type")
|
||||
}
|
||||
|
||||
return result, nil
|
||||
}
|
||||
|
Reference in New Issue
Block a user