Add commands for dealing with cache and site data, cookies, etc

This commit is contained in:
Josh at WLTechBlog
2025-09-30 08:00:30 -05:00
parent 74d99db629
commit 72d4a5653d
10 changed files with 1553 additions and 1 deletions

View File

@@ -2453,3 +2453,171 @@ func (c *Client) ManageFiles(operation, pattern, maxAge string) (*FileManagement
return &result, nil
}
// DisableCache disables browser cache for a tab
// If tabID is empty, the current tab will be used
// timeout is in seconds, 0 means no timeout
func (c *Client) DisableCache(tabID string, timeout int) error {
params := map[string]string{}
// 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("disable-cache", params)
if err != nil {
return err
}
if !resp.Success {
return fmt.Errorf("failed to disable cache: %s", resp.Error)
}
return nil
}
// EnableCache enables browser cache for a tab
// If tabID is empty, the current tab will be used
// timeout is in seconds, 0 means no timeout
func (c *Client) EnableCache(tabID string, timeout int) error {
params := map[string]string{}
// 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("enable-cache", params)
if err != nil {
return err
}
if !resp.Success {
return fmt.Errorf("failed to enable cache: %s", resp.Error)
}
return nil
}
// ClearCache clears browser cache for a tab
// If tabID is empty, the current tab will be used
// timeout is in seconds, 0 means no timeout
func (c *Client) ClearCache(tabID string, timeout int) error {
params := map[string]string{}
// 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("clear-cache", params)
if err != nil {
return err
}
if !resp.Success {
return fmt.Errorf("failed to clear cache: %s", resp.Error)
}
return nil
}
// ClearAllSiteData clears all site data including cookies, storage, cache, etc. for a tab
// If tabID is empty, the current tab will be used
// timeout is in seconds, 0 means no timeout
func (c *Client) ClearAllSiteData(tabID string, timeout int) error {
params := map[string]string{}
// 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("clear-all-site-data", params)
if err != nil {
return err
}
if !resp.Success {
return fmt.Errorf("failed to clear all site data: %s", resp.Error)
}
return nil
}
// ClearCookies clears cookies for a tab
// If tabID is empty, the current tab will be used
// timeout is in seconds, 0 means no timeout
func (c *Client) ClearCookies(tabID string, timeout int) error {
params := map[string]string{}
// 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("clear-cookies", params)
if err != nil {
return err
}
if !resp.Success {
return fmt.Errorf("failed to clear cookies: %s", resp.Error)
}
return nil
}
// ClearStorage clears web storage (localStorage, sessionStorage, IndexedDB, etc.) for a tab
// If tabID is empty, the current tab will be used
// timeout is in seconds, 0 means no timeout
func (c *Client) ClearStorage(tabID string, timeout int) error {
params := map[string]string{}
// 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("clear-storage", params)
if err != nil {
return err
}
if !resp.Success {
return fmt.Errorf("failed to clear storage: %s", resp.Error)
}
return nil
}