page.go 66 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792
  1. // Package page provides the Chrome DevTools Protocol
  2. // commands, types, and events for the Page domain.
  3. //
  4. // Actions and events related to the inspected page belong to the page
  5. // domain.
  6. //
  7. // Generated by the cdproto-gen command.
  8. package page
  9. // Code generated by cdproto-gen. DO NOT EDIT.
  10. import (
  11. "context"
  12. "encoding/base64"
  13. "github.com/chromedp/cdproto/cdp"
  14. "github.com/chromedp/cdproto/debugger"
  15. "github.com/chromedp/cdproto/dom"
  16. "github.com/chromedp/cdproto/io"
  17. "github.com/chromedp/cdproto/runtime"
  18. )
  19. // AddScriptToEvaluateOnNewDocumentParams evaluates given script in every
  20. // frame upon creation (before loading frame's scripts).
  21. type AddScriptToEvaluateOnNewDocumentParams struct {
  22. Source string `json:"source"`
  23. WorldName string `json:"worldName,omitempty"` // If specified, creates an isolated world with the given name and evaluates given script in it. This world name will be used as the ExecutionContextDescription::name when the corresponding event is emitted.
  24. IncludeCommandLineAPI bool `json:"includeCommandLineAPI,omitempty"` // Specifies whether command line API should be available to the script, defaults to false.
  25. RunImmediately bool `json:"runImmediately,omitempty"` // If true, runs the script immediately on existing execution contexts or worlds. Default: false.
  26. }
  27. // AddScriptToEvaluateOnNewDocument evaluates given script in every frame
  28. // upon creation (before loading frame's scripts).
  29. //
  30. // See: https://chromedevtools.github.io/devtools-protocol/tot/Page#method-addScriptToEvaluateOnNewDocument
  31. //
  32. // parameters:
  33. //
  34. // source
  35. func AddScriptToEvaluateOnNewDocument(source string) *AddScriptToEvaluateOnNewDocumentParams {
  36. return &AddScriptToEvaluateOnNewDocumentParams{
  37. Source: source,
  38. }
  39. }
  40. // WithWorldName if specified, creates an isolated world with the given name
  41. // and evaluates given script in it. This world name will be used as the
  42. // ExecutionContextDescription::name when the corresponding event is emitted.
  43. func (p AddScriptToEvaluateOnNewDocumentParams) WithWorldName(worldName string) *AddScriptToEvaluateOnNewDocumentParams {
  44. p.WorldName = worldName
  45. return &p
  46. }
  47. // WithIncludeCommandLineAPI specifies whether command line API should be
  48. // available to the script, defaults to false.
  49. func (p AddScriptToEvaluateOnNewDocumentParams) WithIncludeCommandLineAPI(includeCommandLineAPI bool) *AddScriptToEvaluateOnNewDocumentParams {
  50. p.IncludeCommandLineAPI = includeCommandLineAPI
  51. return &p
  52. }
  53. // WithRunImmediately if true, runs the script immediately on existing
  54. // execution contexts or worlds. Default: false.
  55. func (p AddScriptToEvaluateOnNewDocumentParams) WithRunImmediately(runImmediately bool) *AddScriptToEvaluateOnNewDocumentParams {
  56. p.RunImmediately = runImmediately
  57. return &p
  58. }
  59. // AddScriptToEvaluateOnNewDocumentReturns return values.
  60. type AddScriptToEvaluateOnNewDocumentReturns struct {
  61. Identifier ScriptIdentifier `json:"identifier,omitempty"` // Identifier of the added script.
  62. }
  63. // Do executes Page.addScriptToEvaluateOnNewDocument against the provided context.
  64. //
  65. // returns:
  66. //
  67. // identifier - Identifier of the added script.
  68. func (p *AddScriptToEvaluateOnNewDocumentParams) Do(ctx context.Context) (identifier ScriptIdentifier, err error) {
  69. // execute
  70. var res AddScriptToEvaluateOnNewDocumentReturns
  71. err = cdp.Execute(ctx, CommandAddScriptToEvaluateOnNewDocument, p, &res)
  72. if err != nil {
  73. return "", err
  74. }
  75. return res.Identifier, nil
  76. }
  77. // BringToFrontParams brings page to front (activates tab).
  78. type BringToFrontParams struct{}
  79. // BringToFront brings page to front (activates tab).
  80. //
  81. // See: https://chromedevtools.github.io/devtools-protocol/tot/Page#method-bringToFront
  82. func BringToFront() *BringToFrontParams {
  83. return &BringToFrontParams{}
  84. }
  85. // Do executes Page.bringToFront against the provided context.
  86. func (p *BringToFrontParams) Do(ctx context.Context) (err error) {
  87. return cdp.Execute(ctx, CommandBringToFront, nil, nil)
  88. }
  89. // CaptureScreenshotParams capture page screenshot.
  90. type CaptureScreenshotParams struct {
  91. Format CaptureScreenshotFormat `json:"format,omitempty"` // Image compression format (defaults to png).
  92. Quality int64 `json:"quality,omitempty"` // Compression quality from range [0..100] (jpeg only).
  93. Clip *Viewport `json:"clip,omitempty"` // Capture the screenshot of a given region only.
  94. FromSurface bool `json:"fromSurface,omitempty"` // Capture the screenshot from the surface, rather than the view. Defaults to true.
  95. CaptureBeyondViewport bool `json:"captureBeyondViewport,omitempty"` // Capture the screenshot beyond the viewport. Defaults to false.
  96. OptimizeForSpeed bool `json:"optimizeForSpeed,omitempty"` // Optimize image encoding for speed, not for resulting size (defaults to false)
  97. }
  98. // CaptureScreenshot capture page screenshot.
  99. //
  100. // See: https://chromedevtools.github.io/devtools-protocol/tot/Page#method-captureScreenshot
  101. //
  102. // parameters:
  103. func CaptureScreenshot() *CaptureScreenshotParams {
  104. return &CaptureScreenshotParams{}
  105. }
  106. // WithFormat image compression format (defaults to png).
  107. func (p CaptureScreenshotParams) WithFormat(format CaptureScreenshotFormat) *CaptureScreenshotParams {
  108. p.Format = format
  109. return &p
  110. }
  111. // WithQuality compression quality from range [0..100] (jpeg only).
  112. func (p CaptureScreenshotParams) WithQuality(quality int64) *CaptureScreenshotParams {
  113. p.Quality = quality
  114. return &p
  115. }
  116. // WithClip capture the screenshot of a given region only.
  117. func (p CaptureScreenshotParams) WithClip(clip *Viewport) *CaptureScreenshotParams {
  118. p.Clip = clip
  119. return &p
  120. }
  121. // WithFromSurface capture the screenshot from the surface, rather than the
  122. // view. Defaults to true.
  123. func (p CaptureScreenshotParams) WithFromSurface(fromSurface bool) *CaptureScreenshotParams {
  124. p.FromSurface = fromSurface
  125. return &p
  126. }
  127. // WithCaptureBeyondViewport capture the screenshot beyond the viewport.
  128. // Defaults to false.
  129. func (p CaptureScreenshotParams) WithCaptureBeyondViewport(captureBeyondViewport bool) *CaptureScreenshotParams {
  130. p.CaptureBeyondViewport = captureBeyondViewport
  131. return &p
  132. }
  133. // WithOptimizeForSpeed optimize image encoding for speed, not for resulting
  134. // size (defaults to false).
  135. func (p CaptureScreenshotParams) WithOptimizeForSpeed(optimizeForSpeed bool) *CaptureScreenshotParams {
  136. p.OptimizeForSpeed = optimizeForSpeed
  137. return &p
  138. }
  139. // CaptureScreenshotReturns return values.
  140. type CaptureScreenshotReturns struct {
  141. Data string `json:"data,omitempty"` // Base64-encoded image data.
  142. }
  143. // Do executes Page.captureScreenshot against the provided context.
  144. //
  145. // returns:
  146. //
  147. // data - Base64-encoded image data.
  148. func (p *CaptureScreenshotParams) Do(ctx context.Context) (data []byte, err error) {
  149. // execute
  150. var res CaptureScreenshotReturns
  151. err = cdp.Execute(ctx, CommandCaptureScreenshot, p, &res)
  152. if err != nil {
  153. return nil, err
  154. }
  155. // decode
  156. var dec []byte
  157. dec, err = base64.StdEncoding.DecodeString(res.Data)
  158. if err != nil {
  159. return nil, err
  160. }
  161. return dec, nil
  162. }
  163. // CaptureSnapshotParams returns a snapshot of the page as a string. For
  164. // MHTML format, the serialization includes iframes, shadow DOM, external
  165. // resources, and element-inline styles.
  166. type CaptureSnapshotParams struct {
  167. Format CaptureSnapshotFormat `json:"format,omitempty"` // Format (defaults to mhtml).
  168. }
  169. // CaptureSnapshot returns a snapshot of the page as a string. For MHTML
  170. // format, the serialization includes iframes, shadow DOM, external resources,
  171. // and element-inline styles.
  172. //
  173. // See: https://chromedevtools.github.io/devtools-protocol/tot/Page#method-captureSnapshot
  174. //
  175. // parameters:
  176. func CaptureSnapshot() *CaptureSnapshotParams {
  177. return &CaptureSnapshotParams{}
  178. }
  179. // WithFormat format (defaults to mhtml).
  180. func (p CaptureSnapshotParams) WithFormat(format CaptureSnapshotFormat) *CaptureSnapshotParams {
  181. p.Format = format
  182. return &p
  183. }
  184. // CaptureSnapshotReturns return values.
  185. type CaptureSnapshotReturns struct {
  186. Data string `json:"data,omitempty"` // Serialized page data.
  187. }
  188. // Do executes Page.captureSnapshot against the provided context.
  189. //
  190. // returns:
  191. //
  192. // data - Serialized page data.
  193. func (p *CaptureSnapshotParams) Do(ctx context.Context) (data string, err error) {
  194. // execute
  195. var res CaptureSnapshotReturns
  196. err = cdp.Execute(ctx, CommandCaptureSnapshot, p, &res)
  197. if err != nil {
  198. return "", err
  199. }
  200. return res.Data, nil
  201. }
  202. // CreateIsolatedWorldParams creates an isolated world for the given frame.
  203. type CreateIsolatedWorldParams struct {
  204. FrameID cdp.FrameID `json:"frameId"` // Id of the frame in which the isolated world should be created.
  205. WorldName string `json:"worldName,omitempty"` // An optional name which is reported in the Execution Context.
  206. GrantUniveralAccess bool `json:"grantUniveralAccess,omitempty"` // Whether or not universal access should be granted to the isolated world. This is a powerful option, use with caution.
  207. }
  208. // CreateIsolatedWorld creates an isolated world for the given frame.
  209. //
  210. // See: https://chromedevtools.github.io/devtools-protocol/tot/Page#method-createIsolatedWorld
  211. //
  212. // parameters:
  213. //
  214. // frameID - Id of the frame in which the isolated world should be created.
  215. func CreateIsolatedWorld(frameID cdp.FrameID) *CreateIsolatedWorldParams {
  216. return &CreateIsolatedWorldParams{
  217. FrameID: frameID,
  218. }
  219. }
  220. // WithWorldName an optional name which is reported in the Execution Context.
  221. func (p CreateIsolatedWorldParams) WithWorldName(worldName string) *CreateIsolatedWorldParams {
  222. p.WorldName = worldName
  223. return &p
  224. }
  225. // WithGrantUniveralAccess whether or not universal access should be granted
  226. // to the isolated world. This is a powerful option, use with caution.
  227. func (p CreateIsolatedWorldParams) WithGrantUniveralAccess(grantUniveralAccess bool) *CreateIsolatedWorldParams {
  228. p.GrantUniveralAccess = grantUniveralAccess
  229. return &p
  230. }
  231. // CreateIsolatedWorldReturns return values.
  232. type CreateIsolatedWorldReturns struct {
  233. ExecutionContextID runtime.ExecutionContextID `json:"executionContextId,omitempty"` // Execution context of the isolated world.
  234. }
  235. // Do executes Page.createIsolatedWorld against the provided context.
  236. //
  237. // returns:
  238. //
  239. // executionContextID - Execution context of the isolated world.
  240. func (p *CreateIsolatedWorldParams) Do(ctx context.Context) (executionContextID runtime.ExecutionContextID, err error) {
  241. // execute
  242. var res CreateIsolatedWorldReturns
  243. err = cdp.Execute(ctx, CommandCreateIsolatedWorld, p, &res)
  244. if err != nil {
  245. return 0, err
  246. }
  247. return res.ExecutionContextID, nil
  248. }
  249. // DisableParams disables page domain notifications.
  250. type DisableParams struct{}
  251. // Disable disables page domain notifications.
  252. //
  253. // See: https://chromedevtools.github.io/devtools-protocol/tot/Page#method-disable
  254. func Disable() *DisableParams {
  255. return &DisableParams{}
  256. }
  257. // Do executes Page.disable against the provided context.
  258. func (p *DisableParams) Do(ctx context.Context) (err error) {
  259. return cdp.Execute(ctx, CommandDisable, nil, nil)
  260. }
  261. // EnableParams enables page domain notifications.
  262. type EnableParams struct{}
  263. // Enable enables page domain notifications.
  264. //
  265. // See: https://chromedevtools.github.io/devtools-protocol/tot/Page#method-enable
  266. func Enable() *EnableParams {
  267. return &EnableParams{}
  268. }
  269. // Do executes Page.enable against the provided context.
  270. func (p *EnableParams) Do(ctx context.Context) (err error) {
  271. return cdp.Execute(ctx, CommandEnable, nil, nil)
  272. }
  273. // GetAppManifestParams gets the processed manifest for this current
  274. // document. This API always waits for the manifest to be loaded. If manifestId
  275. // is provided, and it does not match the manifest of the current document, this
  276. // API errors out. If there is not a loaded page, this API errors out
  277. // immediately.
  278. type GetAppManifestParams struct {
  279. ManifestID string `json:"manifestId,omitempty"`
  280. }
  281. // GetAppManifest gets the processed manifest for this current document. This
  282. // API always waits for the manifest to be loaded. If manifestId is provided,
  283. // and it does not match the manifest of the current document, this API errors
  284. // out. If there is not a loaded page, this API errors out immediately.
  285. //
  286. // See: https://chromedevtools.github.io/devtools-protocol/tot/Page#method-getAppManifest
  287. //
  288. // parameters:
  289. func GetAppManifest() *GetAppManifestParams {
  290. return &GetAppManifestParams{}
  291. }
  292. // WithManifestID [no description].
  293. func (p GetAppManifestParams) WithManifestID(manifestID string) *GetAppManifestParams {
  294. p.ManifestID = manifestID
  295. return &p
  296. }
  297. // GetAppManifestReturns return values.
  298. type GetAppManifestReturns struct {
  299. URL string `json:"url,omitempty"` // Manifest location.
  300. Errors []*AppManifestError `json:"errors,omitempty"`
  301. Data string `json:"data,omitempty"` // Manifest content.
  302. Manifest *WebAppManifest `json:"manifest,omitempty"`
  303. }
  304. // Do executes Page.getAppManifest against the provided context.
  305. //
  306. // returns:
  307. //
  308. // url - Manifest location.
  309. // errors
  310. // data - Manifest content.
  311. // manifest
  312. func (p *GetAppManifestParams) Do(ctx context.Context) (url string, errors []*AppManifestError, data string, manifest *WebAppManifest, err error) {
  313. // execute
  314. var res GetAppManifestReturns
  315. err = cdp.Execute(ctx, CommandGetAppManifest, p, &res)
  316. if err != nil {
  317. return "", nil, "", nil, err
  318. }
  319. return res.URL, res.Errors, res.Data, res.Manifest, nil
  320. }
  321. // GetInstallabilityErrorsParams [no description].
  322. type GetInstallabilityErrorsParams struct{}
  323. // GetInstallabilityErrors [no description].
  324. //
  325. // See: https://chromedevtools.github.io/devtools-protocol/tot/Page#method-getInstallabilityErrors
  326. func GetInstallabilityErrors() *GetInstallabilityErrorsParams {
  327. return &GetInstallabilityErrorsParams{}
  328. }
  329. // GetInstallabilityErrorsReturns return values.
  330. type GetInstallabilityErrorsReturns struct {
  331. InstallabilityErrors []*InstallabilityError `json:"installabilityErrors,omitempty"`
  332. }
  333. // Do executes Page.getInstallabilityErrors against the provided context.
  334. //
  335. // returns:
  336. //
  337. // installabilityErrors
  338. func (p *GetInstallabilityErrorsParams) Do(ctx context.Context) (installabilityErrors []*InstallabilityError, err error) {
  339. // execute
  340. var res GetInstallabilityErrorsReturns
  341. err = cdp.Execute(ctx, CommandGetInstallabilityErrors, nil, &res)
  342. if err != nil {
  343. return nil, err
  344. }
  345. return res.InstallabilityErrors, nil
  346. }
  347. // GetAppIDParams returns the unique (PWA) app id. Only returns values if the
  348. // feature flag 'WebAppEnableManifestId' is enabled.
  349. type GetAppIDParams struct{}
  350. // GetAppID returns the unique (PWA) app id. Only returns values if the
  351. // feature flag 'WebAppEnableManifestId' is enabled.
  352. //
  353. // See: https://chromedevtools.github.io/devtools-protocol/tot/Page#method-getAppId
  354. func GetAppID() *GetAppIDParams {
  355. return &GetAppIDParams{}
  356. }
  357. // GetAppIDReturns return values.
  358. type GetAppIDReturns struct {
  359. AppID string `json:"appId,omitempty"` // App id, either from manifest's id attribute or computed from start_url
  360. RecommendedID string `json:"recommendedId,omitempty"` // Recommendation for manifest's id attribute to match current id computed from start_url
  361. }
  362. // Do executes Page.getAppId against the provided context.
  363. //
  364. // returns:
  365. //
  366. // appID - App id, either from manifest's id attribute or computed from start_url
  367. // recommendedID - Recommendation for manifest's id attribute to match current id computed from start_url
  368. func (p *GetAppIDParams) Do(ctx context.Context) (appID string, recommendedID string, err error) {
  369. // execute
  370. var res GetAppIDReturns
  371. err = cdp.Execute(ctx, CommandGetAppID, nil, &res)
  372. if err != nil {
  373. return "", "", err
  374. }
  375. return res.AppID, res.RecommendedID, nil
  376. }
  377. // GetAdScriptIDParams [no description].
  378. type GetAdScriptIDParams struct {
  379. FrameID cdp.FrameID `json:"frameId"`
  380. }
  381. // GetAdScriptID [no description].
  382. //
  383. // See: https://chromedevtools.github.io/devtools-protocol/tot/Page#method-getAdScriptId
  384. //
  385. // parameters:
  386. //
  387. // frameID
  388. func GetAdScriptID(frameID cdp.FrameID) *GetAdScriptIDParams {
  389. return &GetAdScriptIDParams{
  390. FrameID: frameID,
  391. }
  392. }
  393. // GetAdScriptIDReturns return values.
  394. type GetAdScriptIDReturns struct {
  395. AdScriptID *AdScriptID `json:"adScriptId,omitempty"` // Identifies the bottom-most script which caused the frame to be labelled as an ad. Only sent if frame is labelled as an ad and id is available.
  396. }
  397. // Do executes Page.getAdScriptId against the provided context.
  398. //
  399. // returns:
  400. //
  401. // adScriptID - Identifies the bottom-most script which caused the frame to be labelled as an ad. Only sent if frame is labelled as an ad and id is available.
  402. func (p *GetAdScriptIDParams) Do(ctx context.Context) (adScriptID *AdScriptID, err error) {
  403. // execute
  404. var res GetAdScriptIDReturns
  405. err = cdp.Execute(ctx, CommandGetAdScriptID, p, &res)
  406. if err != nil {
  407. return nil, err
  408. }
  409. return res.AdScriptID, nil
  410. }
  411. // GetFrameTreeParams returns present frame tree structure.
  412. type GetFrameTreeParams struct{}
  413. // GetFrameTree returns present frame tree structure.
  414. //
  415. // See: https://chromedevtools.github.io/devtools-protocol/tot/Page#method-getFrameTree
  416. func GetFrameTree() *GetFrameTreeParams {
  417. return &GetFrameTreeParams{}
  418. }
  419. // GetFrameTreeReturns return values.
  420. type GetFrameTreeReturns struct {
  421. FrameTree *FrameTree `json:"frameTree,omitempty"` // Present frame tree structure.
  422. }
  423. // Do executes Page.getFrameTree against the provided context.
  424. //
  425. // returns:
  426. //
  427. // frameTree - Present frame tree structure.
  428. func (p *GetFrameTreeParams) Do(ctx context.Context) (frameTree *FrameTree, err error) {
  429. // execute
  430. var res GetFrameTreeReturns
  431. err = cdp.Execute(ctx, CommandGetFrameTree, nil, &res)
  432. if err != nil {
  433. return nil, err
  434. }
  435. return res.FrameTree, nil
  436. }
  437. // GetLayoutMetricsParams returns metrics relating to the layouting of the
  438. // page, such as viewport bounds/scale.
  439. type GetLayoutMetricsParams struct{}
  440. // GetLayoutMetrics returns metrics relating to the layouting of the page,
  441. // such as viewport bounds/scale.
  442. //
  443. // See: https://chromedevtools.github.io/devtools-protocol/tot/Page#method-getLayoutMetrics
  444. func GetLayoutMetrics() *GetLayoutMetricsParams {
  445. return &GetLayoutMetricsParams{}
  446. }
  447. // GetLayoutMetricsReturns return values.
  448. type GetLayoutMetricsReturns struct {
  449. LayoutViewport *LayoutViewport `json:"layoutViewport"` // Deprecated metrics relating to the layout viewport. Is in device pixels. Use cssLayoutViewport instead.
  450. VisualViewport *VisualViewport `json:"visualViewport"` // Deprecated metrics relating to the visual viewport. Is in device pixels. Use cssVisualViewport instead.
  451. ContentSize *dom.Rect `json:"contentSize"` // Deprecated size of scrollable area. Is in DP. Use cssContentSize instead.
  452. CSSLayoutViewport *LayoutViewport `json:"cssLayoutViewport"` // Metrics relating to the layout viewport in CSS pixels.
  453. CSSVisualViewport *VisualViewport `json:"cssVisualViewport"` // Metrics relating to the visual viewport in CSS pixels.
  454. CSSContentSize *dom.Rect `json:"cssContentSize"` // Size of scrollable area in CSS pixels.
  455. }
  456. // Do executes Page.getLayoutMetrics against the provided context.
  457. //
  458. // returns:
  459. //
  460. // layoutViewport - Deprecated metrics relating to the layout viewport. Is in device pixels. Use cssLayoutViewport instead.
  461. // visualViewport - Deprecated metrics relating to the visual viewport. Is in device pixels. Use cssVisualViewport instead.
  462. // contentSize - Deprecated size of scrollable area. Is in DP. Use cssContentSize instead.
  463. // cssLayoutViewport - Metrics relating to the layout viewport in CSS pixels.
  464. // cssVisualViewport - Metrics relating to the visual viewport in CSS pixels.
  465. // cssContentSize - Size of scrollable area in CSS pixels.
  466. func (p *GetLayoutMetricsParams) Do(ctx context.Context) (layoutViewport *LayoutViewport, visualViewport *VisualViewport, contentSize *dom.Rect, cssLayoutViewport *LayoutViewport, cssVisualViewport *VisualViewport, cssContentSize *dom.Rect, err error) {
  467. // execute
  468. var res GetLayoutMetricsReturns
  469. err = cdp.Execute(ctx, CommandGetLayoutMetrics, nil, &res)
  470. if err != nil {
  471. return nil, nil, nil, nil, nil, nil, err
  472. }
  473. return res.LayoutViewport, res.VisualViewport, res.ContentSize, res.CSSLayoutViewport, res.CSSVisualViewport, res.CSSContentSize, nil
  474. }
  475. // GetNavigationHistoryParams returns navigation history for the current
  476. // page.
  477. type GetNavigationHistoryParams struct{}
  478. // GetNavigationHistory returns navigation history for the current page.
  479. //
  480. // See: https://chromedevtools.github.io/devtools-protocol/tot/Page#method-getNavigationHistory
  481. func GetNavigationHistory() *GetNavigationHistoryParams {
  482. return &GetNavigationHistoryParams{}
  483. }
  484. // GetNavigationHistoryReturns return values.
  485. type GetNavigationHistoryReturns struct {
  486. CurrentIndex int64 `json:"currentIndex,omitempty"` // Index of the current navigation history entry.
  487. Entries []*NavigationEntry `json:"entries,omitempty"` // Array of navigation history entries.
  488. }
  489. // Do executes Page.getNavigationHistory against the provided context.
  490. //
  491. // returns:
  492. //
  493. // currentIndex - Index of the current navigation history entry.
  494. // entries - Array of navigation history entries.
  495. func (p *GetNavigationHistoryParams) Do(ctx context.Context) (currentIndex int64, entries []*NavigationEntry, err error) {
  496. // execute
  497. var res GetNavigationHistoryReturns
  498. err = cdp.Execute(ctx, CommandGetNavigationHistory, nil, &res)
  499. if err != nil {
  500. return 0, nil, err
  501. }
  502. return res.CurrentIndex, res.Entries, nil
  503. }
  504. // ResetNavigationHistoryParams resets navigation history for the current
  505. // page.
  506. type ResetNavigationHistoryParams struct{}
  507. // ResetNavigationHistory resets navigation history for the current page.
  508. //
  509. // See: https://chromedevtools.github.io/devtools-protocol/tot/Page#method-resetNavigationHistory
  510. func ResetNavigationHistory() *ResetNavigationHistoryParams {
  511. return &ResetNavigationHistoryParams{}
  512. }
  513. // Do executes Page.resetNavigationHistory against the provided context.
  514. func (p *ResetNavigationHistoryParams) Do(ctx context.Context) (err error) {
  515. return cdp.Execute(ctx, CommandResetNavigationHistory, nil, nil)
  516. }
  517. // GetResourceContentParams returns content of the given resource.
  518. type GetResourceContentParams struct {
  519. FrameID cdp.FrameID `json:"frameId"` // Frame id to get resource for.
  520. URL string `json:"url"` // URL of the resource to get content for.
  521. }
  522. // GetResourceContent returns content of the given resource.
  523. //
  524. // See: https://chromedevtools.github.io/devtools-protocol/tot/Page#method-getResourceContent
  525. //
  526. // parameters:
  527. //
  528. // frameID - Frame id to get resource for.
  529. // url - URL of the resource to get content for.
  530. func GetResourceContent(frameID cdp.FrameID, url string) *GetResourceContentParams {
  531. return &GetResourceContentParams{
  532. FrameID: frameID,
  533. URL: url,
  534. }
  535. }
  536. // GetResourceContentReturns return values.
  537. type GetResourceContentReturns struct {
  538. Content string `json:"content,omitempty"` // Resource content.
  539. Base64encoded bool `json:"base64Encoded,omitempty"` // True, if content was served as base64.
  540. }
  541. // Do executes Page.getResourceContent against the provided context.
  542. //
  543. // returns:
  544. //
  545. // content - Resource content.
  546. func (p *GetResourceContentParams) Do(ctx context.Context) (content []byte, err error) {
  547. // execute
  548. var res GetResourceContentReturns
  549. err = cdp.Execute(ctx, CommandGetResourceContent, p, &res)
  550. if err != nil {
  551. return nil, err
  552. }
  553. // decode
  554. var dec []byte
  555. if res.Base64encoded {
  556. dec, err = base64.StdEncoding.DecodeString(res.Content)
  557. if err != nil {
  558. return nil, err
  559. }
  560. } else {
  561. dec = []byte(res.Content)
  562. }
  563. return dec, nil
  564. }
  565. // GetResourceTreeParams returns present frame / resource tree structure.
  566. type GetResourceTreeParams struct{}
  567. // GetResourceTree returns present frame / resource tree structure.
  568. //
  569. // See: https://chromedevtools.github.io/devtools-protocol/tot/Page#method-getResourceTree
  570. func GetResourceTree() *GetResourceTreeParams {
  571. return &GetResourceTreeParams{}
  572. }
  573. // GetResourceTreeReturns return values.
  574. type GetResourceTreeReturns struct {
  575. FrameTree *FrameResourceTree `json:"frameTree,omitempty"` // Present frame / resource tree structure.
  576. }
  577. // Do executes Page.getResourceTree against the provided context.
  578. //
  579. // returns:
  580. //
  581. // frameTree - Present frame / resource tree structure.
  582. func (p *GetResourceTreeParams) Do(ctx context.Context) (frameTree *FrameResourceTree, err error) {
  583. // execute
  584. var res GetResourceTreeReturns
  585. err = cdp.Execute(ctx, CommandGetResourceTree, nil, &res)
  586. if err != nil {
  587. return nil, err
  588. }
  589. return res.FrameTree, nil
  590. }
  591. // HandleJavaScriptDialogParams accepts or dismisses a JavaScript initiated
  592. // dialog (alert, confirm, prompt, or onbeforeunload).
  593. type HandleJavaScriptDialogParams struct {
  594. Accept bool `json:"accept"` // Whether to accept or dismiss the dialog.
  595. PromptText string `json:"promptText,omitempty"` // The text to enter into the dialog prompt before accepting. Used only if this is a prompt dialog.
  596. }
  597. // HandleJavaScriptDialog accepts or dismisses a JavaScript initiated dialog
  598. // (alert, confirm, prompt, or onbeforeunload).
  599. //
  600. // See: https://chromedevtools.github.io/devtools-protocol/tot/Page#method-handleJavaScriptDialog
  601. //
  602. // parameters:
  603. //
  604. // accept - Whether to accept or dismiss the dialog.
  605. func HandleJavaScriptDialog(accept bool) *HandleJavaScriptDialogParams {
  606. return &HandleJavaScriptDialogParams{
  607. Accept: accept,
  608. }
  609. }
  610. // WithPromptText the text to enter into the dialog prompt before accepting.
  611. // Used only if this is a prompt dialog.
  612. func (p HandleJavaScriptDialogParams) WithPromptText(promptText string) *HandleJavaScriptDialogParams {
  613. p.PromptText = promptText
  614. return &p
  615. }
  616. // Do executes Page.handleJavaScriptDialog against the provided context.
  617. func (p *HandleJavaScriptDialogParams) Do(ctx context.Context) (err error) {
  618. return cdp.Execute(ctx, CommandHandleJavaScriptDialog, p, nil)
  619. }
  620. // NavigateParams navigates current page to the given URL.
  621. type NavigateParams struct {
  622. URL string `json:"url"` // URL to navigate the page to.
  623. Referrer string `json:"referrer,omitempty"` // Referrer URL.
  624. TransitionType TransitionType `json:"transitionType,omitempty"` // Intended transition type.
  625. FrameID cdp.FrameID `json:"frameId,omitempty"` // Frame id to navigate, if not specified navigates the top frame.
  626. ReferrerPolicy ReferrerPolicy `json:"referrerPolicy,omitempty"` // Referrer-policy used for the navigation.
  627. }
  628. // Navigate navigates current page to the given URL.
  629. //
  630. // See: https://chromedevtools.github.io/devtools-protocol/tot/Page#method-navigate
  631. //
  632. // parameters:
  633. //
  634. // url - URL to navigate the page to.
  635. func Navigate(url string) *NavigateParams {
  636. return &NavigateParams{
  637. URL: url,
  638. }
  639. }
  640. // WithReferrer referrer URL.
  641. func (p NavigateParams) WithReferrer(referrer string) *NavigateParams {
  642. p.Referrer = referrer
  643. return &p
  644. }
  645. // WithTransitionType intended transition type.
  646. func (p NavigateParams) WithTransitionType(transitionType TransitionType) *NavigateParams {
  647. p.TransitionType = transitionType
  648. return &p
  649. }
  650. // WithFrameID frame id to navigate, if not specified navigates the top
  651. // frame.
  652. func (p NavigateParams) WithFrameID(frameID cdp.FrameID) *NavigateParams {
  653. p.FrameID = frameID
  654. return &p
  655. }
  656. // WithReferrerPolicy referrer-policy used for the navigation.
  657. func (p NavigateParams) WithReferrerPolicy(referrerPolicy ReferrerPolicy) *NavigateParams {
  658. p.ReferrerPolicy = referrerPolicy
  659. return &p
  660. }
  661. // NavigateReturns return values.
  662. type NavigateReturns struct {
  663. FrameID cdp.FrameID `json:"frameId,omitempty"` // Frame id that has navigated (or failed to navigate)
  664. LoaderID cdp.LoaderID `json:"loaderId,omitempty"` // Loader identifier. This is omitted in case of same-document navigation, as the previously committed loaderId would not change.
  665. ErrorText string `json:"errorText,omitempty"` // User friendly error message, present if and only if navigation has failed.
  666. }
  667. // Do executes Page.navigate against the provided context.
  668. //
  669. // returns:
  670. //
  671. // frameID - Frame id that has navigated (or failed to navigate)
  672. // loaderID - Loader identifier. This is omitted in case of same-document navigation, as the previously committed loaderId would not change.
  673. // errorText - User friendly error message, present if and only if navigation has failed.
  674. func (p *NavigateParams) Do(ctx context.Context) (frameID cdp.FrameID, loaderID cdp.LoaderID, errorText string, err error) {
  675. // execute
  676. var res NavigateReturns
  677. err = cdp.Execute(ctx, CommandNavigate, p, &res)
  678. if err != nil {
  679. return "", "", "", err
  680. }
  681. return res.FrameID, res.LoaderID, res.ErrorText, nil
  682. }
  683. // NavigateToHistoryEntryParams navigates current page to the given history
  684. // entry.
  685. type NavigateToHistoryEntryParams struct {
  686. EntryID int64 `json:"entryId"` // Unique id of the entry to navigate to.
  687. }
  688. // NavigateToHistoryEntry navigates current page to the given history entry.
  689. //
  690. // See: https://chromedevtools.github.io/devtools-protocol/tot/Page#method-navigateToHistoryEntry
  691. //
  692. // parameters:
  693. //
  694. // entryID - Unique id of the entry to navigate to.
  695. func NavigateToHistoryEntry(entryID int64) *NavigateToHistoryEntryParams {
  696. return &NavigateToHistoryEntryParams{
  697. EntryID: entryID,
  698. }
  699. }
  700. // Do executes Page.navigateToHistoryEntry against the provided context.
  701. func (p *NavigateToHistoryEntryParams) Do(ctx context.Context) (err error) {
  702. return cdp.Execute(ctx, CommandNavigateToHistoryEntry, p, nil)
  703. }
  704. // PrintToPDFParams print page as PDF.
  705. type PrintToPDFParams struct {
  706. Landscape bool `json:"landscape,omitempty"` // Paper orientation. Defaults to false.
  707. DisplayHeaderFooter bool `json:"displayHeaderFooter,omitempty"` // Display header and footer. Defaults to false.
  708. PrintBackground bool `json:"printBackground,omitempty"` // Print background graphics. Defaults to false.
  709. Scale float64 `json:"scale,omitempty"` // Scale of the webpage rendering. Defaults to 1.
  710. PaperWidth float64 `json:"paperWidth,omitempty"` // Paper width in inches. Defaults to 8.5 inches.
  711. PaperHeight float64 `json:"paperHeight,omitempty"` // Paper height in inches. Defaults to 11 inches.
  712. MarginTop float64 `json:"marginTop"` // Top margin in inches. Defaults to 1cm (~0.4 inches).
  713. MarginBottom float64 `json:"marginBottom"` // Bottom margin in inches. Defaults to 1cm (~0.4 inches).
  714. MarginLeft float64 `json:"marginLeft"` // Left margin in inches. Defaults to 1cm (~0.4 inches).
  715. MarginRight float64 `json:"marginRight"` // Right margin in inches. Defaults to 1cm (~0.4 inches).
  716. PageRanges string `json:"pageRanges,omitempty"` // Paper ranges to print, one based, e.g., '1-5, 8, 11-13'. Pages are printed in the document order, not in the order specified, and no more than once. Defaults to empty string, which implies the entire document is printed. The page numbers are quietly capped to actual page count of the document, and ranges beyond the end of the document are ignored. If this results in no pages to print, an error is reported. It is an error to specify a range with start greater than end.
  717. HeaderTemplate string `json:"headerTemplate,omitempty"` // HTML template for the print header. Should be valid HTML markup with following classes used to inject printing values into them: - date: formatted print date - title: document title - url: document location - pageNumber: current page number - totalPages: total pages in the document For example, <span class=title></span> would generate span containing the title.
  718. FooterTemplate string `json:"footerTemplate,omitempty"` // HTML template for the print footer. Should use the same format as the headerTemplate.
  719. PreferCSSPageSize bool `json:"preferCSSPageSize,omitempty"` // Whether or not to prefer page size as defined by css. Defaults to false, in which case the content will be scaled to fit the paper size.
  720. TransferMode PrintToPDFTransferMode `json:"transferMode,omitempty"` // return as stream
  721. GenerateTaggedPDF bool `json:"generateTaggedPDF,omitempty"` // Whether or not to generate tagged (accessible) PDF. Defaults to embedder choice.
  722. GenerateDocumentOutline bool `json:"generateDocumentOutline,omitempty"` // Whether or not to embed the document outline into the PDF.
  723. }
  724. // PrintToPDF print page as PDF.
  725. //
  726. // See: https://chromedevtools.github.io/devtools-protocol/tot/Page#method-printToPDF
  727. //
  728. // parameters:
  729. func PrintToPDF() *PrintToPDFParams {
  730. return &PrintToPDFParams{}
  731. }
  732. // WithLandscape paper orientation. Defaults to false.
  733. func (p PrintToPDFParams) WithLandscape(landscape bool) *PrintToPDFParams {
  734. p.Landscape = landscape
  735. return &p
  736. }
  737. // WithDisplayHeaderFooter display header and footer. Defaults to false.
  738. func (p PrintToPDFParams) WithDisplayHeaderFooter(displayHeaderFooter bool) *PrintToPDFParams {
  739. p.DisplayHeaderFooter = displayHeaderFooter
  740. return &p
  741. }
  742. // WithPrintBackground print background graphics. Defaults to false.
  743. func (p PrintToPDFParams) WithPrintBackground(printBackground bool) *PrintToPDFParams {
  744. p.PrintBackground = printBackground
  745. return &p
  746. }
  747. // WithScale scale of the webpage rendering. Defaults to 1.
  748. func (p PrintToPDFParams) WithScale(scale float64) *PrintToPDFParams {
  749. p.Scale = scale
  750. return &p
  751. }
  752. // WithPaperWidth paper width in inches. Defaults to 8.5 inches.
  753. func (p PrintToPDFParams) WithPaperWidth(paperWidth float64) *PrintToPDFParams {
  754. p.PaperWidth = paperWidth
  755. return &p
  756. }
  757. // WithPaperHeight paper height in inches. Defaults to 11 inches.
  758. func (p PrintToPDFParams) WithPaperHeight(paperHeight float64) *PrintToPDFParams {
  759. p.PaperHeight = paperHeight
  760. return &p
  761. }
  762. // WithMarginTop top margin in inches. Defaults to 1cm (~0.4 inches).
  763. func (p PrintToPDFParams) WithMarginTop(marginTop float64) *PrintToPDFParams {
  764. p.MarginTop = marginTop
  765. return &p
  766. }
  767. // WithMarginBottom bottom margin in inches. Defaults to 1cm (~0.4 inches).
  768. func (p PrintToPDFParams) WithMarginBottom(marginBottom float64) *PrintToPDFParams {
  769. p.MarginBottom = marginBottom
  770. return &p
  771. }
  772. // WithMarginLeft left margin in inches. Defaults to 1cm (~0.4 inches).
  773. func (p PrintToPDFParams) WithMarginLeft(marginLeft float64) *PrintToPDFParams {
  774. p.MarginLeft = marginLeft
  775. return &p
  776. }
  777. // WithMarginRight right margin in inches. Defaults to 1cm (~0.4 inches).
  778. func (p PrintToPDFParams) WithMarginRight(marginRight float64) *PrintToPDFParams {
  779. p.MarginRight = marginRight
  780. return &p
  781. }
  782. // WithPageRanges paper ranges to print, one based, e.g., '1-5, 8, 11-13'.
  783. // Pages are printed in the document order, not in the order specified, and no
  784. // more than once. Defaults to empty string, which implies the entire document
  785. // is printed. The page numbers are quietly capped to actual page count of the
  786. // document, and ranges beyond the end of the document are ignored. If this
  787. // results in no pages to print, an error is reported. It is an error to specify
  788. // a range with start greater than end.
  789. func (p PrintToPDFParams) WithPageRanges(pageRanges string) *PrintToPDFParams {
  790. p.PageRanges = pageRanges
  791. return &p
  792. }
  793. // WithHeaderTemplate HTML template for the print header. Should be valid
  794. // HTML markup with following classes used to inject printing values into them:
  795. // - date: formatted print date - title: document title - url: document location
  796. // - pageNumber: current page number - totalPages: total pages in the document
  797. // For example, <span class=title></span> would generate span containing the
  798. // title.
  799. func (p PrintToPDFParams) WithHeaderTemplate(headerTemplate string) *PrintToPDFParams {
  800. p.HeaderTemplate = headerTemplate
  801. return &p
  802. }
  803. // WithFooterTemplate HTML template for the print footer. Should use the same
  804. // format as the headerTemplate.
  805. func (p PrintToPDFParams) WithFooterTemplate(footerTemplate string) *PrintToPDFParams {
  806. p.FooterTemplate = footerTemplate
  807. return &p
  808. }
  809. // WithPreferCSSPageSize whether or not to prefer page size as defined by
  810. // css. Defaults to false, in which case the content will be scaled to fit the
  811. // paper size.
  812. func (p PrintToPDFParams) WithPreferCSSPageSize(preferCSSPageSize bool) *PrintToPDFParams {
  813. p.PreferCSSPageSize = preferCSSPageSize
  814. return &p
  815. }
  816. // WithTransferMode return as stream.
  817. func (p PrintToPDFParams) WithTransferMode(transferMode PrintToPDFTransferMode) *PrintToPDFParams {
  818. p.TransferMode = transferMode
  819. return &p
  820. }
  821. // WithGenerateTaggedPDF whether or not to generate tagged (accessible) PDF.
  822. // Defaults to embedder choice.
  823. func (p PrintToPDFParams) WithGenerateTaggedPDF(generateTaggedPDF bool) *PrintToPDFParams {
  824. p.GenerateTaggedPDF = generateTaggedPDF
  825. return &p
  826. }
  827. // WithGenerateDocumentOutline whether or not to embed the document outline
  828. // into the PDF.
  829. func (p PrintToPDFParams) WithGenerateDocumentOutline(generateDocumentOutline bool) *PrintToPDFParams {
  830. p.GenerateDocumentOutline = generateDocumentOutline
  831. return &p
  832. }
  833. // PrintToPDFReturns return values.
  834. type PrintToPDFReturns struct {
  835. Data string `json:"data,omitempty"` // Base64-encoded pdf data. Empty if |returnAsStream| is specified.
  836. Stream io.StreamHandle `json:"stream,omitempty"` // A handle of the stream that holds resulting PDF data.
  837. }
  838. // Do executes Page.printToPDF against the provided context.
  839. //
  840. // returns:
  841. //
  842. // data - Base64-encoded pdf data. Empty if |returnAsStream| is specified.
  843. // stream - A handle of the stream that holds resulting PDF data.
  844. func (p *PrintToPDFParams) Do(ctx context.Context) (data []byte, stream io.StreamHandle, err error) {
  845. // execute
  846. var res PrintToPDFReturns
  847. err = cdp.Execute(ctx, CommandPrintToPDF, p, &res)
  848. if err != nil {
  849. return nil, "", err
  850. }
  851. // decode
  852. var dec []byte
  853. dec, err = base64.StdEncoding.DecodeString(res.Data)
  854. if err != nil {
  855. return nil, "", err
  856. }
  857. return dec, res.Stream, nil
  858. }
  859. // ReloadParams reloads given page optionally ignoring the cache.
  860. type ReloadParams struct {
  861. IgnoreCache bool `json:"ignoreCache,omitempty"` // If true, browser cache is ignored (as if the user pressed Shift+refresh).
  862. ScriptToEvaluateOnLoad string `json:"scriptToEvaluateOnLoad,omitempty"` // If set, the script will be injected into all frames of the inspected page after reload. Argument will be ignored if reloading dataURL origin.
  863. }
  864. // Reload reloads given page optionally ignoring the cache.
  865. //
  866. // See: https://chromedevtools.github.io/devtools-protocol/tot/Page#method-reload
  867. //
  868. // parameters:
  869. func Reload() *ReloadParams {
  870. return &ReloadParams{}
  871. }
  872. // WithIgnoreCache if true, browser cache is ignored (as if the user pressed
  873. // Shift+refresh).
  874. func (p ReloadParams) WithIgnoreCache(ignoreCache bool) *ReloadParams {
  875. p.IgnoreCache = ignoreCache
  876. return &p
  877. }
  878. // WithScriptToEvaluateOnLoad if set, the script will be injected into all
  879. // frames of the inspected page after reload. Argument will be ignored if
  880. // reloading dataURL origin.
  881. func (p ReloadParams) WithScriptToEvaluateOnLoad(scriptToEvaluateOnLoad string) *ReloadParams {
  882. p.ScriptToEvaluateOnLoad = scriptToEvaluateOnLoad
  883. return &p
  884. }
  885. // Do executes Page.reload against the provided context.
  886. func (p *ReloadParams) Do(ctx context.Context) (err error) {
  887. return cdp.Execute(ctx, CommandReload, p, nil)
  888. }
  889. // RemoveScriptToEvaluateOnNewDocumentParams removes given script from the
  890. // list.
  891. type RemoveScriptToEvaluateOnNewDocumentParams struct {
  892. Identifier ScriptIdentifier `json:"identifier"`
  893. }
  894. // RemoveScriptToEvaluateOnNewDocument removes given script from the list.
  895. //
  896. // See: https://chromedevtools.github.io/devtools-protocol/tot/Page#method-removeScriptToEvaluateOnNewDocument
  897. //
  898. // parameters:
  899. //
  900. // identifier
  901. func RemoveScriptToEvaluateOnNewDocument(identifier ScriptIdentifier) *RemoveScriptToEvaluateOnNewDocumentParams {
  902. return &RemoveScriptToEvaluateOnNewDocumentParams{
  903. Identifier: identifier,
  904. }
  905. }
  906. // Do executes Page.removeScriptToEvaluateOnNewDocument against the provided context.
  907. func (p *RemoveScriptToEvaluateOnNewDocumentParams) Do(ctx context.Context) (err error) {
  908. return cdp.Execute(ctx, CommandRemoveScriptToEvaluateOnNewDocument, p, nil)
  909. }
  910. // ScreencastFrameAckParams acknowledges that a screencast frame has been
  911. // received by the frontend.
  912. type ScreencastFrameAckParams struct {
  913. SessionID int64 `json:"sessionId"` // Frame number.
  914. }
  915. // ScreencastFrameAck acknowledges that a screencast frame has been received
  916. // by the frontend.
  917. //
  918. // See: https://chromedevtools.github.io/devtools-protocol/tot/Page#method-screencastFrameAck
  919. //
  920. // parameters:
  921. //
  922. // sessionID - Frame number.
  923. func ScreencastFrameAck(sessionID int64) *ScreencastFrameAckParams {
  924. return &ScreencastFrameAckParams{
  925. SessionID: sessionID,
  926. }
  927. }
  928. // Do executes Page.screencastFrameAck against the provided context.
  929. func (p *ScreencastFrameAckParams) Do(ctx context.Context) (err error) {
  930. return cdp.Execute(ctx, CommandScreencastFrameAck, p, nil)
  931. }
  932. // SearchInResourceParams searches for given string in resource content.
  933. type SearchInResourceParams struct {
  934. FrameID cdp.FrameID `json:"frameId"` // Frame id for resource to search in.
  935. URL string `json:"url"` // URL of the resource to search in.
  936. Query string `json:"query"` // String to search for.
  937. CaseSensitive bool `json:"caseSensitive,omitempty"` // If true, search is case sensitive.
  938. IsRegex bool `json:"isRegex,omitempty"` // If true, treats string parameter as regex.
  939. }
  940. // SearchInResource searches for given string in resource content.
  941. //
  942. // See: https://chromedevtools.github.io/devtools-protocol/tot/Page#method-searchInResource
  943. //
  944. // parameters:
  945. //
  946. // frameID - Frame id for resource to search in.
  947. // url - URL of the resource to search in.
  948. // query - String to search for.
  949. func SearchInResource(frameID cdp.FrameID, url string, query string) *SearchInResourceParams {
  950. return &SearchInResourceParams{
  951. FrameID: frameID,
  952. URL: url,
  953. Query: query,
  954. }
  955. }
  956. // WithCaseSensitive if true, search is case sensitive.
  957. func (p SearchInResourceParams) WithCaseSensitive(caseSensitive bool) *SearchInResourceParams {
  958. p.CaseSensitive = caseSensitive
  959. return &p
  960. }
  961. // WithIsRegex if true, treats string parameter as regex.
  962. func (p SearchInResourceParams) WithIsRegex(isRegex bool) *SearchInResourceParams {
  963. p.IsRegex = isRegex
  964. return &p
  965. }
  966. // SearchInResourceReturns return values.
  967. type SearchInResourceReturns struct {
  968. Result []*debugger.SearchMatch `json:"result,omitempty"` // List of search matches.
  969. }
  970. // Do executes Page.searchInResource against the provided context.
  971. //
  972. // returns:
  973. //
  974. // result - List of search matches.
  975. func (p *SearchInResourceParams) Do(ctx context.Context) (result []*debugger.SearchMatch, err error) {
  976. // execute
  977. var res SearchInResourceReturns
  978. err = cdp.Execute(ctx, CommandSearchInResource, p, &res)
  979. if err != nil {
  980. return nil, err
  981. }
  982. return res.Result, nil
  983. }
  984. // SetAdBlockingEnabledParams enable Chrome's experimental ad filter on all
  985. // sites.
  986. type SetAdBlockingEnabledParams struct {
  987. Enabled bool `json:"enabled"` // Whether to block ads.
  988. }
  989. // SetAdBlockingEnabled enable Chrome's experimental ad filter on all sites.
  990. //
  991. // See: https://chromedevtools.github.io/devtools-protocol/tot/Page#method-setAdBlockingEnabled
  992. //
  993. // parameters:
  994. //
  995. // enabled - Whether to block ads.
  996. func SetAdBlockingEnabled(enabled bool) *SetAdBlockingEnabledParams {
  997. return &SetAdBlockingEnabledParams{
  998. Enabled: enabled,
  999. }
  1000. }
  1001. // Do executes Page.setAdBlockingEnabled against the provided context.
  1002. func (p *SetAdBlockingEnabledParams) Do(ctx context.Context) (err error) {
  1003. return cdp.Execute(ctx, CommandSetAdBlockingEnabled, p, nil)
  1004. }
  1005. // SetBypassCSPParams enable page Content Security Policy by-passing.
  1006. type SetBypassCSPParams struct {
  1007. Enabled bool `json:"enabled"` // Whether to bypass page CSP.
  1008. }
  1009. // SetBypassCSP enable page Content Security Policy by-passing.
  1010. //
  1011. // See: https://chromedevtools.github.io/devtools-protocol/tot/Page#method-setBypassCSP
  1012. //
  1013. // parameters:
  1014. //
  1015. // enabled - Whether to bypass page CSP.
  1016. func SetBypassCSP(enabled bool) *SetBypassCSPParams {
  1017. return &SetBypassCSPParams{
  1018. Enabled: enabled,
  1019. }
  1020. }
  1021. // Do executes Page.setBypassCSP against the provided context.
  1022. func (p *SetBypassCSPParams) Do(ctx context.Context) (err error) {
  1023. return cdp.Execute(ctx, CommandSetBypassCSP, p, nil)
  1024. }
  1025. // GetPermissionsPolicyStateParams get Permissions Policy state on given
  1026. // frame.
  1027. type GetPermissionsPolicyStateParams struct {
  1028. FrameID cdp.FrameID `json:"frameId"`
  1029. }
  1030. // GetPermissionsPolicyState get Permissions Policy state on given frame.
  1031. //
  1032. // See: https://chromedevtools.github.io/devtools-protocol/tot/Page#method-getPermissionsPolicyState
  1033. //
  1034. // parameters:
  1035. //
  1036. // frameID
  1037. func GetPermissionsPolicyState(frameID cdp.FrameID) *GetPermissionsPolicyStateParams {
  1038. return &GetPermissionsPolicyStateParams{
  1039. FrameID: frameID,
  1040. }
  1041. }
  1042. // GetPermissionsPolicyStateReturns return values.
  1043. type GetPermissionsPolicyStateReturns struct {
  1044. States []*PermissionsPolicyFeatureState `json:"states,omitempty"`
  1045. }
  1046. // Do executes Page.getPermissionsPolicyState against the provided context.
  1047. //
  1048. // returns:
  1049. //
  1050. // states
  1051. func (p *GetPermissionsPolicyStateParams) Do(ctx context.Context) (states []*PermissionsPolicyFeatureState, err error) {
  1052. // execute
  1053. var res GetPermissionsPolicyStateReturns
  1054. err = cdp.Execute(ctx, CommandGetPermissionsPolicyState, p, &res)
  1055. if err != nil {
  1056. return nil, err
  1057. }
  1058. return res.States, nil
  1059. }
  1060. // GetOriginTrialsParams get Origin Trials on given frame.
  1061. type GetOriginTrialsParams struct {
  1062. FrameID cdp.FrameID `json:"frameId"`
  1063. }
  1064. // GetOriginTrials get Origin Trials on given frame.
  1065. //
  1066. // See: https://chromedevtools.github.io/devtools-protocol/tot/Page#method-getOriginTrials
  1067. //
  1068. // parameters:
  1069. //
  1070. // frameID
  1071. func GetOriginTrials(frameID cdp.FrameID) *GetOriginTrialsParams {
  1072. return &GetOriginTrialsParams{
  1073. FrameID: frameID,
  1074. }
  1075. }
  1076. // GetOriginTrialsReturns return values.
  1077. type GetOriginTrialsReturns struct {
  1078. OriginTrials []*cdp.OriginTrial `json:"originTrials,omitempty"`
  1079. }
  1080. // Do executes Page.getOriginTrials against the provided context.
  1081. //
  1082. // returns:
  1083. //
  1084. // originTrials
  1085. func (p *GetOriginTrialsParams) Do(ctx context.Context) (originTrials []*cdp.OriginTrial, err error) {
  1086. // execute
  1087. var res GetOriginTrialsReturns
  1088. err = cdp.Execute(ctx, CommandGetOriginTrials, p, &res)
  1089. if err != nil {
  1090. return nil, err
  1091. }
  1092. return res.OriginTrials, nil
  1093. }
  1094. // SetFontFamiliesParams set generic font families.
  1095. type SetFontFamiliesParams struct {
  1096. FontFamilies *FontFamilies `json:"fontFamilies"` // Specifies font families to set. If a font family is not specified, it won't be changed.
  1097. ForScripts []*ScriptFontFamilies `json:"forScripts,omitempty"` // Specifies font families to set for individual scripts.
  1098. }
  1099. // SetFontFamilies set generic font families.
  1100. //
  1101. // See: https://chromedevtools.github.io/devtools-protocol/tot/Page#method-setFontFamilies
  1102. //
  1103. // parameters:
  1104. //
  1105. // fontFamilies - Specifies font families to set. If a font family is not specified, it won't be changed.
  1106. func SetFontFamilies(fontFamilies *FontFamilies) *SetFontFamiliesParams {
  1107. return &SetFontFamiliesParams{
  1108. FontFamilies: fontFamilies,
  1109. }
  1110. }
  1111. // WithForScripts specifies font families to set for individual scripts.
  1112. func (p SetFontFamiliesParams) WithForScripts(forScripts []*ScriptFontFamilies) *SetFontFamiliesParams {
  1113. p.ForScripts = forScripts
  1114. return &p
  1115. }
  1116. // Do executes Page.setFontFamilies against the provided context.
  1117. func (p *SetFontFamiliesParams) Do(ctx context.Context) (err error) {
  1118. return cdp.Execute(ctx, CommandSetFontFamilies, p, nil)
  1119. }
  1120. // SetFontSizesParams set default font sizes.
  1121. type SetFontSizesParams struct {
  1122. FontSizes *FontSizes `json:"fontSizes"` // Specifies font sizes to set. If a font size is not specified, it won't be changed.
  1123. }
  1124. // SetFontSizes set default font sizes.
  1125. //
  1126. // See: https://chromedevtools.github.io/devtools-protocol/tot/Page#method-setFontSizes
  1127. //
  1128. // parameters:
  1129. //
  1130. // fontSizes - Specifies font sizes to set. If a font size is not specified, it won't be changed.
  1131. func SetFontSizes(fontSizes *FontSizes) *SetFontSizesParams {
  1132. return &SetFontSizesParams{
  1133. FontSizes: fontSizes,
  1134. }
  1135. }
  1136. // Do executes Page.setFontSizes against the provided context.
  1137. func (p *SetFontSizesParams) Do(ctx context.Context) (err error) {
  1138. return cdp.Execute(ctx, CommandSetFontSizes, p, nil)
  1139. }
  1140. // SetDocumentContentParams sets given markup as the document's HTML.
  1141. type SetDocumentContentParams struct {
  1142. FrameID cdp.FrameID `json:"frameId"` // Frame id to set HTML for.
  1143. HTML string `json:"html"` // HTML content to set.
  1144. }
  1145. // SetDocumentContent sets given markup as the document's HTML.
  1146. //
  1147. // See: https://chromedevtools.github.io/devtools-protocol/tot/Page#method-setDocumentContent
  1148. //
  1149. // parameters:
  1150. //
  1151. // frameID - Frame id to set HTML for.
  1152. // html - HTML content to set.
  1153. func SetDocumentContent(frameID cdp.FrameID, html string) *SetDocumentContentParams {
  1154. return &SetDocumentContentParams{
  1155. FrameID: frameID,
  1156. HTML: html,
  1157. }
  1158. }
  1159. // Do executes Page.setDocumentContent against the provided context.
  1160. func (p *SetDocumentContentParams) Do(ctx context.Context) (err error) {
  1161. return cdp.Execute(ctx, CommandSetDocumentContent, p, nil)
  1162. }
  1163. // SetLifecycleEventsEnabledParams controls whether page will emit lifecycle
  1164. // events.
  1165. type SetLifecycleEventsEnabledParams struct {
  1166. Enabled bool `json:"enabled"` // If true, starts emitting lifecycle events.
  1167. }
  1168. // SetLifecycleEventsEnabled controls whether page will emit lifecycle
  1169. // events.
  1170. //
  1171. // See: https://chromedevtools.github.io/devtools-protocol/tot/Page#method-setLifecycleEventsEnabled
  1172. //
  1173. // parameters:
  1174. //
  1175. // enabled - If true, starts emitting lifecycle events.
  1176. func SetLifecycleEventsEnabled(enabled bool) *SetLifecycleEventsEnabledParams {
  1177. return &SetLifecycleEventsEnabledParams{
  1178. Enabled: enabled,
  1179. }
  1180. }
  1181. // Do executes Page.setLifecycleEventsEnabled against the provided context.
  1182. func (p *SetLifecycleEventsEnabledParams) Do(ctx context.Context) (err error) {
  1183. return cdp.Execute(ctx, CommandSetLifecycleEventsEnabled, p, nil)
  1184. }
  1185. // StartScreencastParams starts sending each frame using the screencastFrame
  1186. // event.
  1187. type StartScreencastParams struct {
  1188. Format ScreencastFormat `json:"format,omitempty"` // Image compression format.
  1189. Quality int64 `json:"quality,omitempty"` // Compression quality from range [0..100].
  1190. MaxWidth int64 `json:"maxWidth,omitempty"` // Maximum screenshot width.
  1191. MaxHeight int64 `json:"maxHeight,omitempty"` // Maximum screenshot height.
  1192. EveryNthFrame int64 `json:"everyNthFrame,omitempty"` // Send every n-th frame.
  1193. }
  1194. // StartScreencast starts sending each frame using the screencastFrame event.
  1195. //
  1196. // See: https://chromedevtools.github.io/devtools-protocol/tot/Page#method-startScreencast
  1197. //
  1198. // parameters:
  1199. func StartScreencast() *StartScreencastParams {
  1200. return &StartScreencastParams{}
  1201. }
  1202. // WithFormat image compression format.
  1203. func (p StartScreencastParams) WithFormat(format ScreencastFormat) *StartScreencastParams {
  1204. p.Format = format
  1205. return &p
  1206. }
  1207. // WithQuality compression quality from range [0..100].
  1208. func (p StartScreencastParams) WithQuality(quality int64) *StartScreencastParams {
  1209. p.Quality = quality
  1210. return &p
  1211. }
  1212. // WithMaxWidth maximum screenshot width.
  1213. func (p StartScreencastParams) WithMaxWidth(maxWidth int64) *StartScreencastParams {
  1214. p.MaxWidth = maxWidth
  1215. return &p
  1216. }
  1217. // WithMaxHeight maximum screenshot height.
  1218. func (p StartScreencastParams) WithMaxHeight(maxHeight int64) *StartScreencastParams {
  1219. p.MaxHeight = maxHeight
  1220. return &p
  1221. }
  1222. // WithEveryNthFrame send every n-th frame.
  1223. func (p StartScreencastParams) WithEveryNthFrame(everyNthFrame int64) *StartScreencastParams {
  1224. p.EveryNthFrame = everyNthFrame
  1225. return &p
  1226. }
  1227. // Do executes Page.startScreencast against the provided context.
  1228. func (p *StartScreencastParams) Do(ctx context.Context) (err error) {
  1229. return cdp.Execute(ctx, CommandStartScreencast, p, nil)
  1230. }
  1231. // StopLoadingParams force the page stop all navigations and pending resource
  1232. // fetches.
  1233. type StopLoadingParams struct{}
  1234. // StopLoading force the page stop all navigations and pending resource
  1235. // fetches.
  1236. //
  1237. // See: https://chromedevtools.github.io/devtools-protocol/tot/Page#method-stopLoading
  1238. func StopLoading() *StopLoadingParams {
  1239. return &StopLoadingParams{}
  1240. }
  1241. // Do executes Page.stopLoading against the provided context.
  1242. func (p *StopLoadingParams) Do(ctx context.Context) (err error) {
  1243. return cdp.Execute(ctx, CommandStopLoading, nil, nil)
  1244. }
  1245. // CrashParams crashes renderer on the IO thread, generates minidumps.
  1246. type CrashParams struct{}
  1247. // Crash crashes renderer on the IO thread, generates minidumps.
  1248. //
  1249. // See: https://chromedevtools.github.io/devtools-protocol/tot/Page#method-crash
  1250. func Crash() *CrashParams {
  1251. return &CrashParams{}
  1252. }
  1253. // Do executes Page.crash against the provided context.
  1254. func (p *CrashParams) Do(ctx context.Context) (err error) {
  1255. return cdp.Execute(ctx, CommandCrash, nil, nil)
  1256. }
  1257. // CloseParams tries to close page, running its beforeunload hooks, if any.
  1258. type CloseParams struct{}
  1259. // Close tries to close page, running its beforeunload hooks, if any.
  1260. //
  1261. // See: https://chromedevtools.github.io/devtools-protocol/tot/Page#method-close
  1262. func Close() *CloseParams {
  1263. return &CloseParams{}
  1264. }
  1265. // Do executes Page.close against the provided context.
  1266. func (p *CloseParams) Do(ctx context.Context) (err error) {
  1267. return cdp.Execute(ctx, CommandClose, nil, nil)
  1268. }
  1269. // SetWebLifecycleStateParams tries to update the web lifecycle state of the
  1270. // page. It will transition the page to the given state according to:
  1271. // https://github.com/WICG/web-lifecycle/.
  1272. type SetWebLifecycleStateParams struct {
  1273. State SetWebLifecycleStateState `json:"state"` // Target lifecycle state
  1274. }
  1275. // SetWebLifecycleState tries to update the web lifecycle state of the page.
  1276. // It will transition the page to the given state according to:
  1277. // https://github.com/WICG/web-lifecycle/.
  1278. //
  1279. // See: https://chromedevtools.github.io/devtools-protocol/tot/Page#method-setWebLifecycleState
  1280. //
  1281. // parameters:
  1282. //
  1283. // state - Target lifecycle state
  1284. func SetWebLifecycleState(state SetWebLifecycleStateState) *SetWebLifecycleStateParams {
  1285. return &SetWebLifecycleStateParams{
  1286. State: state,
  1287. }
  1288. }
  1289. // Do executes Page.setWebLifecycleState against the provided context.
  1290. func (p *SetWebLifecycleStateParams) Do(ctx context.Context) (err error) {
  1291. return cdp.Execute(ctx, CommandSetWebLifecycleState, p, nil)
  1292. }
  1293. // StopScreencastParams stops sending each frame in the screencastFrame.
  1294. type StopScreencastParams struct{}
  1295. // StopScreencast stops sending each frame in the screencastFrame.
  1296. //
  1297. // See: https://chromedevtools.github.io/devtools-protocol/tot/Page#method-stopScreencast
  1298. func StopScreencast() *StopScreencastParams {
  1299. return &StopScreencastParams{}
  1300. }
  1301. // Do executes Page.stopScreencast against the provided context.
  1302. func (p *StopScreencastParams) Do(ctx context.Context) (err error) {
  1303. return cdp.Execute(ctx, CommandStopScreencast, nil, nil)
  1304. }
  1305. // ProduceCompilationCacheParams requests backend to produce compilation
  1306. // cache for the specified scripts. scripts are appended to the list of scripts
  1307. // for which the cache would be produced. The list may be reset during page
  1308. // navigation. When script with a matching URL is encountered, the cache is
  1309. // optionally produced upon backend discretion, based on internal heuristics.
  1310. // See also: Page.compilationCacheProduced.
  1311. type ProduceCompilationCacheParams struct {
  1312. Scripts []*CompilationCacheParams `json:"scripts"`
  1313. }
  1314. // ProduceCompilationCache requests backend to produce compilation cache for
  1315. // the specified scripts. scripts are appended to the list of scripts for which
  1316. // the cache would be produced. The list may be reset during page navigation.
  1317. // When script with a matching URL is encountered, the cache is optionally
  1318. // produced upon backend discretion, based on internal heuristics. See also:
  1319. // Page.compilationCacheProduced.
  1320. //
  1321. // See: https://chromedevtools.github.io/devtools-protocol/tot/Page#method-produceCompilationCache
  1322. //
  1323. // parameters:
  1324. //
  1325. // scripts
  1326. func ProduceCompilationCache(scripts []*CompilationCacheParams) *ProduceCompilationCacheParams {
  1327. return &ProduceCompilationCacheParams{
  1328. Scripts: scripts,
  1329. }
  1330. }
  1331. // Do executes Page.produceCompilationCache against the provided context.
  1332. func (p *ProduceCompilationCacheParams) Do(ctx context.Context) (err error) {
  1333. return cdp.Execute(ctx, CommandProduceCompilationCache, p, nil)
  1334. }
  1335. // AddCompilationCacheParams seeds compilation cache for given url.
  1336. // Compilation cache does not survive cross-process navigation.
  1337. type AddCompilationCacheParams struct {
  1338. URL string `json:"url"`
  1339. Data string `json:"data"` // Base64-encoded data
  1340. }
  1341. // AddCompilationCache seeds compilation cache for given url. Compilation
  1342. // cache does not survive cross-process navigation.
  1343. //
  1344. // See: https://chromedevtools.github.io/devtools-protocol/tot/Page#method-addCompilationCache
  1345. //
  1346. // parameters:
  1347. //
  1348. // url
  1349. // data - Base64-encoded data
  1350. func AddCompilationCache(url string, data string) *AddCompilationCacheParams {
  1351. return &AddCompilationCacheParams{
  1352. URL: url,
  1353. Data: data,
  1354. }
  1355. }
  1356. // Do executes Page.addCompilationCache against the provided context.
  1357. func (p *AddCompilationCacheParams) Do(ctx context.Context) (err error) {
  1358. return cdp.Execute(ctx, CommandAddCompilationCache, p, nil)
  1359. }
  1360. // ClearCompilationCacheParams clears seeded compilation cache.
  1361. type ClearCompilationCacheParams struct{}
  1362. // ClearCompilationCache clears seeded compilation cache.
  1363. //
  1364. // See: https://chromedevtools.github.io/devtools-protocol/tot/Page#method-clearCompilationCache
  1365. func ClearCompilationCache() *ClearCompilationCacheParams {
  1366. return &ClearCompilationCacheParams{}
  1367. }
  1368. // Do executes Page.clearCompilationCache against the provided context.
  1369. func (p *ClearCompilationCacheParams) Do(ctx context.Context) (err error) {
  1370. return cdp.Execute(ctx, CommandClearCompilationCache, nil, nil)
  1371. }
  1372. // SetSPCTransactionModeParams sets the Secure Payment Confirmation
  1373. // transaction mode.
  1374. // https://w3c.github.io/secure-payment-confirmation/#sctn-automation-set-spc-transaction-mode.
  1375. type SetSPCTransactionModeParams struct {
  1376. Mode AutoResponseMode `json:"mode"`
  1377. }
  1378. // SetSPCTransactionMode sets the Secure Payment Confirmation transaction
  1379. // mode.
  1380. // https://w3c.github.io/secure-payment-confirmation/#sctn-automation-set-spc-transaction-mode.
  1381. //
  1382. // See: https://chromedevtools.github.io/devtools-protocol/tot/Page#method-setSPCTransactionMode
  1383. //
  1384. // parameters:
  1385. //
  1386. // mode
  1387. func SetSPCTransactionMode(mode AutoResponseMode) *SetSPCTransactionModeParams {
  1388. return &SetSPCTransactionModeParams{
  1389. Mode: mode,
  1390. }
  1391. }
  1392. // Do executes Page.setSPCTransactionMode against the provided context.
  1393. func (p *SetSPCTransactionModeParams) Do(ctx context.Context) (err error) {
  1394. return cdp.Execute(ctx, CommandSetSPCTransactionMode, p, nil)
  1395. }
  1396. // SetRPHRegistrationModeParams extensions for Custom Handlers API:
  1397. // https://html.spec.whatwg.org/multipage/system-state.html#rph-automation.
  1398. type SetRPHRegistrationModeParams struct {
  1399. Mode AutoResponseMode `json:"mode"`
  1400. }
  1401. // SetRPHRegistrationMode extensions for Custom Handlers API:
  1402. // https://html.spec.whatwg.org/multipage/system-state.html#rph-automation.
  1403. //
  1404. // See: https://chromedevtools.github.io/devtools-protocol/tot/Page#method-setRPHRegistrationMode
  1405. //
  1406. // parameters:
  1407. //
  1408. // mode
  1409. func SetRPHRegistrationMode(mode AutoResponseMode) *SetRPHRegistrationModeParams {
  1410. return &SetRPHRegistrationModeParams{
  1411. Mode: mode,
  1412. }
  1413. }
  1414. // Do executes Page.setRPHRegistrationMode against the provided context.
  1415. func (p *SetRPHRegistrationModeParams) Do(ctx context.Context) (err error) {
  1416. return cdp.Execute(ctx, CommandSetRPHRegistrationMode, p, nil)
  1417. }
  1418. // GenerateTestReportParams generates a report for testing.
  1419. type GenerateTestReportParams struct {
  1420. Message string `json:"message"` // Message to be displayed in the report.
  1421. Group string `json:"group,omitempty"` // Specifies the endpoint group to deliver the report to.
  1422. }
  1423. // GenerateTestReport generates a report for testing.
  1424. //
  1425. // See: https://chromedevtools.github.io/devtools-protocol/tot/Page#method-generateTestReport
  1426. //
  1427. // parameters:
  1428. //
  1429. // message - Message to be displayed in the report.
  1430. func GenerateTestReport(message string) *GenerateTestReportParams {
  1431. return &GenerateTestReportParams{
  1432. Message: message,
  1433. }
  1434. }
  1435. // WithGroup specifies the endpoint group to deliver the report to.
  1436. func (p GenerateTestReportParams) WithGroup(group string) *GenerateTestReportParams {
  1437. p.Group = group
  1438. return &p
  1439. }
  1440. // Do executes Page.generateTestReport against the provided context.
  1441. func (p *GenerateTestReportParams) Do(ctx context.Context) (err error) {
  1442. return cdp.Execute(ctx, CommandGenerateTestReport, p, nil)
  1443. }
  1444. // WaitForDebuggerParams pauses page execution. Can be resumed using generic
  1445. // Runtime.runIfWaitingForDebugger.
  1446. type WaitForDebuggerParams struct{}
  1447. // WaitForDebugger pauses page execution. Can be resumed using generic
  1448. // Runtime.runIfWaitingForDebugger.
  1449. //
  1450. // See: https://chromedevtools.github.io/devtools-protocol/tot/Page#method-waitForDebugger
  1451. func WaitForDebugger() *WaitForDebuggerParams {
  1452. return &WaitForDebuggerParams{}
  1453. }
  1454. // Do executes Page.waitForDebugger against the provided context.
  1455. func (p *WaitForDebuggerParams) Do(ctx context.Context) (err error) {
  1456. return cdp.Execute(ctx, CommandWaitForDebugger, nil, nil)
  1457. }
  1458. // SetInterceptFileChooserDialogParams intercept file chooser requests and
  1459. // transfer control to protocol clients. When file chooser interception is
  1460. // enabled, native file chooser dialog is not shown. Instead, a protocol event
  1461. // Page.fileChooserOpened is emitted.
  1462. type SetInterceptFileChooserDialogParams struct {
  1463. Enabled bool `json:"enabled"`
  1464. }
  1465. // SetInterceptFileChooserDialog intercept file chooser requests and transfer
  1466. // control to protocol clients. When file chooser interception is enabled,
  1467. // native file chooser dialog is not shown. Instead, a protocol event
  1468. // Page.fileChooserOpened is emitted.
  1469. //
  1470. // See: https://chromedevtools.github.io/devtools-protocol/tot/Page#method-setInterceptFileChooserDialog
  1471. //
  1472. // parameters:
  1473. //
  1474. // enabled
  1475. func SetInterceptFileChooserDialog(enabled bool) *SetInterceptFileChooserDialogParams {
  1476. return &SetInterceptFileChooserDialogParams{
  1477. Enabled: enabled,
  1478. }
  1479. }
  1480. // Do executes Page.setInterceptFileChooserDialog against the provided context.
  1481. func (p *SetInterceptFileChooserDialogParams) Do(ctx context.Context) (err error) {
  1482. return cdp.Execute(ctx, CommandSetInterceptFileChooserDialog, p, nil)
  1483. }
  1484. // SetPrerenderingAllowedParams enable/disable prerendering manually. This
  1485. // command is a short-term solution for https://crbug.com/1440085. See
  1486. // https://docs.google.com/document/d/12HVmFxYj5Jc-eJr5OmWsa2bqTJsbgGLKI6ZIyx0_wpA
  1487. // for more details. TODO(https://crbug.com/1440085): Remove this once Puppeteer
  1488. // supports tab targets.
  1489. type SetPrerenderingAllowedParams struct {
  1490. IsAllowed bool `json:"isAllowed"`
  1491. }
  1492. // SetPrerenderingAllowed enable/disable prerendering manually. This command
  1493. // is a short-term solution for https://crbug.com/1440085. See
  1494. // https://docs.google.com/document/d/12HVmFxYj5Jc-eJr5OmWsa2bqTJsbgGLKI6ZIyx0_wpA
  1495. // for more details. TODO(https://crbug.com/1440085): Remove this once Puppeteer
  1496. // supports tab targets.
  1497. //
  1498. // See: https://chromedevtools.github.io/devtools-protocol/tot/Page#method-setPrerenderingAllowed
  1499. //
  1500. // parameters:
  1501. //
  1502. // isAllowed
  1503. func SetPrerenderingAllowed(isAllowed bool) *SetPrerenderingAllowedParams {
  1504. return &SetPrerenderingAllowedParams{
  1505. IsAllowed: isAllowed,
  1506. }
  1507. }
  1508. // Do executes Page.setPrerenderingAllowed against the provided context.
  1509. func (p *SetPrerenderingAllowedParams) Do(ctx context.Context) (err error) {
  1510. return cdp.Execute(ctx, CommandSetPrerenderingAllowed, p, nil)
  1511. }
  1512. // Command names.
  1513. const (
  1514. CommandAddScriptToEvaluateOnNewDocument = "Page.addScriptToEvaluateOnNewDocument"
  1515. CommandBringToFront = "Page.bringToFront"
  1516. CommandCaptureScreenshot = "Page.captureScreenshot"
  1517. CommandCaptureSnapshot = "Page.captureSnapshot"
  1518. CommandCreateIsolatedWorld = "Page.createIsolatedWorld"
  1519. CommandDisable = "Page.disable"
  1520. CommandEnable = "Page.enable"
  1521. CommandGetAppManifest = "Page.getAppManifest"
  1522. CommandGetInstallabilityErrors = "Page.getInstallabilityErrors"
  1523. CommandGetAppID = "Page.getAppId"
  1524. CommandGetAdScriptID = "Page.getAdScriptId"
  1525. CommandGetFrameTree = "Page.getFrameTree"
  1526. CommandGetLayoutMetrics = "Page.getLayoutMetrics"
  1527. CommandGetNavigationHistory = "Page.getNavigationHistory"
  1528. CommandResetNavigationHistory = "Page.resetNavigationHistory"
  1529. CommandGetResourceContent = "Page.getResourceContent"
  1530. CommandGetResourceTree = "Page.getResourceTree"
  1531. CommandHandleJavaScriptDialog = "Page.handleJavaScriptDialog"
  1532. CommandNavigate = "Page.navigate"
  1533. CommandNavigateToHistoryEntry = "Page.navigateToHistoryEntry"
  1534. CommandPrintToPDF = "Page.printToPDF"
  1535. CommandReload = "Page.reload"
  1536. CommandRemoveScriptToEvaluateOnNewDocument = "Page.removeScriptToEvaluateOnNewDocument"
  1537. CommandScreencastFrameAck = "Page.screencastFrameAck"
  1538. CommandSearchInResource = "Page.searchInResource"
  1539. CommandSetAdBlockingEnabled = "Page.setAdBlockingEnabled"
  1540. CommandSetBypassCSP = "Page.setBypassCSP"
  1541. CommandGetPermissionsPolicyState = "Page.getPermissionsPolicyState"
  1542. CommandGetOriginTrials = "Page.getOriginTrials"
  1543. CommandSetFontFamilies = "Page.setFontFamilies"
  1544. CommandSetFontSizes = "Page.setFontSizes"
  1545. CommandSetDocumentContent = "Page.setDocumentContent"
  1546. CommandSetLifecycleEventsEnabled = "Page.setLifecycleEventsEnabled"
  1547. CommandStartScreencast = "Page.startScreencast"
  1548. CommandStopLoading = "Page.stopLoading"
  1549. CommandCrash = "Page.crash"
  1550. CommandClose = "Page.close"
  1551. CommandSetWebLifecycleState = "Page.setWebLifecycleState"
  1552. CommandStopScreencast = "Page.stopScreencast"
  1553. CommandProduceCompilationCache = "Page.produceCompilationCache"
  1554. CommandAddCompilationCache = "Page.addCompilationCache"
  1555. CommandClearCompilationCache = "Page.clearCompilationCache"
  1556. CommandSetSPCTransactionMode = "Page.setSPCTransactionMode"
  1557. CommandSetRPHRegistrationMode = "Page.setRPHRegistrationMode"
  1558. CommandGenerateTestReport = "Page.generateTestReport"
  1559. CommandWaitForDebugger = "Page.waitForDebugger"
  1560. CommandSetInterceptFileChooserDialog = "Page.setInterceptFileChooserDialog"
  1561. CommandSetPrerenderingAllowed = "Page.setPrerenderingAllowed"
  1562. )