indexeddb.go 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475
  1. // Package indexeddb provides the Chrome DevTools Protocol
  2. // commands, types, and events for the IndexedDB domain.
  3. //
  4. // Generated by the cdproto-gen command.
  5. package indexeddb
  6. // Code generated by cdproto-gen. DO NOT EDIT.
  7. import (
  8. "context"
  9. "github.com/chromedp/cdproto/cdp"
  10. "github.com/chromedp/cdproto/storage"
  11. )
  12. // ClearObjectStoreParams clears all entries from an object store.
  13. type ClearObjectStoreParams struct {
  14. SecurityOrigin string `json:"securityOrigin,omitempty"` // At least and at most one of securityOrigin, storageKey, or storageBucket must be specified. Security origin.
  15. StorageKey string `json:"storageKey,omitempty"` // Storage key.
  16. StorageBucket *storage.Bucket `json:"storageBucket,omitempty"` // Storage bucket. If not specified, it uses the default bucket.
  17. DatabaseName string `json:"databaseName"` // Database name.
  18. ObjectStoreName string `json:"objectStoreName"` // Object store name.
  19. }
  20. // ClearObjectStore clears all entries from an object store.
  21. //
  22. // See: https://chromedevtools.github.io/devtools-protocol/tot/IndexedDB#method-clearObjectStore
  23. //
  24. // parameters:
  25. //
  26. // databaseName - Database name.
  27. // objectStoreName - Object store name.
  28. func ClearObjectStore(databaseName string, objectStoreName string) *ClearObjectStoreParams {
  29. return &ClearObjectStoreParams{
  30. DatabaseName: databaseName,
  31. ObjectStoreName: objectStoreName,
  32. }
  33. }
  34. // WithSecurityOrigin at least and at most one of securityOrigin, storageKey,
  35. // or storageBucket must be specified. Security origin.
  36. func (p ClearObjectStoreParams) WithSecurityOrigin(securityOrigin string) *ClearObjectStoreParams {
  37. p.SecurityOrigin = securityOrigin
  38. return &p
  39. }
  40. // WithStorageKey storage key.
  41. func (p ClearObjectStoreParams) WithStorageKey(storageKey string) *ClearObjectStoreParams {
  42. p.StorageKey = storageKey
  43. return &p
  44. }
  45. // WithStorageBucket storage bucket. If not specified, it uses the default
  46. // bucket.
  47. func (p ClearObjectStoreParams) WithStorageBucket(storageBucket *storage.Bucket) *ClearObjectStoreParams {
  48. p.StorageBucket = storageBucket
  49. return &p
  50. }
  51. // Do executes IndexedDB.clearObjectStore against the provided context.
  52. func (p *ClearObjectStoreParams) Do(ctx context.Context) (err error) {
  53. return cdp.Execute(ctx, CommandClearObjectStore, p, nil)
  54. }
  55. // DeleteDatabaseParams deletes a database.
  56. type DeleteDatabaseParams struct {
  57. SecurityOrigin string `json:"securityOrigin,omitempty"` // At least and at most one of securityOrigin, storageKey, or storageBucket must be specified. Security origin.
  58. StorageKey string `json:"storageKey,omitempty"` // Storage key.
  59. StorageBucket *storage.Bucket `json:"storageBucket,omitempty"` // Storage bucket. If not specified, it uses the default bucket.
  60. DatabaseName string `json:"databaseName"` // Database name.
  61. }
  62. // DeleteDatabase deletes a database.
  63. //
  64. // See: https://chromedevtools.github.io/devtools-protocol/tot/IndexedDB#method-deleteDatabase
  65. //
  66. // parameters:
  67. //
  68. // databaseName - Database name.
  69. func DeleteDatabase(databaseName string) *DeleteDatabaseParams {
  70. return &DeleteDatabaseParams{
  71. DatabaseName: databaseName,
  72. }
  73. }
  74. // WithSecurityOrigin at least and at most one of securityOrigin, storageKey,
  75. // or storageBucket must be specified. Security origin.
  76. func (p DeleteDatabaseParams) WithSecurityOrigin(securityOrigin string) *DeleteDatabaseParams {
  77. p.SecurityOrigin = securityOrigin
  78. return &p
  79. }
  80. // WithStorageKey storage key.
  81. func (p DeleteDatabaseParams) WithStorageKey(storageKey string) *DeleteDatabaseParams {
  82. p.StorageKey = storageKey
  83. return &p
  84. }
  85. // WithStorageBucket storage bucket. If not specified, it uses the default
  86. // bucket.
  87. func (p DeleteDatabaseParams) WithStorageBucket(storageBucket *storage.Bucket) *DeleteDatabaseParams {
  88. p.StorageBucket = storageBucket
  89. return &p
  90. }
  91. // Do executes IndexedDB.deleteDatabase against the provided context.
  92. func (p *DeleteDatabaseParams) Do(ctx context.Context) (err error) {
  93. return cdp.Execute(ctx, CommandDeleteDatabase, p, nil)
  94. }
  95. // DeleteObjectStoreEntriesParams delete a range of entries from an object
  96. // store.
  97. type DeleteObjectStoreEntriesParams struct {
  98. SecurityOrigin string `json:"securityOrigin,omitempty"` // At least and at most one of securityOrigin, storageKey, or storageBucket must be specified. Security origin.
  99. StorageKey string `json:"storageKey,omitempty"` // Storage key.
  100. StorageBucket *storage.Bucket `json:"storageBucket,omitempty"` // Storage bucket. If not specified, it uses the default bucket.
  101. DatabaseName string `json:"databaseName"`
  102. ObjectStoreName string `json:"objectStoreName"`
  103. KeyRange *KeyRange `json:"keyRange"` // Range of entry keys to delete
  104. }
  105. // DeleteObjectStoreEntries delete a range of entries from an object store.
  106. //
  107. // See: https://chromedevtools.github.io/devtools-protocol/tot/IndexedDB#method-deleteObjectStoreEntries
  108. //
  109. // parameters:
  110. //
  111. // databaseName
  112. // objectStoreName
  113. // keyRange - Range of entry keys to delete
  114. func DeleteObjectStoreEntries(databaseName string, objectStoreName string, keyRange *KeyRange) *DeleteObjectStoreEntriesParams {
  115. return &DeleteObjectStoreEntriesParams{
  116. DatabaseName: databaseName,
  117. ObjectStoreName: objectStoreName,
  118. KeyRange: keyRange,
  119. }
  120. }
  121. // WithSecurityOrigin at least and at most one of securityOrigin, storageKey,
  122. // or storageBucket must be specified. Security origin.
  123. func (p DeleteObjectStoreEntriesParams) WithSecurityOrigin(securityOrigin string) *DeleteObjectStoreEntriesParams {
  124. p.SecurityOrigin = securityOrigin
  125. return &p
  126. }
  127. // WithStorageKey storage key.
  128. func (p DeleteObjectStoreEntriesParams) WithStorageKey(storageKey string) *DeleteObjectStoreEntriesParams {
  129. p.StorageKey = storageKey
  130. return &p
  131. }
  132. // WithStorageBucket storage bucket. If not specified, it uses the default
  133. // bucket.
  134. func (p DeleteObjectStoreEntriesParams) WithStorageBucket(storageBucket *storage.Bucket) *DeleteObjectStoreEntriesParams {
  135. p.StorageBucket = storageBucket
  136. return &p
  137. }
  138. // Do executes IndexedDB.deleteObjectStoreEntries against the provided context.
  139. func (p *DeleteObjectStoreEntriesParams) Do(ctx context.Context) (err error) {
  140. return cdp.Execute(ctx, CommandDeleteObjectStoreEntries, p, nil)
  141. }
  142. // DisableParams disables events from backend.
  143. type DisableParams struct{}
  144. // Disable disables events from backend.
  145. //
  146. // See: https://chromedevtools.github.io/devtools-protocol/tot/IndexedDB#method-disable
  147. func Disable() *DisableParams {
  148. return &DisableParams{}
  149. }
  150. // Do executes IndexedDB.disable against the provided context.
  151. func (p *DisableParams) Do(ctx context.Context) (err error) {
  152. return cdp.Execute(ctx, CommandDisable, nil, nil)
  153. }
  154. // EnableParams enables events from backend.
  155. type EnableParams struct{}
  156. // Enable enables events from backend.
  157. //
  158. // See: https://chromedevtools.github.io/devtools-protocol/tot/IndexedDB#method-enable
  159. func Enable() *EnableParams {
  160. return &EnableParams{}
  161. }
  162. // Do executes IndexedDB.enable against the provided context.
  163. func (p *EnableParams) Do(ctx context.Context) (err error) {
  164. return cdp.Execute(ctx, CommandEnable, nil, nil)
  165. }
  166. // RequestDataParams requests data from object store or index.
  167. type RequestDataParams struct {
  168. SecurityOrigin string `json:"securityOrigin,omitempty"` // At least and at most one of securityOrigin, storageKey, or storageBucket must be specified. Security origin.
  169. StorageKey string `json:"storageKey,omitempty"` // Storage key.
  170. StorageBucket *storage.Bucket `json:"storageBucket,omitempty"` // Storage bucket. If not specified, it uses the default bucket.
  171. DatabaseName string `json:"databaseName"` // Database name.
  172. ObjectStoreName string `json:"objectStoreName"` // Object store name.
  173. IndexName string `json:"indexName"` // Index name, empty string for object store data requests.
  174. SkipCount int64 `json:"skipCount"` // Number of records to skip.
  175. PageSize int64 `json:"pageSize"` // Number of records to fetch.
  176. KeyRange *KeyRange `json:"keyRange,omitempty"` // Key range.
  177. }
  178. // RequestData requests data from object store or index.
  179. //
  180. // See: https://chromedevtools.github.io/devtools-protocol/tot/IndexedDB#method-requestData
  181. //
  182. // parameters:
  183. //
  184. // databaseName - Database name.
  185. // objectStoreName - Object store name.
  186. // indexName - Index name, empty string for object store data requests.
  187. // skipCount - Number of records to skip.
  188. // pageSize - Number of records to fetch.
  189. func RequestData(databaseName string, objectStoreName string, indexName string, skipCount int64, pageSize int64) *RequestDataParams {
  190. return &RequestDataParams{
  191. DatabaseName: databaseName,
  192. ObjectStoreName: objectStoreName,
  193. IndexName: indexName,
  194. SkipCount: skipCount,
  195. PageSize: pageSize,
  196. }
  197. }
  198. // WithSecurityOrigin at least and at most one of securityOrigin, storageKey,
  199. // or storageBucket must be specified. Security origin.
  200. func (p RequestDataParams) WithSecurityOrigin(securityOrigin string) *RequestDataParams {
  201. p.SecurityOrigin = securityOrigin
  202. return &p
  203. }
  204. // WithStorageKey storage key.
  205. func (p RequestDataParams) WithStorageKey(storageKey string) *RequestDataParams {
  206. p.StorageKey = storageKey
  207. return &p
  208. }
  209. // WithStorageBucket storage bucket. If not specified, it uses the default
  210. // bucket.
  211. func (p RequestDataParams) WithStorageBucket(storageBucket *storage.Bucket) *RequestDataParams {
  212. p.StorageBucket = storageBucket
  213. return &p
  214. }
  215. // WithKeyRange key range.
  216. func (p RequestDataParams) WithKeyRange(keyRange *KeyRange) *RequestDataParams {
  217. p.KeyRange = keyRange
  218. return &p
  219. }
  220. // RequestDataReturns return values.
  221. type RequestDataReturns struct {
  222. ObjectStoreDataEntries []*DataEntry `json:"objectStoreDataEntries,omitempty"` // Array of object store data entries.
  223. HasMore bool `json:"hasMore,omitempty"` // If true, there are more entries to fetch in the given range.
  224. }
  225. // Do executes IndexedDB.requestData against the provided context.
  226. //
  227. // returns:
  228. //
  229. // objectStoreDataEntries - Array of object store data entries.
  230. // hasMore - If true, there are more entries to fetch in the given range.
  231. func (p *RequestDataParams) Do(ctx context.Context) (objectStoreDataEntries []*DataEntry, hasMore bool, err error) {
  232. // execute
  233. var res RequestDataReturns
  234. err = cdp.Execute(ctx, CommandRequestData, p, &res)
  235. if err != nil {
  236. return nil, false, err
  237. }
  238. return res.ObjectStoreDataEntries, res.HasMore, nil
  239. }
  240. // GetMetadataParams gets metadata of an object store.
  241. type GetMetadataParams struct {
  242. SecurityOrigin string `json:"securityOrigin,omitempty"` // At least and at most one of securityOrigin, storageKey, or storageBucket must be specified. Security origin.
  243. StorageKey string `json:"storageKey,omitempty"` // Storage key.
  244. StorageBucket *storage.Bucket `json:"storageBucket,omitempty"` // Storage bucket. If not specified, it uses the default bucket.
  245. DatabaseName string `json:"databaseName"` // Database name.
  246. ObjectStoreName string `json:"objectStoreName"` // Object store name.
  247. }
  248. // GetMetadata gets metadata of an object store.
  249. //
  250. // See: https://chromedevtools.github.io/devtools-protocol/tot/IndexedDB#method-getMetadata
  251. //
  252. // parameters:
  253. //
  254. // databaseName - Database name.
  255. // objectStoreName - Object store name.
  256. func GetMetadata(databaseName string, objectStoreName string) *GetMetadataParams {
  257. return &GetMetadataParams{
  258. DatabaseName: databaseName,
  259. ObjectStoreName: objectStoreName,
  260. }
  261. }
  262. // WithSecurityOrigin at least and at most one of securityOrigin, storageKey,
  263. // or storageBucket must be specified. Security origin.
  264. func (p GetMetadataParams) WithSecurityOrigin(securityOrigin string) *GetMetadataParams {
  265. p.SecurityOrigin = securityOrigin
  266. return &p
  267. }
  268. // WithStorageKey storage key.
  269. func (p GetMetadataParams) WithStorageKey(storageKey string) *GetMetadataParams {
  270. p.StorageKey = storageKey
  271. return &p
  272. }
  273. // WithStorageBucket storage bucket. If not specified, it uses the default
  274. // bucket.
  275. func (p GetMetadataParams) WithStorageBucket(storageBucket *storage.Bucket) *GetMetadataParams {
  276. p.StorageBucket = storageBucket
  277. return &p
  278. }
  279. // GetMetadataReturns return values.
  280. type GetMetadataReturns struct {
  281. EntriesCount float64 `json:"entriesCount,omitempty"` // the entries count
  282. KeyGeneratorValue float64 `json:"keyGeneratorValue,omitempty"` // the current value of key generator, to become the next inserted key into the object store. Valid if objectStore.autoIncrement is true.
  283. }
  284. // Do executes IndexedDB.getMetadata against the provided context.
  285. //
  286. // returns:
  287. //
  288. // entriesCount - the entries count
  289. // keyGeneratorValue - the current value of key generator, to become the next inserted key into the object store. Valid if objectStore.autoIncrement is true.
  290. func (p *GetMetadataParams) Do(ctx context.Context) (entriesCount float64, keyGeneratorValue float64, err error) {
  291. // execute
  292. var res GetMetadataReturns
  293. err = cdp.Execute(ctx, CommandGetMetadata, p, &res)
  294. if err != nil {
  295. return 0, 0, err
  296. }
  297. return res.EntriesCount, res.KeyGeneratorValue, nil
  298. }
  299. // RequestDatabaseParams requests database with given name in given frame.
  300. type RequestDatabaseParams struct {
  301. SecurityOrigin string `json:"securityOrigin,omitempty"` // At least and at most one of securityOrigin, storageKey, or storageBucket must be specified. Security origin.
  302. StorageKey string `json:"storageKey,omitempty"` // Storage key.
  303. StorageBucket *storage.Bucket `json:"storageBucket,omitempty"` // Storage bucket. If not specified, it uses the default bucket.
  304. DatabaseName string `json:"databaseName"` // Database name.
  305. }
  306. // RequestDatabase requests database with given name in given frame.
  307. //
  308. // See: https://chromedevtools.github.io/devtools-protocol/tot/IndexedDB#method-requestDatabase
  309. //
  310. // parameters:
  311. //
  312. // databaseName - Database name.
  313. func RequestDatabase(databaseName string) *RequestDatabaseParams {
  314. return &RequestDatabaseParams{
  315. DatabaseName: databaseName,
  316. }
  317. }
  318. // WithSecurityOrigin at least and at most one of securityOrigin, storageKey,
  319. // or storageBucket must be specified. Security origin.
  320. func (p RequestDatabaseParams) WithSecurityOrigin(securityOrigin string) *RequestDatabaseParams {
  321. p.SecurityOrigin = securityOrigin
  322. return &p
  323. }
  324. // WithStorageKey storage key.
  325. func (p RequestDatabaseParams) WithStorageKey(storageKey string) *RequestDatabaseParams {
  326. p.StorageKey = storageKey
  327. return &p
  328. }
  329. // WithStorageBucket storage bucket. If not specified, it uses the default
  330. // bucket.
  331. func (p RequestDatabaseParams) WithStorageBucket(storageBucket *storage.Bucket) *RequestDatabaseParams {
  332. p.StorageBucket = storageBucket
  333. return &p
  334. }
  335. // RequestDatabaseReturns return values.
  336. type RequestDatabaseReturns struct {
  337. DatabaseWithObjectStores *DatabaseWithObjectStores `json:"databaseWithObjectStores,omitempty"` // Database with an array of object stores.
  338. }
  339. // Do executes IndexedDB.requestDatabase against the provided context.
  340. //
  341. // returns:
  342. //
  343. // databaseWithObjectStores - Database with an array of object stores.
  344. func (p *RequestDatabaseParams) Do(ctx context.Context) (databaseWithObjectStores *DatabaseWithObjectStores, err error) {
  345. // execute
  346. var res RequestDatabaseReturns
  347. err = cdp.Execute(ctx, CommandRequestDatabase, p, &res)
  348. if err != nil {
  349. return nil, err
  350. }
  351. return res.DatabaseWithObjectStores, nil
  352. }
  353. // RequestDatabaseNamesParams requests database names for given security
  354. // origin.
  355. type RequestDatabaseNamesParams struct {
  356. SecurityOrigin string `json:"securityOrigin,omitempty"` // At least and at most one of securityOrigin, storageKey, or storageBucket must be specified. Security origin.
  357. StorageKey string `json:"storageKey,omitempty"` // Storage key.
  358. StorageBucket *storage.Bucket `json:"storageBucket,omitempty"` // Storage bucket. If not specified, it uses the default bucket.
  359. }
  360. // RequestDatabaseNames requests database names for given security origin.
  361. //
  362. // See: https://chromedevtools.github.io/devtools-protocol/tot/IndexedDB#method-requestDatabaseNames
  363. //
  364. // parameters:
  365. func RequestDatabaseNames() *RequestDatabaseNamesParams {
  366. return &RequestDatabaseNamesParams{}
  367. }
  368. // WithSecurityOrigin at least and at most one of securityOrigin, storageKey,
  369. // or storageBucket must be specified. Security origin.
  370. func (p RequestDatabaseNamesParams) WithSecurityOrigin(securityOrigin string) *RequestDatabaseNamesParams {
  371. p.SecurityOrigin = securityOrigin
  372. return &p
  373. }
  374. // WithStorageKey storage key.
  375. func (p RequestDatabaseNamesParams) WithStorageKey(storageKey string) *RequestDatabaseNamesParams {
  376. p.StorageKey = storageKey
  377. return &p
  378. }
  379. // WithStorageBucket storage bucket. If not specified, it uses the default
  380. // bucket.
  381. func (p RequestDatabaseNamesParams) WithStorageBucket(storageBucket *storage.Bucket) *RequestDatabaseNamesParams {
  382. p.StorageBucket = storageBucket
  383. return &p
  384. }
  385. // RequestDatabaseNamesReturns return values.
  386. type RequestDatabaseNamesReturns struct {
  387. DatabaseNames []string `json:"databaseNames,omitempty"` // Database names for origin.
  388. }
  389. // Do executes IndexedDB.requestDatabaseNames against the provided context.
  390. //
  391. // returns:
  392. //
  393. // databaseNames - Database names for origin.
  394. func (p *RequestDatabaseNamesParams) Do(ctx context.Context) (databaseNames []string, err error) {
  395. // execute
  396. var res RequestDatabaseNamesReturns
  397. err = cdp.Execute(ctx, CommandRequestDatabaseNames, p, &res)
  398. if err != nil {
  399. return nil, err
  400. }
  401. return res.DatabaseNames, nil
  402. }
  403. // Command names.
  404. const (
  405. CommandClearObjectStore = "IndexedDB.clearObjectStore"
  406. CommandDeleteDatabase = "IndexedDB.deleteDatabase"
  407. CommandDeleteObjectStoreEntries = "IndexedDB.deleteObjectStoreEntries"
  408. CommandDisable = "IndexedDB.disable"
  409. CommandEnable = "IndexedDB.enable"
  410. CommandRequestData = "IndexedDB.requestData"
  411. CommandGetMetadata = "IndexedDB.getMetadata"
  412. CommandRequestDatabase = "IndexedDB.requestDatabase"
  413. CommandRequestDatabaseNames = "IndexedDB.requestDatabaseNames"
  414. )