extensions.go 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240
  1. // Package extensions provides the Chrome DevTools Protocol
  2. // commands, types, and events for the Extensions domain.
  3. //
  4. // Defines commands and events for browser extensions.
  5. //
  6. // Generated by the cdproto-gen command.
  7. package extensions
  8. // Code generated by cdproto-gen. DO NOT EDIT.
  9. import (
  10. "context"
  11. "github.com/chromedp/cdproto/cdp"
  12. "github.com/go-json-experiment/json/jsontext"
  13. )
  14. // LoadUnpackedParams installs an unpacked extension from the filesystem
  15. // similar to --load-extension CLI flags. Returns extension ID once the
  16. // extension has been installed. Available if the client is connected using the
  17. // --remote-debugging-pipe flag and the --enable-unsafe-extension-debugging flag
  18. // is set.
  19. type LoadUnpackedParams struct {
  20. Path string `json:"path"` // Absolute file path.
  21. }
  22. // LoadUnpacked installs an unpacked extension from the filesystem similar to
  23. // --load-extension CLI flags. Returns extension ID once the extension has been
  24. // installed. Available if the client is connected using the
  25. // --remote-debugging-pipe flag and the --enable-unsafe-extension-debugging flag
  26. // is set.
  27. //
  28. // See: https://chromedevtools.github.io/devtools-protocol/tot/Extensions#method-loadUnpacked
  29. //
  30. // parameters:
  31. //
  32. // path - Absolute file path.
  33. func LoadUnpacked(path string) *LoadUnpackedParams {
  34. return &LoadUnpackedParams{
  35. Path: path,
  36. }
  37. }
  38. // LoadUnpackedReturns return values.
  39. type LoadUnpackedReturns struct {
  40. ID string `json:"id,omitempty,omitzero"` // Extension id.
  41. }
  42. // Do executes Extensions.loadUnpacked against the provided context.
  43. //
  44. // returns:
  45. //
  46. // id - Extension id.
  47. func (p *LoadUnpackedParams) Do(ctx context.Context) (id string, err error) {
  48. // execute
  49. var res LoadUnpackedReturns
  50. err = cdp.Execute(ctx, CommandLoadUnpacked, p, &res)
  51. if err != nil {
  52. return "", err
  53. }
  54. return res.ID, nil
  55. }
  56. // UninstallParams uninstalls an unpacked extension (others not supported)
  57. // from the profile. Available if the client is connected using the
  58. // --remote-debugging-pipe flag and the --enable-unsafe-extension-debugging.
  59. type UninstallParams struct {
  60. ID string `json:"id"` // Extension id.
  61. }
  62. // Uninstall uninstalls an unpacked extension (others not supported) from the
  63. // profile. Available if the client is connected using the
  64. // --remote-debugging-pipe flag and the --enable-unsafe-extension-debugging.
  65. //
  66. // See: https://chromedevtools.github.io/devtools-protocol/tot/Extensions#method-uninstall
  67. //
  68. // parameters:
  69. //
  70. // id - Extension id.
  71. func Uninstall(id string) *UninstallParams {
  72. return &UninstallParams{
  73. ID: id,
  74. }
  75. }
  76. // Do executes Extensions.uninstall against the provided context.
  77. func (p *UninstallParams) Do(ctx context.Context) (err error) {
  78. return cdp.Execute(ctx, CommandUninstall, p, nil)
  79. }
  80. // GetStorageItemsParams gets data from extension storage in the given
  81. // storageArea. If keys is specified, these are used to filter the result.
  82. type GetStorageItemsParams struct {
  83. ID string `json:"id"` // ID of extension.
  84. StorageArea StorageArea `json:"storageArea"` // StorageArea to retrieve data from.
  85. Keys []string `json:"keys,omitempty,omitzero"` // Keys to retrieve.
  86. }
  87. // GetStorageItems gets data from extension storage in the given storageArea.
  88. // If keys is specified, these are used to filter the result.
  89. //
  90. // See: https://chromedevtools.github.io/devtools-protocol/tot/Extensions#method-getStorageItems
  91. //
  92. // parameters:
  93. //
  94. // id - ID of extension.
  95. // storageArea - StorageArea to retrieve data from.
  96. func GetStorageItems(id string, storageArea StorageArea) *GetStorageItemsParams {
  97. return &GetStorageItemsParams{
  98. ID: id,
  99. StorageArea: storageArea,
  100. }
  101. }
  102. // WithKeys keys to retrieve.
  103. func (p GetStorageItemsParams) WithKeys(keys []string) *GetStorageItemsParams {
  104. p.Keys = keys
  105. return &p
  106. }
  107. // GetStorageItemsReturns return values.
  108. type GetStorageItemsReturns struct {
  109. Data jsontext.Value `json:"data,omitempty,omitzero"`
  110. }
  111. // Do executes Extensions.getStorageItems against the provided context.
  112. //
  113. // returns:
  114. //
  115. // data
  116. func (p *GetStorageItemsParams) Do(ctx context.Context) (data jsontext.Value, err error) {
  117. // execute
  118. var res GetStorageItemsReturns
  119. err = cdp.Execute(ctx, CommandGetStorageItems, p, &res)
  120. if err != nil {
  121. return nil, err
  122. }
  123. return res.Data, nil
  124. }
  125. // RemoveStorageItemsParams removes keys from extension storage in the given
  126. // storageArea.
  127. type RemoveStorageItemsParams struct {
  128. ID string `json:"id"` // ID of extension.
  129. StorageArea StorageArea `json:"storageArea"` // StorageArea to remove data from.
  130. Keys []string `json:"keys"` // Keys to remove.
  131. }
  132. // RemoveStorageItems removes keys from extension storage in the given
  133. // storageArea.
  134. //
  135. // See: https://chromedevtools.github.io/devtools-protocol/tot/Extensions#method-removeStorageItems
  136. //
  137. // parameters:
  138. //
  139. // id - ID of extension.
  140. // storageArea - StorageArea to remove data from.
  141. // keys - Keys to remove.
  142. func RemoveStorageItems(id string, storageArea StorageArea, keys []string) *RemoveStorageItemsParams {
  143. return &RemoveStorageItemsParams{
  144. ID: id,
  145. StorageArea: storageArea,
  146. Keys: keys,
  147. }
  148. }
  149. // Do executes Extensions.removeStorageItems against the provided context.
  150. func (p *RemoveStorageItemsParams) Do(ctx context.Context) (err error) {
  151. return cdp.Execute(ctx, CommandRemoveStorageItems, p, nil)
  152. }
  153. // ClearStorageItemsParams clears extension storage in the given storageArea.
  154. type ClearStorageItemsParams struct {
  155. ID string `json:"id"` // ID of extension.
  156. StorageArea StorageArea `json:"storageArea"` // StorageArea to remove data from.
  157. }
  158. // ClearStorageItems clears extension storage in the given storageArea.
  159. //
  160. // See: https://chromedevtools.github.io/devtools-protocol/tot/Extensions#method-clearStorageItems
  161. //
  162. // parameters:
  163. //
  164. // id - ID of extension.
  165. // storageArea - StorageArea to remove data from.
  166. func ClearStorageItems(id string, storageArea StorageArea) *ClearStorageItemsParams {
  167. return &ClearStorageItemsParams{
  168. ID: id,
  169. StorageArea: storageArea,
  170. }
  171. }
  172. // Do executes Extensions.clearStorageItems against the provided context.
  173. func (p *ClearStorageItemsParams) Do(ctx context.Context) (err error) {
  174. return cdp.Execute(ctx, CommandClearStorageItems, p, nil)
  175. }
  176. // SetStorageItemsParams sets values in extension storage in the given
  177. // storageArea. The provided values will be merged with existing values in the
  178. // storage area.
  179. type SetStorageItemsParams struct {
  180. ID string `json:"id"` // ID of extension.
  181. StorageArea StorageArea `json:"storageArea"` // StorageArea to set data in.
  182. Values jsontext.Value `json:"values"`
  183. }
  184. // SetStorageItems sets values in extension storage in the given storageArea.
  185. // The provided values will be merged with existing values in the storage area.
  186. //
  187. // See: https://chromedevtools.github.io/devtools-protocol/tot/Extensions#method-setStorageItems
  188. //
  189. // parameters:
  190. //
  191. // id - ID of extension.
  192. // storageArea - StorageArea to set data in.
  193. // values - Values to set.
  194. func SetStorageItems(id string, storageArea StorageArea, values jsontext.Value) *SetStorageItemsParams {
  195. return &SetStorageItemsParams{
  196. ID: id,
  197. StorageArea: storageArea,
  198. Values: values,
  199. }
  200. }
  201. // Do executes Extensions.setStorageItems against the provided context.
  202. func (p *SetStorageItemsParams) Do(ctx context.Context) (err error) {
  203. return cdp.Execute(ctx, CommandSetStorageItems, p, nil)
  204. }
  205. // Command names.
  206. const (
  207. CommandLoadUnpacked = "Extensions.loadUnpacked"
  208. CommandUninstall = "Extensions.uninstall"
  209. CommandGetStorageItems = "Extensions.getStorageItems"
  210. CommandRemoveStorageItems = "Extensions.removeStorageItems"
  211. CommandClearStorageItems = "Extensions.clearStorageItems"
  212. CommandSetStorageItems = "Extensions.setStorageItems"
  213. )