pwa.go 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335
  1. // Package pwa provides the Chrome DevTools Protocol
  2. // commands, types, and events for the PWA domain.
  3. //
  4. // This domain allows interacting with the browser to control PWAs.
  5. //
  6. // Generated by the cdproto-gen command.
  7. package pwa
  8. // Code generated by cdproto-gen. DO NOT EDIT.
  9. import (
  10. "context"
  11. "github.com/chromedp/cdproto/cdp"
  12. "github.com/chromedp/cdproto/target"
  13. )
  14. // GetOsAppStateParams returns the following OS state for the given manifest
  15. // id.
  16. type GetOsAppStateParams struct {
  17. ManifestID string `json:"manifestId"` // The id from the webapp's manifest file, commonly it's the url of the site installing the webapp. See https://web.dev/learn/pwa/web-app-manifest.
  18. }
  19. // GetOsAppState returns the following OS state for the given manifest id.
  20. //
  21. // See: https://chromedevtools.github.io/devtools-protocol/tot/PWA#method-getOsAppState
  22. //
  23. // parameters:
  24. //
  25. // manifestID - The id from the webapp's manifest file, commonly it's the url of the site installing the webapp. See https://web.dev/learn/pwa/web-app-manifest.
  26. func GetOsAppState(manifestID string) *GetOsAppStateParams {
  27. return &GetOsAppStateParams{
  28. ManifestID: manifestID,
  29. }
  30. }
  31. // GetOsAppStateReturns return values.
  32. type GetOsAppStateReturns struct {
  33. BadgeCount int64 `json:"badgeCount,omitempty,omitzero"`
  34. FileHandlers []*FileHandler `json:"fileHandlers,omitempty,omitzero"`
  35. }
  36. // Do executes PWA.getOsAppState against the provided context.
  37. //
  38. // returns:
  39. //
  40. // badgeCount
  41. // fileHandlers
  42. func (p *GetOsAppStateParams) Do(ctx context.Context) (badgeCount int64, fileHandlers []*FileHandler, err error) {
  43. // execute
  44. var res GetOsAppStateReturns
  45. err = cdp.Execute(ctx, CommandGetOsAppState, p, &res)
  46. if err != nil {
  47. return 0, nil, err
  48. }
  49. return res.BadgeCount, res.FileHandlers, nil
  50. }
  51. // InstallParams installs the given manifest identity, optionally using the
  52. // given install_url or IWA bundle location. TODO(crbug.com/337872319) Support
  53. // IWA to meet the following specific requirement. IWA-specific install
  54. // description: If the manifest_id is isolated-app://, install_url_or_bundle_url
  55. // is required, and can be either an http(s) URL or file:// URL pointing to a
  56. // signed web bundle (.swbn). The .swbn file's signing key must correspond to
  57. // manifest_id. If Chrome is not in IWA dev mode, the installation will fail,
  58. // regardless of the state of the allowlist.
  59. type InstallParams struct {
  60. ManifestID string `json:"manifestId"`
  61. InstallURLOrBundleURL string `json:"installUrlOrBundleUrl,omitempty,omitzero"` // The location of the app or bundle overriding the one derived from the manifestId.
  62. }
  63. // Install installs the given manifest identity, optionally using the given
  64. // install_url or IWA bundle location. TODO(crbug.com/337872319) Support IWA to
  65. // meet the following specific requirement. IWA-specific install description: If
  66. // the manifest_id is isolated-app://, install_url_or_bundle_url is required,
  67. // and can be either an http(s) URL or file:// URL pointing to a signed web
  68. // bundle (.swbn). The .swbn file's signing key must correspond to manifest_id.
  69. // If Chrome is not in IWA dev mode, the installation will fail, regardless of
  70. // the state of the allowlist.
  71. //
  72. // See: https://chromedevtools.github.io/devtools-protocol/tot/PWA#method-install
  73. //
  74. // parameters:
  75. //
  76. // manifestID
  77. func Install(manifestID string) *InstallParams {
  78. return &InstallParams{
  79. ManifestID: manifestID,
  80. }
  81. }
  82. // WithInstallURLOrBundleURL the location of the app or bundle overriding the
  83. // one derived from the manifestId.
  84. func (p InstallParams) WithInstallURLOrBundleURL(installURLOrBundleURL string) *InstallParams {
  85. p.InstallURLOrBundleURL = installURLOrBundleURL
  86. return &p
  87. }
  88. // Do executes PWA.install against the provided context.
  89. func (p *InstallParams) Do(ctx context.Context) (err error) {
  90. return cdp.Execute(ctx, CommandInstall, p, nil)
  91. }
  92. // UninstallParams uninstalls the given manifest_id and closes any opened app
  93. // windows.
  94. type UninstallParams struct {
  95. ManifestID string `json:"manifestId"`
  96. }
  97. // Uninstall uninstalls the given manifest_id and closes any opened app
  98. // windows.
  99. //
  100. // See: https://chromedevtools.github.io/devtools-protocol/tot/PWA#method-uninstall
  101. //
  102. // parameters:
  103. //
  104. // manifestID
  105. func Uninstall(manifestID string) *UninstallParams {
  106. return &UninstallParams{
  107. ManifestID: manifestID,
  108. }
  109. }
  110. // Do executes PWA.uninstall against the provided context.
  111. func (p *UninstallParams) Do(ctx context.Context) (err error) {
  112. return cdp.Execute(ctx, CommandUninstall, p, nil)
  113. }
  114. // LaunchParams launches the installed web app, or an url in the same web app
  115. // instead of the default start url if it is provided. Returns a page
  116. // Target.TargetID which can be used to attach to via Target.attachToTarget or
  117. // similar APIs.
  118. type LaunchParams struct {
  119. ManifestID string `json:"manifestId"`
  120. URL string `json:"url,omitempty,omitzero"`
  121. }
  122. // Launch launches the installed web app, or an url in the same web app
  123. // instead of the default start url if it is provided. Returns a page
  124. // Target.TargetID which can be used to attach to via Target.attachToTarget or
  125. // similar APIs.
  126. //
  127. // See: https://chromedevtools.github.io/devtools-protocol/tot/PWA#method-launch
  128. //
  129. // parameters:
  130. //
  131. // manifestID
  132. func Launch(manifestID string) *LaunchParams {
  133. return &LaunchParams{
  134. ManifestID: manifestID,
  135. }
  136. }
  137. // WithURL [no description].
  138. func (p LaunchParams) WithURL(url string) *LaunchParams {
  139. p.URL = url
  140. return &p
  141. }
  142. // LaunchReturns return values.
  143. type LaunchReturns struct {
  144. TargetID target.ID `json:"targetId,omitempty,omitzero"` // ID of the tab target created as a result.
  145. }
  146. // Do executes PWA.launch against the provided context.
  147. //
  148. // returns:
  149. //
  150. // targetID - ID of the tab target created as a result.
  151. func (p *LaunchParams) Do(ctx context.Context) (targetID target.ID, err error) {
  152. // execute
  153. var res LaunchReturns
  154. err = cdp.Execute(ctx, CommandLaunch, p, &res)
  155. if err != nil {
  156. return "", err
  157. }
  158. return res.TargetID, nil
  159. }
  160. // LaunchFilesInAppParams opens one or more local files from an installed web
  161. // app identified by its manifestId. The web app needs to have file handlers
  162. // registered to process the files. The API returns one or more page
  163. // Target.TargetIDs which can be used to attach to via Target.attachToTarget or
  164. // similar APIs. If some files in the parameters cannot be handled by the web
  165. // app, they will be ignored. If none of the files can be handled, this API
  166. // returns an error. If no files are provided as the parameter, this API also
  167. // returns an error. According to the definition of the file handlers in the
  168. // manifest file, one Target.TargetID may represent a page handling one or more
  169. // files. The order of the returned Target.TargetIDs is not guaranteed.
  170. // TODO(crbug.com/339454034): Check the existences of the input files.
  171. type LaunchFilesInAppParams struct {
  172. ManifestID string `json:"manifestId"`
  173. Files []string `json:"files"`
  174. }
  175. // LaunchFilesInApp opens one or more local files from an installed web app
  176. // identified by its manifestId. The web app needs to have file handlers
  177. // registered to process the files. The API returns one or more page
  178. // Target.TargetIDs which can be used to attach to via Target.attachToTarget or
  179. // similar APIs. If some files in the parameters cannot be handled by the web
  180. // app, they will be ignored. If none of the files can be handled, this API
  181. // returns an error. If no files are provided as the parameter, this API also
  182. // returns an error. According to the definition of the file handlers in the
  183. // manifest file, one Target.TargetID may represent a page handling one or more
  184. // files. The order of the returned Target.TargetIDs is not guaranteed.
  185. // TODO(crbug.com/339454034): Check the existences of the input files.
  186. //
  187. // See: https://chromedevtools.github.io/devtools-protocol/tot/PWA#method-launchFilesInApp
  188. //
  189. // parameters:
  190. //
  191. // manifestID
  192. // files
  193. func LaunchFilesInApp(manifestID string, files []string) *LaunchFilesInAppParams {
  194. return &LaunchFilesInAppParams{
  195. ManifestID: manifestID,
  196. Files: files,
  197. }
  198. }
  199. // LaunchFilesInAppReturns return values.
  200. type LaunchFilesInAppReturns struct {
  201. TargetIDs []target.ID `json:"targetIds,omitempty,omitzero"` // IDs of the tab targets created as the result.
  202. }
  203. // Do executes PWA.launchFilesInApp against the provided context.
  204. //
  205. // returns:
  206. //
  207. // targetIDs - IDs of the tab targets created as the result.
  208. func (p *LaunchFilesInAppParams) Do(ctx context.Context) (targetIDs []target.ID, err error) {
  209. // execute
  210. var res LaunchFilesInAppReturns
  211. err = cdp.Execute(ctx, CommandLaunchFilesInApp, p, &res)
  212. if err != nil {
  213. return nil, err
  214. }
  215. return res.TargetIDs, nil
  216. }
  217. // OpenCurrentPageInAppParams opens the current page in its web app
  218. // identified by the manifest id, needs to be called on a page target. This
  219. // function returns immediately without waiting for the app to finish loading.
  220. type OpenCurrentPageInAppParams struct {
  221. ManifestID string `json:"manifestId"`
  222. }
  223. // OpenCurrentPageInApp opens the current page in its web app identified by
  224. // the manifest id, needs to be called on a page target. This function returns
  225. // immediately without waiting for the app to finish loading.
  226. //
  227. // See: https://chromedevtools.github.io/devtools-protocol/tot/PWA#method-openCurrentPageInApp
  228. //
  229. // parameters:
  230. //
  231. // manifestID
  232. func OpenCurrentPageInApp(manifestID string) *OpenCurrentPageInAppParams {
  233. return &OpenCurrentPageInAppParams{
  234. ManifestID: manifestID,
  235. }
  236. }
  237. // Do executes PWA.openCurrentPageInApp against the provided context.
  238. func (p *OpenCurrentPageInAppParams) Do(ctx context.Context) (err error) {
  239. return cdp.Execute(ctx, CommandOpenCurrentPageInApp, p, nil)
  240. }
  241. // ChangeAppUserSettingsParams changes user settings of the web app
  242. // identified by its manifestId. If the app was not installed, this command
  243. // returns an error. Unset parameters will be ignored; unrecognized values will
  244. // cause an error. Unlike the ones defined in the manifest files of the web
  245. // apps, these settings are provided by the browser and controlled by the users,
  246. // they impact the way the browser handling the web apps. See the comment of
  247. // each parameter.
  248. type ChangeAppUserSettingsParams struct {
  249. ManifestID string `json:"manifestId"`
  250. LinkCapturing bool `json:"linkCapturing"` // If user allows the links clicked on by the user in the app's scope, or extended scope if the manifest has scope extensions and the flags DesktopPWAsLinkCapturingWithScopeExtensions and WebAppEnableScopeExtensions are enabled. Note, the API does not support resetting the linkCapturing to the initial value, uninstalling and installing the web app again will reset it. TODO(crbug.com/339453269): Setting this value on ChromeOS is not supported yet.
  251. DisplayMode DisplayMode `json:"displayMode,omitempty,omitzero"`
  252. }
  253. // ChangeAppUserSettings changes user settings of the web app identified by
  254. // its manifestId. If the app was not installed, this command returns an error.
  255. // Unset parameters will be ignored; unrecognized values will cause an error.
  256. // Unlike the ones defined in the manifest files of the web apps, these settings
  257. // are provided by the browser and controlled by the users, they impact the way
  258. // the browser handling the web apps. See the comment of each parameter.
  259. //
  260. // See: https://chromedevtools.github.io/devtools-protocol/tot/PWA#method-changeAppUserSettings
  261. //
  262. // parameters:
  263. //
  264. // manifestID
  265. func ChangeAppUserSettings(manifestID string) *ChangeAppUserSettingsParams {
  266. return &ChangeAppUserSettingsParams{
  267. ManifestID: manifestID,
  268. LinkCapturing: false,
  269. }
  270. }
  271. // WithLinkCapturing if user allows the links clicked on by the user in the
  272. // app's scope, or extended scope if the manifest has scope extensions and the
  273. // flags DesktopPWAsLinkCapturingWithScopeExtensions and
  274. // WebAppEnableScopeExtensions are enabled. Note, the API does not support
  275. // resetting the linkCapturing to the initial value, uninstalling and installing
  276. // the web app again will reset it. TODO(crbug.com/339453269): Setting this
  277. // value on ChromeOS is not supported yet.
  278. func (p ChangeAppUserSettingsParams) WithLinkCapturing(linkCapturing bool) *ChangeAppUserSettingsParams {
  279. p.LinkCapturing = linkCapturing
  280. return &p
  281. }
  282. // WithDisplayMode [no description].
  283. func (p ChangeAppUserSettingsParams) WithDisplayMode(displayMode DisplayMode) *ChangeAppUserSettingsParams {
  284. p.DisplayMode = displayMode
  285. return &p
  286. }
  287. // Do executes PWA.changeAppUserSettings against the provided context.
  288. func (p *ChangeAppUserSettingsParams) Do(ctx context.Context) (err error) {
  289. return cdp.Execute(ctx, CommandChangeAppUserSettings, p, nil)
  290. }
  291. // Command names.
  292. const (
  293. CommandGetOsAppState = "PWA.getOsAppState"
  294. CommandInstall = "PWA.install"
  295. CommandUninstall = "PWA.uninstall"
  296. CommandLaunch = "PWA.launch"
  297. CommandLaunchFilesInApp = "PWA.launchFilesInApp"
  298. CommandOpenCurrentPageInApp = "PWA.openCurrentPageInApp"
  299. CommandChangeAppUserSettings = "PWA.changeAppUserSettings"
  300. )