chrome-devtools-frontend 1.0.923319 → 1.0.925171

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (313) hide show
  1. package/config/gni/all_devtools_files.gni +0 -1
  2. package/config/gni/devtools_grd_files.gni +1 -3
  3. package/config/gni/devtools_image_files.gni +1 -1
  4. package/front_end/Images/src/copy_icon.svg +79 -0
  5. package/front_end/core/common/EventTarget.ts +22 -27
  6. package/front_end/core/common/Object.ts +28 -26
  7. package/front_end/core/common/Settings.ts +9 -8
  8. package/front_end/core/i18n/locales/en-US.json +18 -39
  9. package/front_end/core/i18n/locales/en-XL.json +18 -39
  10. package/front_end/core/platform/string-utilities.ts +4 -3
  11. package/front_end/core/sdk/EmulationModel.ts +1 -1
  12. package/front_end/core/sdk/NetworkManager.ts +1 -2
  13. package/front_end/core/sdk/ResourceTreeModel.ts +2 -3
  14. package/front_end/core/sdk/RuntimeModel.ts +2 -3
  15. package/front_end/core/sdk/SourceMap.ts +74 -31
  16. package/front_end/core/sdk/TargetManager.ts +9 -8
  17. package/front_end/core/sdk/TracingManager.ts +1 -1
  18. package/front_end/entrypoints/main/MainImpl.ts +1 -1
  19. package/front_end/entrypoints/node_main/NodeMain.ts +1 -1
  20. package/front_end/generated/InspectorBackendCommands.js +9 -5
  21. package/front_end/generated/protocol-mapping.d.ts +1 -0
  22. package/front_end/generated/protocol-proxy-api.d.ts +1 -0
  23. package/front_end/generated/protocol.d.ts +13 -2
  24. package/front_end/legacy_test_runner/application_test_runner/application_test_runner.js +0 -1
  25. package/front_end/models/bindings/CompilerScriptMapping.ts +24 -6
  26. package/front_end/models/bindings/DebuggerWorkspaceBinding.ts +30 -30
  27. package/front_end/models/extensions/ExtensionServer.ts +10 -13
  28. package/front_end/models/workspace/WorkspaceImpl.ts +1 -1
  29. package/front_end/models/workspace_diff/WorkspaceDiff.ts +24 -20
  30. package/front_end/panels/animation/AnimationModel.ts +6 -1
  31. package/front_end/panels/animation/AnimationTimeline.ts +2 -2
  32. package/front_end/panels/application/AppManifestView.ts +58 -20
  33. package/front_end/panels/application/ApplicationPanelCacheSection.ts +1 -59
  34. package/front_end/panels/application/ApplicationPanelSidebar.ts +15 -163
  35. package/front_end/panels/application/BackgroundServiceModel.ts +6 -1
  36. package/front_end/panels/application/BackgroundServiceView.ts +4 -4
  37. package/front_end/panels/application/DatabaseModel.ts +6 -1
  38. package/front_end/panels/application/DatabaseTableView.ts +1 -1
  39. package/front_end/panels/application/IndexedDBModel.ts +9 -1
  40. package/front_end/panels/application/IndexedDBViews.ts +6 -7
  41. package/front_end/panels/application/ServiceWorkerCacheViews.ts +1 -1
  42. package/front_end/panels/application/ServiceWorkersView.ts +3 -3
  43. package/front_end/panels/application/StorageItemsView.ts +2 -3
  44. package/front_end/panels/application/StorageView.ts +0 -13
  45. package/front_end/panels/application/appManifestView.css +8 -0
  46. package/front_end/panels/application/application-legacy.ts +0 -3
  47. package/front_end/panels/application/application.ts +0 -4
  48. package/front_end/panels/browser_debugger/ObjectEventListenersSidebarPane.ts +1 -1
  49. package/front_end/panels/console/ConsolePinPane.ts +1 -2
  50. package/front_end/panels/console/ConsoleSidebar.ts +2 -2
  51. package/front_end/panels/console/ConsoleView.ts +7 -6
  52. package/front_end/panels/console/ConsoleViewMessage.ts +4 -3
  53. package/front_end/panels/coverage/CoverageModel.ts +9 -3
  54. package/front_end/panels/coverage/CoverageView.ts +3 -2
  55. package/front_end/panels/css_overview/CSSOverviewModel.ts +1 -1
  56. package/front_end/panels/elements/ColorSwatchPopoverIcon.ts +1 -1
  57. package/front_end/panels/elements/ComputedStyleWidget.ts +2 -2
  58. package/front_end/panels/elements/ElementsPanel.ts +3 -3
  59. package/front_end/panels/elements/StylePropertyTreeElement.ts +14 -4
  60. package/front_end/panels/elements/StylesSidebarPane.ts +4 -2
  61. package/front_end/panels/input/InputModel.ts +1 -1
  62. package/front_end/panels/issues/ComboBoxOfCheckBoxes.ts +2 -4
  63. package/front_end/panels/issues/HiddenIssuesRow.ts +7 -12
  64. package/front_end/panels/layers/LayerTreeModel.ts +6 -1
  65. package/front_end/panels/layers/LayersPanel.ts +3 -4
  66. package/front_end/panels/lighthouse/LighthouseReportRenderer.ts +1 -0
  67. package/front_end/panels/media/MainView.ts +22 -19
  68. package/front_end/panels/media/MediaModel.ts +15 -7
  69. package/front_end/panels/media/PlayerMessagesView.ts +2 -4
  70. package/front_end/panels/network/NetworkPanel.ts +6 -6
  71. package/front_end/panels/network/RequestHeadersView.ts +7 -0
  72. package/front_end/panels/network/networkLogView.css +5 -0
  73. package/front_end/panels/profiler/HeapProfileView.ts +14 -4
  74. package/front_end/panels/profiler/HeapSnapshotView.ts +54 -22
  75. package/front_end/panels/profiler/LiveHeapProfileView.ts +2 -2
  76. package/front_end/panels/profiler/ProfileHeader.ts +11 -2
  77. package/front_end/panels/profiler/ProfileView.ts +3 -3
  78. package/front_end/panels/profiler/ProfilesPanel.ts +7 -6
  79. package/front_end/panels/screencast/InputModel.ts +1 -1
  80. package/front_end/panels/screencast/ScreencastView.ts +1 -1
  81. package/front_end/panels/security/SecurityModel.ts +5 -1
  82. package/front_end/panels/security/SecurityPanel.ts +1 -2
  83. package/front_end/panels/sensors/SensorsView.ts +3 -2
  84. package/front_end/panels/settings/emulation/components/UserAgentClientHintsForm.ts +6 -3
  85. package/front_end/panels/sources/CSSPlugin.ts +1 -1
  86. package/front_end/panels/sources/DebuggerPlugin.ts +6 -4
  87. package/front_end/panels/sources/InplaceFormatterEditorAction.ts +1 -1
  88. package/front_end/panels/sources/ScriptFormatterEditorAction.ts +1 -1
  89. package/front_end/panels/sources/SourcesPanel.ts +2 -2
  90. package/front_end/panels/timeline/TimelineFlameChartView.ts +5 -8
  91. package/front_end/panels/timeline/TimelineUIUtils.ts +1 -2
  92. package/front_end/panels/web_audio/AudioContextSelector.ts +4 -6
  93. package/front_end/panels/web_audio/WebAudioModel.ts +19 -1
  94. package/front_end/panels/web_audio/WebAudioView.ts +28 -22
  95. package/front_end/panels/web_audio/graph_visualizer/graph_visualizer.ts +0 -7
  96. package/front_end/panels/web_audio/web_audio.ts +1 -23
  97. package/front_end/third_party/lighthouse/lighthouse-dt-bundle.js +598 -595
  98. package/front_end/third_party/lighthouse/locales/en-US.json +6 -0
  99. package/front_end/third_party/lighthouse/locales/en-XL.json +6 -0
  100. package/front_end/third_party/lighthouse/report/bundle.d.ts +25 -4
  101. package/front_end/third_party/lighthouse/report/bundle.js +111 -22
  102. package/front_end/third_party/lighthouse/report-assets/report.css +120 -12
  103. package/front_end/third_party/lighthouse/report-assets/report.js +10 -10
  104. package/front_end/third_party/puppeteer/README.chromium +1 -1
  105. package/front_end/third_party/puppeteer/package/CHANGELOG.md +66 -0
  106. package/front_end/third_party/puppeteer/package/README.md +34 -13
  107. package/front_end/third_party/puppeteer/package/lib/cjs/puppeteer/common/AriaQueryHandler.d.ts.map +1 -1
  108. package/front_end/third_party/puppeteer/package/lib/cjs/puppeteer/common/AriaQueryHandler.js +5 -5
  109. package/front_end/third_party/puppeteer/package/lib/cjs/puppeteer/common/AriaQueryHandler.js.map +1 -1
  110. package/front_end/third_party/puppeteer/package/lib/cjs/puppeteer/common/Browser.d.ts +18 -2
  111. package/front_end/third_party/puppeteer/package/lib/cjs/puppeteer/common/Browser.d.ts.map +1 -1
  112. package/front_end/third_party/puppeteer/package/lib/cjs/puppeteer/common/Browser.js +8 -3
  113. package/front_end/third_party/puppeteer/package/lib/cjs/puppeteer/common/Browser.js.map +1 -1
  114. package/front_end/third_party/puppeteer/package/lib/cjs/puppeteer/common/Connection.d.ts +2 -2
  115. package/front_end/third_party/puppeteer/package/lib/cjs/puppeteer/common/Connection.js +2 -2
  116. package/front_end/third_party/puppeteer/package/lib/cjs/puppeteer/common/Coverage.d.ts +22 -6
  117. package/front_end/third_party/puppeteer/package/lib/cjs/puppeteer/common/Coverage.d.ts.map +1 -1
  118. package/front_end/third_party/puppeteer/package/lib/cjs/puppeteer/common/Coverage.js +14 -7
  119. package/front_end/third_party/puppeteer/package/lib/cjs/puppeteer/common/Coverage.js.map +1 -1
  120. package/front_end/third_party/puppeteer/package/lib/cjs/puppeteer/common/DOMWorld.d.ts +1 -0
  121. package/front_end/third_party/puppeteer/package/lib/cjs/puppeteer/common/DOMWorld.d.ts.map +1 -1
  122. package/front_end/third_party/puppeteer/package/lib/cjs/puppeteer/common/DOMWorld.js +10 -6
  123. package/front_end/third_party/puppeteer/package/lib/cjs/puppeteer/common/DOMWorld.js.map +1 -1
  124. package/front_end/third_party/puppeteer/package/lib/cjs/puppeteer/common/DeviceDescriptors.d.ts.map +1 -1
  125. package/front_end/third_party/puppeteer/package/lib/cjs/puppeteer/common/DeviceDescriptors.js +120 -0
  126. package/front_end/third_party/puppeteer/package/lib/cjs/puppeteer/common/DeviceDescriptors.js.map +1 -1
  127. package/front_end/third_party/puppeteer/package/lib/cjs/puppeteer/common/EvalTypes.d.ts +1 -1
  128. package/front_end/third_party/puppeteer/package/lib/cjs/puppeteer/common/EvalTypes.d.ts.map +1 -1
  129. package/front_end/third_party/puppeteer/package/lib/cjs/puppeteer/common/FrameManager.d.ts.map +1 -1
  130. package/front_end/third_party/puppeteer/package/lib/cjs/puppeteer/common/FrameManager.js +2 -2
  131. package/front_end/third_party/puppeteer/package/lib/cjs/puppeteer/common/FrameManager.js.map +1 -1
  132. package/front_end/third_party/puppeteer/package/lib/cjs/puppeteer/common/HTTPRequest.d.ts +62 -3
  133. package/front_end/third_party/puppeteer/package/lib/cjs/puppeteer/common/HTTPRequest.d.ts.map +1 -1
  134. package/front_end/third_party/puppeteer/package/lib/cjs/puppeteer/common/HTTPRequest.js +131 -3
  135. package/front_end/third_party/puppeteer/package/lib/cjs/puppeteer/common/HTTPRequest.js.map +1 -1
  136. package/front_end/third_party/puppeteer/package/lib/cjs/puppeteer/common/Input.d.ts +40 -0
  137. package/front_end/third_party/puppeteer/package/lib/cjs/puppeteer/common/Input.d.ts.map +1 -1
  138. package/front_end/third_party/puppeteer/package/lib/cjs/puppeteer/common/Input.js +76 -0
  139. package/front_end/third_party/puppeteer/package/lib/cjs/puppeteer/common/Input.js.map +1 -1
  140. package/front_end/third_party/puppeteer/package/lib/cjs/puppeteer/common/JSHandle.d.ts +53 -2
  141. package/front_end/third_party/puppeteer/package/lib/cjs/puppeteer/common/JSHandle.d.ts.map +1 -1
  142. package/front_end/third_party/puppeteer/package/lib/cjs/puppeteer/common/JSHandle.js +82 -13
  143. package/front_end/third_party/puppeteer/package/lib/cjs/puppeteer/common/JSHandle.js.map +1 -1
  144. package/front_end/third_party/puppeteer/package/lib/cjs/puppeteer/common/NetworkManager.d.ts +2 -1
  145. package/front_end/third_party/puppeteer/package/lib/cjs/puppeteer/common/NetworkManager.d.ts.map +1 -1
  146. package/front_end/third_party/puppeteer/package/lib/cjs/puppeteer/common/NetworkManager.js +14 -2
  147. package/front_end/third_party/puppeteer/package/lib/cjs/puppeteer/common/NetworkManager.js.map +1 -1
  148. package/front_end/third_party/puppeteer/package/lib/cjs/puppeteer/common/PDFOptions.d.ts +5 -0
  149. package/front_end/third_party/puppeteer/package/lib/cjs/puppeteer/common/PDFOptions.d.ts.map +1 -1
  150. package/front_end/third_party/puppeteer/package/lib/cjs/puppeteer/common/PDFOptions.js.map +1 -1
  151. package/front_end/third_party/puppeteer/package/lib/cjs/puppeteer/common/Page.d.ts +1053 -29
  152. package/front_end/third_party/puppeteer/package/lib/cjs/puppeteer/common/Page.d.ts.map +1 -1
  153. package/front_end/third_party/puppeteer/package/lib/cjs/puppeteer/common/Page.js +1114 -22
  154. package/front_end/third_party/puppeteer/package/lib/cjs/puppeteer/common/Page.js.map +1 -1
  155. package/front_end/third_party/puppeteer/package/lib/cjs/puppeteer/common/Tracing.d.ts.map +1 -1
  156. package/front_end/third_party/puppeteer/package/lib/cjs/puppeteer/common/Tracing.js +17 -6
  157. package/front_end/third_party/puppeteer/package/lib/cjs/puppeteer/common/Tracing.js.map +1 -1
  158. package/front_end/third_party/puppeteer/package/lib/cjs/puppeteer/common/assert.d.ts +1 -0
  159. package/front_end/third_party/puppeteer/package/lib/cjs/puppeteer/common/assert.d.ts.map +1 -1
  160. package/front_end/third_party/puppeteer/package/lib/cjs/puppeteer/common/assert.js +6 -1
  161. package/front_end/third_party/puppeteer/package/lib/cjs/puppeteer/common/assert.js.map +1 -1
  162. package/front_end/third_party/puppeteer/package/lib/cjs/puppeteer/common/helper.d.ts +21 -5
  163. package/front_end/third_party/puppeteer/package/lib/cjs/puppeteer/common/helper.d.ts.map +1 -1
  164. package/front_end/third_party/puppeteer/package/lib/cjs/puppeteer/common/helper.js +47 -28
  165. package/front_end/third_party/puppeteer/package/lib/cjs/puppeteer/common/helper.js.map +1 -1
  166. package/front_end/third_party/puppeteer/package/lib/cjs/puppeteer/global.d.ts +17 -0
  167. package/front_end/third_party/puppeteer/package/lib/cjs/puppeteer/global.d.ts.map +1 -0
  168. package/front_end/third_party/puppeteer/package/lib/cjs/puppeteer/global.js +3 -0
  169. package/front_end/third_party/puppeteer/package/lib/cjs/puppeteer/global.js.map +1 -0
  170. package/front_end/third_party/puppeteer/package/lib/cjs/puppeteer/node/BrowserFetcher.d.ts.map +1 -1
  171. package/front_end/third_party/puppeteer/package/lib/cjs/puppeteer/node/BrowserFetcher.js +9 -10
  172. package/front_end/third_party/puppeteer/package/lib/cjs/puppeteer/node/BrowserFetcher.js.map +1 -1
  173. package/front_end/third_party/puppeteer/package/lib/cjs/puppeteer/node/BrowserRunner.d.ts.map +1 -1
  174. package/front_end/third_party/puppeteer/package/lib/cjs/puppeteer/node/BrowserRunner.js +5 -2
  175. package/front_end/third_party/puppeteer/package/lib/cjs/puppeteer/node/BrowserRunner.js.map +1 -1
  176. package/front_end/third_party/puppeteer/package/lib/cjs/puppeteer/node/LaunchOptions.d.ts +10 -2
  177. package/front_end/third_party/puppeteer/package/lib/cjs/puppeteer/node/LaunchOptions.d.ts.map +1 -1
  178. package/front_end/third_party/puppeteer/package/lib/cjs/puppeteer/node/Launcher.d.ts +1 -1
  179. package/front_end/third_party/puppeteer/package/lib/cjs/puppeteer/node/Launcher.d.ts.map +1 -1
  180. package/front_end/third_party/puppeteer/package/lib/cjs/puppeteer/node/Launcher.js +83 -6
  181. package/front_end/third_party/puppeteer/package/lib/cjs/puppeteer/node/Launcher.js.map +1 -1
  182. package/front_end/third_party/puppeteer/package/lib/cjs/puppeteer/node/NodeWebSocketTransport.d.ts.map +1 -1
  183. package/front_end/third_party/puppeteer/package/lib/cjs/puppeteer/node/NodeWebSocketTransport.js +7 -1
  184. package/front_end/third_party/puppeteer/package/lib/cjs/puppeteer/node/NodeWebSocketTransport.js.map +1 -1
  185. package/front_end/third_party/puppeteer/package/lib/cjs/puppeteer/node/Puppeteer.d.ts +1 -1
  186. package/front_end/third_party/puppeteer/package/lib/cjs/puppeteer/node/Puppeteer.d.ts.map +1 -1
  187. package/front_end/third_party/puppeteer/package/lib/cjs/puppeteer/node/Puppeteer.js +2 -2
  188. package/front_end/third_party/puppeteer/package/lib/cjs/puppeteer/node/Puppeteer.js.map +1 -1
  189. package/front_end/third_party/puppeteer/package/lib/cjs/puppeteer/node/install.d.ts.map +1 -1
  190. package/front_end/third_party/puppeteer/package/lib/cjs/puppeteer/node/install.js +17 -3
  191. package/front_end/third_party/puppeteer/package/lib/cjs/puppeteer/node/install.js.map +1 -1
  192. package/front_end/third_party/puppeteer/package/lib/cjs/puppeteer/revisions.js +1 -1
  193. package/front_end/third_party/puppeteer/package/lib/esm/puppeteer/common/AriaQueryHandler.d.ts.map +1 -1
  194. package/front_end/third_party/puppeteer/package/lib/esm/puppeteer/common/AriaQueryHandler.js +5 -5
  195. package/front_end/third_party/puppeteer/package/lib/esm/puppeteer/common/AriaQueryHandler.js.map +1 -1
  196. package/front_end/third_party/puppeteer/package/lib/esm/puppeteer/common/Browser.d.ts +18 -2
  197. package/front_end/third_party/puppeteer/package/lib/esm/puppeteer/common/Browser.d.ts.map +1 -1
  198. package/front_end/third_party/puppeteer/package/lib/esm/puppeteer/common/Browser.js +8 -3
  199. package/front_end/third_party/puppeteer/package/lib/esm/puppeteer/common/Browser.js.map +1 -1
  200. package/front_end/third_party/puppeteer/package/lib/esm/puppeteer/common/Connection.d.ts +2 -2
  201. package/front_end/third_party/puppeteer/package/lib/esm/puppeteer/common/Connection.js +2 -2
  202. package/front_end/third_party/puppeteer/package/lib/esm/puppeteer/common/Coverage.d.ts +22 -6
  203. package/front_end/third_party/puppeteer/package/lib/esm/puppeteer/common/Coverage.d.ts.map +1 -1
  204. package/front_end/third_party/puppeteer/package/lib/esm/puppeteer/common/Coverage.js +14 -7
  205. package/front_end/third_party/puppeteer/package/lib/esm/puppeteer/common/Coverage.js.map +1 -1
  206. package/front_end/third_party/puppeteer/package/lib/esm/puppeteer/common/DOMWorld.d.ts +1 -0
  207. package/front_end/third_party/puppeteer/package/lib/esm/puppeteer/common/DOMWorld.d.ts.map +1 -1
  208. package/front_end/third_party/puppeteer/package/lib/esm/puppeteer/common/DOMWorld.js +10 -6
  209. package/front_end/third_party/puppeteer/package/lib/esm/puppeteer/common/DOMWorld.js.map +1 -1
  210. package/front_end/third_party/puppeteer/package/lib/esm/puppeteer/common/DeviceDescriptors.d.ts.map +1 -1
  211. package/front_end/third_party/puppeteer/package/lib/esm/puppeteer/common/DeviceDescriptors.js +120 -0
  212. package/front_end/third_party/puppeteer/package/lib/esm/puppeteer/common/DeviceDescriptors.js.map +1 -1
  213. package/front_end/third_party/puppeteer/package/lib/esm/puppeteer/common/EvalTypes.d.ts +1 -1
  214. package/front_end/third_party/puppeteer/package/lib/esm/puppeteer/common/EvalTypes.d.ts.map +1 -1
  215. package/front_end/third_party/puppeteer/package/lib/esm/puppeteer/common/FrameManager.d.ts.map +1 -1
  216. package/front_end/third_party/puppeteer/package/lib/esm/puppeteer/common/FrameManager.js +2 -2
  217. package/front_end/third_party/puppeteer/package/lib/esm/puppeteer/common/FrameManager.js.map +1 -1
  218. package/front_end/third_party/puppeteer/package/lib/esm/puppeteer/common/HTTPRequest.d.ts +62 -3
  219. package/front_end/third_party/puppeteer/package/lib/esm/puppeteer/common/HTTPRequest.d.ts.map +1 -1
  220. package/front_end/third_party/puppeteer/package/lib/esm/puppeteer/common/HTTPRequest.js +131 -3
  221. package/front_end/third_party/puppeteer/package/lib/esm/puppeteer/common/HTTPRequest.js.map +1 -1
  222. package/front_end/third_party/puppeteer/package/lib/esm/puppeteer/common/Input.d.ts +40 -0
  223. package/front_end/third_party/puppeteer/package/lib/esm/puppeteer/common/Input.d.ts.map +1 -1
  224. package/front_end/third_party/puppeteer/package/lib/esm/puppeteer/common/Input.js +76 -0
  225. package/front_end/third_party/puppeteer/package/lib/esm/puppeteer/common/Input.js.map +1 -1
  226. package/front_end/third_party/puppeteer/package/lib/esm/puppeteer/common/JSHandle.d.ts +53 -2
  227. package/front_end/third_party/puppeteer/package/lib/esm/puppeteer/common/JSHandle.d.ts.map +1 -1
  228. package/front_end/third_party/puppeteer/package/lib/esm/puppeteer/common/JSHandle.js +82 -13
  229. package/front_end/third_party/puppeteer/package/lib/esm/puppeteer/common/JSHandle.js.map +1 -1
  230. package/front_end/third_party/puppeteer/package/lib/esm/puppeteer/common/NetworkManager.d.ts +2 -1
  231. package/front_end/third_party/puppeteer/package/lib/esm/puppeteer/common/NetworkManager.d.ts.map +1 -1
  232. package/front_end/third_party/puppeteer/package/lib/esm/puppeteer/common/NetworkManager.js +14 -2
  233. package/front_end/third_party/puppeteer/package/lib/esm/puppeteer/common/NetworkManager.js.map +1 -1
  234. package/front_end/third_party/puppeteer/package/lib/esm/puppeteer/common/PDFOptions.d.ts +5 -0
  235. package/front_end/third_party/puppeteer/package/lib/esm/puppeteer/common/PDFOptions.d.ts.map +1 -1
  236. package/front_end/third_party/puppeteer/package/lib/esm/puppeteer/common/PDFOptions.js.map +1 -1
  237. package/front_end/third_party/puppeteer/package/lib/esm/puppeteer/common/Page.d.ts +1053 -29
  238. package/front_end/third_party/puppeteer/package/lib/esm/puppeteer/common/Page.d.ts.map +1 -1
  239. package/front_end/third_party/puppeteer/package/lib/esm/puppeteer/common/Page.js +1115 -23
  240. package/front_end/third_party/puppeteer/package/lib/esm/puppeteer/common/Page.js.map +1 -1
  241. package/front_end/third_party/puppeteer/package/lib/esm/puppeteer/common/Tracing.d.ts.map +1 -1
  242. package/front_end/third_party/puppeteer/package/lib/esm/puppeteer/common/Tracing.js +17 -6
  243. package/front_end/third_party/puppeteer/package/lib/esm/puppeteer/common/Tracing.js.map +1 -1
  244. package/front_end/third_party/puppeteer/package/lib/esm/puppeteer/common/assert.d.ts +1 -0
  245. package/front_end/third_party/puppeteer/package/lib/esm/puppeteer/common/assert.d.ts.map +1 -1
  246. package/front_end/third_party/puppeteer/package/lib/esm/puppeteer/common/assert.js +4 -0
  247. package/front_end/third_party/puppeteer/package/lib/esm/puppeteer/common/assert.js.map +1 -1
  248. package/front_end/third_party/puppeteer/package/lib/esm/puppeteer/common/helper.d.ts +21 -5
  249. package/front_end/third_party/puppeteer/package/lib/esm/puppeteer/common/helper.d.ts.map +1 -1
  250. package/front_end/third_party/puppeteer/package/lib/esm/puppeteer/common/helper.js +32 -13
  251. package/front_end/third_party/puppeteer/package/lib/esm/puppeteer/common/helper.js.map +1 -1
  252. package/front_end/third_party/puppeteer/package/lib/esm/puppeteer/global.d.ts +17 -0
  253. package/front_end/third_party/puppeteer/package/lib/esm/puppeteer/global.d.ts.map +1 -0
  254. package/front_end/third_party/puppeteer/package/lib/esm/puppeteer/global.js +2 -0
  255. package/front_end/third_party/puppeteer/package/lib/esm/puppeteer/global.js.map +1 -0
  256. package/front_end/third_party/puppeteer/package/lib/esm/puppeteer/node/BrowserFetcher.d.ts.map +1 -1
  257. package/front_end/third_party/puppeteer/package/lib/esm/puppeteer/node/BrowserFetcher.js +9 -10
  258. package/front_end/third_party/puppeteer/package/lib/esm/puppeteer/node/BrowserFetcher.js.map +1 -1
  259. package/front_end/third_party/puppeteer/package/lib/esm/puppeteer/node/BrowserRunner.d.ts.map +1 -1
  260. package/front_end/third_party/puppeteer/package/lib/esm/puppeteer/node/BrowserRunner.js +5 -2
  261. package/front_end/third_party/puppeteer/package/lib/esm/puppeteer/node/BrowserRunner.js.map +1 -1
  262. package/front_end/third_party/puppeteer/package/lib/esm/puppeteer/node/LaunchOptions.d.ts +10 -2
  263. package/front_end/third_party/puppeteer/package/lib/esm/puppeteer/node/LaunchOptions.d.ts.map +1 -1
  264. package/front_end/third_party/puppeteer/package/lib/esm/puppeteer/node/Launcher.d.ts +1 -1
  265. package/front_end/third_party/puppeteer/package/lib/esm/puppeteer/node/Launcher.d.ts.map +1 -1
  266. package/front_end/third_party/puppeteer/package/lib/esm/puppeteer/node/Launcher.js +83 -6
  267. package/front_end/third_party/puppeteer/package/lib/esm/puppeteer/node/Launcher.js.map +1 -1
  268. package/front_end/third_party/puppeteer/package/lib/esm/puppeteer/node/NodeWebSocketTransport.d.ts.map +1 -1
  269. package/front_end/third_party/puppeteer/package/lib/esm/puppeteer/node/NodeWebSocketTransport.js +7 -1
  270. package/front_end/third_party/puppeteer/package/lib/esm/puppeteer/node/NodeWebSocketTransport.js.map +1 -1
  271. package/front_end/third_party/puppeteer/package/lib/esm/puppeteer/node/Puppeteer.d.ts +1 -1
  272. package/front_end/third_party/puppeteer/package/lib/esm/puppeteer/node/Puppeteer.d.ts.map +1 -1
  273. package/front_end/third_party/puppeteer/package/lib/esm/puppeteer/node/Puppeteer.js +2 -2
  274. package/front_end/third_party/puppeteer/package/lib/esm/puppeteer/node/Puppeteer.js.map +1 -1
  275. package/front_end/third_party/puppeteer/package/lib/esm/puppeteer/node/install.d.ts.map +1 -1
  276. package/front_end/third_party/puppeteer/package/lib/esm/puppeteer/node/install.js +17 -3
  277. package/front_end/third_party/puppeteer/package/lib/esm/puppeteer/node/install.js.map +1 -1
  278. package/front_end/third_party/puppeteer/package/lib/esm/puppeteer/revisions.js +1 -1
  279. package/front_end/third_party/puppeteer/package/lib/types.d.ts +1382 -19726
  280. package/front_end/third_party/puppeteer/package/package.json +9 -6
  281. package/front_end/third_party/wasmparser/README.chromium +2 -2
  282. package/front_end/third_party/wasmparser/package/CHANGELOG.md +13 -0
  283. package/front_end/third_party/wasmparser/package/dist/cjs/WasmDis.js +50 -10
  284. package/front_end/third_party/wasmparser/package/dist/cjs/WasmDis.js.map +1 -1
  285. package/front_end/third_party/wasmparser/package/dist/cjs/WasmParser.d.ts +21 -4
  286. package/front_end/third_party/wasmparser/package/dist/cjs/WasmParser.js +76 -8
  287. package/front_end/third_party/wasmparser/package/dist/cjs/WasmParser.js.map +1 -1
  288. package/front_end/third_party/wasmparser/package/dist/esm/WasmDis.js +50 -10
  289. package/front_end/third_party/wasmparser/package/dist/esm/WasmDis.js.map +1 -1
  290. package/front_end/third_party/wasmparser/package/dist/esm/WasmParser.d.ts +21 -4
  291. package/front_end/third_party/wasmparser/package/dist/esm/WasmParser.js +76 -8
  292. package/front_end/third_party/wasmparser/package/dist/esm/WasmParser.js.map +1 -1
  293. package/front_end/third_party/wasmparser/package/package.json +1 -1
  294. package/front_end/third_party/wasmparser/package/src/WasmDis.ts +47 -10
  295. package/front_end/third_party/wasmparser/package/src/WasmParser.ts +75 -5
  296. package/front_end/ui/components/icon_button/iconButton.css +4 -0
  297. package/front_end/ui/components/linear_memory_inspector/LinearMemoryInspectorPane.ts +2 -6
  298. package/front_end/ui/legacy/FilterBar.ts +1 -1
  299. package/front_end/ui/legacy/GlassPane.ts +1 -3
  300. package/front_end/ui/legacy/SplitWidget.ts +1 -1
  301. package/front_end/ui/legacy/UIUtils.ts +3 -4
  302. package/front_end/ui/legacy/components/color_picker/ContrastDetails.ts +3 -3
  303. package/front_end/ui/legacy/components/color_picker/Spectrum.ts +1 -1
  304. package/front_end/ui/legacy/components/inline_editor/SwatchPopoverHelper.ts +6 -2
  305. package/front_end/ui/legacy/components/perf_ui/OverviewGrid.ts +3 -3
  306. package/front_end/ui/legacy/components/utils/TargetDetachedDialog.ts +1 -1
  307. package/front_end/ui/legacy/reportView.css +1 -0
  308. package/package.json +1 -1
  309. package/scripts/build/rollup.config.js +0 -5
  310. package/front_end/Images/src/exclamation_mark_circle_icon.svg +0 -65
  311. package/front_end/legacy_test_runner/application_test_runner/AppcacheTestRunner.js +0 -220
  312. package/front_end/panels/application/ApplicationCacheItemsView.ts +0 -335
  313. package/front_end/panels/application/ApplicationCacheModel.ts +0 -206
@@ -102,6 +102,7 @@ class Page extends EventEmitter_js_1.EventEmitter {
102
102
  // TODO: improve this typedef - it's a function that takes a file chooser or
103
103
  // something?
104
104
  this._fileChooserInterceptors = new Set();
105
+ this._userDragInterceptionEnabled = false;
105
106
  this._client = client;
106
107
  this._target = target;
107
108
  this._keyboard = new Input_js_1.Keyboard(client);
@@ -121,7 +122,7 @@ class Page extends EventEmitter_js_1.EventEmitter {
121
122
  // We still want to attach to workers for emitting events.
122
123
  // We still want to attach to iframes so sessions may interact with them.
123
124
  // We detach from all other types out of an abundance of caution.
124
- // See https://source.chromium.org/chromium/chromium/src/+/master:content/browser/devtools/devtools_agent_host_impl.cc?q=f:devtools%20-f:out%20%22::kTypePage%5B%5D%22&ss=chromium
125
+ // See https://source.chromium.org/chromium/chromium/src/+/main:content/browser/devtools/devtools_agent_host_impl.cc?ss=chromium&q=f:devtools%20-f:out%20%22::kTypePage%5B%5D%22
125
126
  // for the complete list of available types.
126
127
  client
127
128
  .send('Target.detachFromTarget', {
@@ -201,6 +202,12 @@ class Page extends EventEmitter_js_1.EventEmitter {
201
202
  for (const interceptor of interceptors)
202
203
  interceptor.call(null, fileChooser);
203
204
  }
205
+ /**
206
+ * @returns `true` if drag events are being intercepted, `false` otherwise.
207
+ */
208
+ isDragInterceptionEnabled() {
209
+ return this._userDragInterceptionEnabled;
210
+ }
204
211
  /**
205
212
  * @returns `true` if the page has JavaScript enabled, `false` otherwise.
206
213
  */
@@ -210,9 +217,15 @@ class Page extends EventEmitter_js_1.EventEmitter {
210
217
  /**
211
218
  * Listen to page events.
212
219
  */
220
+ // Note: this method exists to define event typings and handle
221
+ // proper wireup of cooperative request interception. Actual event listening and
222
+ // dispatching is delegated to EventEmitter.
213
223
  on(eventName, handler) {
214
- // Note: this method only exists to define the types; we delegate the impl
215
- // to EventEmitter.
224
+ if (eventName === 'request') {
225
+ return super.on(eventName, (event) => {
226
+ event.enqueueInterceptAction(() => handler(event));
227
+ });
228
+ }
216
229
  return super.on(eventName, handler);
217
230
  }
218
231
  once(eventName, handler) {
@@ -221,8 +234,26 @@ class Page extends EventEmitter_js_1.EventEmitter {
221
234
  return super.once(eventName, handler);
222
235
  }
223
236
  /**
237
+ * This method is typically coupled with an action that triggers file
238
+ * choosing. The following example clicks a button that issues a file chooser
239
+ * and then responds with `/tmp/myfile.pdf` as if a user has selected this file.
240
+ *
241
+ * ```js
242
+ * const [fileChooser] = await Promise.all([
243
+ * page.waitForFileChooser(),
244
+ * page.click('#upload-file-button'),
245
+ * // some button that triggers file selection
246
+ * ]);
247
+ * await fileChooser.accept(['/tmp/myfile.pdf']);
248
+ * ```
249
+ *
250
+ * NOTE: This must be called before the file chooser is launched. It will not
251
+ * return a currently active file chooser.
224
252
  * @param options - Optional waiting parameters
225
253
  * @returns Resolves after a page requests a file picker.
254
+ * @remarks
255
+ * NOTE: In non-headless Chromium, this method results in the native file picker
256
+ * dialog `not showing up` for the user.
226
257
  */
227
258
  async waitForFileChooser(options = {}) {
228
259
  if (!this._fileChooserInterceptors.size)
@@ -242,11 +273,9 @@ class Page extends EventEmitter_js_1.EventEmitter {
242
273
  }
243
274
  /**
244
275
  * Sets the page's geolocation.
245
- *
246
276
  * @remarks
247
- * Consider using {@link BrowserContext.overridePermissions} to grant
277
+ * NOTE: Consider using {@link BrowserContext.overridePermissions} to grant
248
278
  * permissions for the page to read its geolocation.
249
- *
250
279
  * @example
251
280
  * ```js
252
281
  * await page.setGeolocation({latitude: 59.95, longitude: 30.31667});
@@ -273,13 +302,20 @@ class Page extends EventEmitter_js_1.EventEmitter {
273
302
  return this._target;
274
303
  }
275
304
  /**
276
- * @returns The browser this page belongs to.
305
+ * Get the CDP session client the page belongs to.
306
+ * @internal
307
+ */
308
+ client() {
309
+ return this._client;
310
+ }
311
+ /**
312
+ * Get the browser the page belongs to.
277
313
  */
278
314
  browser() {
279
315
  return this._target.browser();
280
316
  }
281
317
  /**
282
- * @returns The browser context that the page belongs to
318
+ * Get the browser context that the page belongs to.
283
319
  */
284
320
  browserContext() {
285
321
  return this._target.browserContext();
@@ -296,6 +332,8 @@ class Page extends EventEmitter_js_1.EventEmitter {
296
332
  }
297
333
  /**
298
334
  * @returns The page's main frame.
335
+ * @remarks
336
+ * Page is guaranteed to have a main frame which persists during navigations.
299
337
  */
300
338
  mainFrame() {
301
339
  return this._frameManager.mainFrame();
@@ -323,8 +361,11 @@ class Page extends EventEmitter_js_1.EventEmitter {
323
361
  }
324
362
  /**
325
363
  * @returns all of the dedicated
326
- * {@link https://developer.mozilla.org/en-US/docs/Web/API/Web_Workers_API | WebWorkers}
364
+ * {@link https://developer.mozilla.org/en-US/docs/Web/API/Web_Workers_API |
365
+ * WebWorkers}
327
366
  * associated with the page.
367
+ * @remarks
368
+ * NOTE: This does not contain ServiceWorkers
328
369
  */
329
370
  workers() {
330
371
  return Array.from(this._workers.values());
@@ -359,22 +400,74 @@ class Page extends EventEmitter_js_1.EventEmitter {
359
400
  * await browser.close();
360
401
  * })();
361
402
  * ```
403
+ * NOTE: Enabling request interception disables page caching.
362
404
  */
363
405
  async setRequestInterception(value) {
364
406
  return this._frameManager.networkManager().setRequestInterception(value);
365
407
  }
408
+ /**
409
+ * @param enabled - Whether to enable drag interception.
410
+ *
411
+ * @remarks
412
+ * Activating drag interception enables the `Input.drag`,
413
+ * methods This provides the capability to capture drag events emitted
414
+ * on the page, which can then be used to simulate drag-and-drop.
415
+ */
416
+ async setDragInterception(enabled) {
417
+ this._userDragInterceptionEnabled = enabled;
418
+ return this._client.send('Input.setInterceptDrags', { enabled });
419
+ }
366
420
  /**
367
421
  * @param enabled - When `true`, enables offline mode for the page.
422
+ * @remarks
423
+ * NOTE: while this method sets the network connection to offline, it does
424
+ * not change the parameters used in [page.emulateNetworkConditions(networkConditions)]
425
+ * (#pageemulatenetworkconditionsnetworkconditions)
368
426
  */
369
427
  setOfflineMode(enabled) {
370
428
  return this._frameManager.networkManager().setOfflineMode(enabled);
371
429
  }
430
+ /**
431
+ * @param networkConditions - Passing `null` disables network condition emulation.
432
+ * @example
433
+ * ```js
434
+ * const puppeteer = require('puppeteer');
435
+ * const slow3G = puppeteer.networkConditions['Slow 3G'];
436
+ *
437
+ * (async () => {
438
+ * const browser = await puppeteer.launch();
439
+ * const page = await browser.newPage();
440
+ * await page.emulateNetworkConditions(slow3G);
441
+ * await page.goto('https://www.google.com');
442
+ * // other actions...
443
+ * await browser.close();
444
+ * })();
445
+ * ```
446
+ * @remarks
447
+ * NOTE: This does not affect WebSockets and WebRTC PeerConnections (see
448
+ * https://crbug.com/563644). To set the page offline, you can use
449
+ * [page.setOfflineMode(enabled)](#pagesetofflinemodeenabled).
450
+ */
372
451
  emulateNetworkConditions(networkConditions) {
373
452
  return this._frameManager
374
453
  .networkManager()
375
454
  .emulateNetworkConditions(networkConditions);
376
455
  }
377
456
  /**
457
+ * This setting will change the default maximum navigation time for the
458
+ * following methods and related shortcuts:
459
+ *
460
+ * - {@link Page.goBack | page.goBack(options)}
461
+ *
462
+ * - {@link Page.goForward | page.goForward(options)}
463
+ *
464
+ * - {@link Page.goto | page.goto(url,options)}
465
+ *
466
+ * - {@link Page.reload | page.reload(options)}
467
+ *
468
+ * - {@link Page.setContent | page.setContent(html,options)}
469
+ *
470
+ * - {@link Page.waitForNavigation | page.waitForNavigation(options)}
378
471
  * @param timeout - Maximum navigation time in milliseconds.
379
472
  */
380
473
  setDefaultNavigationTimeout(timeout) {
@@ -458,6 +551,9 @@ class Page extends EventEmitter_js_1.EventEmitter {
458
551
  * given prototype.
459
552
  *
460
553
  * @remarks
554
+ * Shortcut for
555
+ * {@link ExecutionContext.queryObjects |
556
+ * page.mainFrame().executionContext().queryObjects(prototypeHandle)}.
461
557
  *
462
558
  * @example
463
559
  *
@@ -474,6 +570,8 @@ class Page extends EventEmitter_js_1.EventEmitter {
474
570
  * await mapPrototype.dispose();
475
571
  * ```
476
572
  * @param prototypeHandle - a handle to the object prototype.
573
+ * @returns Promise which resolves to a handle to an array of objects with
574
+ * this prototype.
477
575
  */
478
576
  async queryObjects(prototypeHandle) {
479
577
  const context = await this.mainFrame().executionContext();
@@ -605,9 +703,24 @@ class Page extends EventEmitter_js_1.EventEmitter {
605
703
  async $$eval(selector, pageFunction, ...args) {
606
704
  return this.mainFrame().$$eval(selector, pageFunction, ...args);
607
705
  }
706
+ /**
707
+ * The method runs `document.querySelectorAll` within the page. If no elements
708
+ * match the selector, the return value resolves to `[]`.
709
+ * @remarks
710
+ * Shortcut for {@link Frame.$$ | Page.mainFrame().$$(selector) }.
711
+ * @param selector - A `selector` to query page for
712
+ */
608
713
  async $$(selector) {
609
714
  return this.mainFrame().$$(selector);
610
715
  }
716
+ /**
717
+ * The method evaluates the XPath expression relative to the page document as
718
+ * its context node. If there are no such elements, the method resolves to an
719
+ * empty array.
720
+ * @remarks
721
+ * Shortcut for {@link Frame.$x | Page.mainFrame().$x(expression) }.
722
+ * @param expression - Expression to evaluate
723
+ */
611
724
  async $x(expression) {
612
725
  return this.mainFrame().$x(expression);
613
726
  }
@@ -636,6 +749,12 @@ class Page extends EventEmitter_js_1.EventEmitter {
636
749
  await this._client.send('Network.deleteCookies', item);
637
750
  }
638
751
  }
752
+ /**
753
+ * @example
754
+ * ```js
755
+ * await page.setCookie(cookieObject1, cookieObject2);
756
+ * ```
757
+ */
639
758
  async setCookie(...cookies) {
640
759
  const pageURL = this.url();
641
760
  const startsWithHTTP = pageURL.startsWith('http');
@@ -651,12 +770,84 @@ class Page extends EventEmitter_js_1.EventEmitter {
651
770
  if (items.length)
652
771
  await this._client.send('Network.setCookies', { cookies: items });
653
772
  }
773
+ /**
774
+ * Adds a `<script>` tag into the page with the desired URL or content.
775
+ * @remarks
776
+ * Shortcut for {@link Frame.addScriptTag | page.mainFrame().addScriptTag(options) }.
777
+ * @returns Promise which resolves to the added tag when the script's onload fires or
778
+ * when the script content was injected into frame.
779
+ */
654
780
  async addScriptTag(options) {
655
781
  return this.mainFrame().addScriptTag(options);
656
782
  }
783
+ /**
784
+ * Adds a `<link rel="stylesheet">` tag into the page with the desired URL or a
785
+ * `<style type="text/css">` tag with the content.
786
+ * @returns Promise which resolves to the added tag when the stylesheet's
787
+ * onload fires or when the CSS content was injected into frame.
788
+ */
657
789
  async addStyleTag(options) {
658
790
  return this.mainFrame().addStyleTag(options);
659
791
  }
792
+ /**
793
+ * The method adds a function called `name` on the page's `window` object. When
794
+ * called, the function executes `puppeteerFunction` in node.js and returns a
795
+ * `Promise` which resolves to the return value of `puppeteerFunction`.
796
+ *
797
+ * If the puppeteerFunction returns a `Promise`, it will be awaited.
798
+ *
799
+ * NOTE: Functions installed via `page.exposeFunction` survive navigations.
800
+ * @param name - Name of the function on the window object
801
+ * @param puppeteerFunction - Callback function which will be called in
802
+ * Puppeteer's context.
803
+ * @example
804
+ * An example of adding an `md5` function into the page:
805
+ * ```js
806
+ * const puppeteer = require('puppeteer');
807
+ * const crypto = require('crypto');
808
+ *
809
+ * (async () => {
810
+ * const browser = await puppeteer.launch();
811
+ * const page = await browser.newPage();
812
+ * page.on('console', (msg) => console.log(msg.text()));
813
+ * await page.exposeFunction('md5', (text) =>
814
+ * crypto.createHash('md5').update(text).digest('hex')
815
+ * );
816
+ * await page.evaluate(async () => {
817
+ * // use window.md5 to compute hashes
818
+ * const myString = 'PUPPETEER';
819
+ * const myHash = await window.md5(myString);
820
+ * console.log(`md5 of ${myString} is ${myHash}`);
821
+ * });
822
+ * await browser.close();
823
+ * })();
824
+ * ```
825
+ * An example of adding a `window.readfile` function into the page:
826
+ * ```js
827
+ * const puppeteer = require('puppeteer');
828
+ * const fs = require('fs');
829
+ *
830
+ * (async () => {
831
+ * const browser = await puppeteer.launch();
832
+ * const page = await browser.newPage();
833
+ * page.on('console', (msg) => console.log(msg.text()));
834
+ * await page.exposeFunction('readfile', async (filePath) => {
835
+ * return new Promise((resolve, reject) => {
836
+ * fs.readFile(filePath, 'utf8', (err, text) => {
837
+ * if (err) reject(err);
838
+ * else resolve(text);
839
+ * });
840
+ * });
841
+ * });
842
+ * await page.evaluate(async () => {
843
+ * // use window.readfile to read contents of a file
844
+ * const content = await window.readfile('/etc/hosts');
845
+ * console.log(content);
846
+ * });
847
+ * await browser.close();
848
+ * })();
849
+ * ```
850
+ */
660
851
  async exposeFunction(name, puppeteerFunction) {
661
852
  if (this._pageBindings.has(name))
662
853
  throw new Error(`Failed to add page binding with name ${name}: window['${name}'] already exists!`);
@@ -668,15 +859,71 @@ class Page extends EventEmitter_js_1.EventEmitter {
668
859
  });
669
860
  await Promise.all(this.frames().map((frame) => frame.evaluate(expression).catch(helper_js_1.debugError)));
670
861
  }
862
+ /**
863
+ * Provide credentials for `HTTP authentication`.
864
+ * @remarks To disable authentication, pass `null`.
865
+ */
671
866
  async authenticate(credentials) {
672
867
  return this._frameManager.networkManager().authenticate(credentials);
673
868
  }
869
+ /**
870
+ * The extra HTTP headers will be sent with every request the page initiates.
871
+ * NOTE: All HTTP header names are lowercased. (HTTP headers are
872
+ * case-insensitive, so this shouldn’t impact your server code.)
873
+ * NOTE: page.setExtraHTTPHeaders does not guarantee the order of headers in
874
+ * the outgoing requests.
875
+ * @param headers - An object containing additional HTTP headers to be sent
876
+ * with every request. All header values must be strings.
877
+ * @returns
878
+ */
674
879
  async setExtraHTTPHeaders(headers) {
675
880
  return this._frameManager.networkManager().setExtraHTTPHeaders(headers);
676
881
  }
677
- async setUserAgent(userAgent) {
678
- return this._frameManager.networkManager().setUserAgent(userAgent);
882
+ /**
883
+ * @param userAgent - Specific user agent to use in this page
884
+ * @param userAgentData - Specific user agent client hint data to use in this
885
+ * page
886
+ * @returns Promise which resolves when the user agent is set.
887
+ */
888
+ async setUserAgent(userAgent, userAgentMetadata) {
889
+ return this._frameManager
890
+ .networkManager()
891
+ .setUserAgent(userAgent, userAgentMetadata);
679
892
  }
893
+ /**
894
+ * @returns Object containing metrics as key/value pairs.
895
+ *
896
+ * - `Timestamp` : The timestamp when the metrics sample was taken.
897
+ *
898
+ * - `Documents` : Number of documents in the page.
899
+ *
900
+ * - `Frames` : Number of frames in the page.
901
+ *
902
+ * - `JSEventListeners` : Number of events in the page.
903
+ *
904
+ * - `Nodes` : Number of DOM nodes in the page.
905
+ *
906
+ * - `LayoutCount` : Total number of full or partial page layout.
907
+ *
908
+ * - `RecalcStyleCount` : Total number of page style recalculations.
909
+ *
910
+ * - `LayoutDuration` : Combined durations of all page layouts.
911
+ *
912
+ * - `RecalcStyleDuration` : Combined duration of all page style
913
+ * recalculations.
914
+ *
915
+ * - `ScriptDuration` : Combined duration of JavaScript execution.
916
+ *
917
+ * - `TaskDuration` : Combined duration of all tasks performed by the browser.
918
+ *
919
+ *
920
+ * - `JSHeapUsedSize` : Used JavaScript heap size.
921
+ *
922
+ * - `JSHeapTotalSize` : Total JavaScript heap size.
923
+ * @remarks
924
+ * NOTE: All timestamps are in monotonic time: monotonically increasing time
925
+ * in seconds since an arbitrary point in the past.
926
+ */
680
927
  async metrics() {
681
928
  const response = await this._client.send('Performance.getMetrics');
682
929
  return this._buildMetricsObject(response.metrics);
@@ -808,18 +1055,134 @@ class Page extends EventEmitter_js_1.EventEmitter {
808
1055
  color: { r: 0, g: 0, b: 0, a: 0 },
809
1056
  });
810
1057
  }
1058
+ /**
1059
+ *
1060
+ * @returns
1061
+ * @remarks Shortcut for
1062
+ * {@link Frame.url | page.mainFrame().url()}.
1063
+ */
811
1064
  url() {
812
1065
  return this.mainFrame().url();
813
1066
  }
814
1067
  async content() {
815
1068
  return await this._frameManager.mainFrame().content();
816
1069
  }
1070
+ /**
1071
+ * @param html - HTML markup to assign to the page.
1072
+ * @param options - Parameters that has some properties.
1073
+ * @remarks
1074
+ * The parameter `options` might have the following options.
1075
+ *
1076
+ * - `timeout` : Maximum time in milliseconds for resources to load, defaults
1077
+ * to 30 seconds, pass `0` to disable timeout. The default value can be
1078
+ * changed by using the
1079
+ * {@link Page.setDefaultNavigationTimeout |
1080
+ * page.setDefaultNavigationTimeout(timeout)}
1081
+ * or {@link Page.setDefaultTimeout | page.setDefaultTimeout(timeout)}
1082
+ * methods.
1083
+ *
1084
+ * - `waitUntil`: When to consider setting markup succeeded, defaults to `load`.
1085
+ * Given an array of event strings, setting content is considered to be
1086
+ * successful after all events have been fired. Events can be either:<br/>
1087
+ * - `load` : consider setting content to be finished when the `load` event is
1088
+ * fired.<br/>
1089
+ * - `domcontentloaded` : consider setting content to be finished when the
1090
+ * `DOMContentLoaded` event is fired.<br/>
1091
+ * - `networkidle0` : consider setting content to be finished when there are no
1092
+ * more than 0 network connections for at least `500` ms.<br/>
1093
+ * - `networkidle2` : consider setting content to be finished when there are no
1094
+ * more than 2 network connections for at least `500` ms.
1095
+ */
817
1096
  async setContent(html, options = {}) {
818
1097
  await this._frameManager.mainFrame().setContent(html, options);
819
1098
  }
1099
+ /**
1100
+ * @param url - URL to navigate page to. The URL should include scheme, e.g.
1101
+ * `https://`
1102
+ * @param options - Navigation Parameter
1103
+ * @returns Promise which resolves to the main resource response. In case of
1104
+ * multiple redirects, the navigation will resolve with the response of the
1105
+ * last redirect.
1106
+ * @remarks
1107
+ * The argument `options` might have the following properties:
1108
+ *
1109
+ * - `timeout` : Maximum navigation time in milliseconds, defaults to 30
1110
+ * seconds, pass 0 to disable timeout. The default value can be changed by
1111
+ * using the
1112
+ * {@link Page.setDefaultNavigationTimeout |
1113
+ * page.setDefaultNavigationTimeout(timeout)}
1114
+ * or {@link Page.setDefaultTimeout | page.setDefaultTimeout(timeout)}
1115
+ * methods.
1116
+ *
1117
+ * - `waitUntil`:When to consider navigation succeeded, defaults to `load`.
1118
+ * Given an array of event strings, navigation is considered to be successful
1119
+ * after all events have been fired. Events can be either:<br/>
1120
+ * - `load` : consider navigation to be finished when the load event is
1121
+ * fired.<br/>
1122
+ * - `domcontentloaded` : consider navigation to be finished when the
1123
+ * DOMContentLoaded event is fired.<br/>
1124
+ * - `networkidle0` : consider navigation to be finished when there are no
1125
+ * more than 0 network connections for at least `500` ms.<br/>
1126
+ * - `networkidle2` : consider navigation to be finished when there are no
1127
+ * more than 2 network connections for at least `500` ms.
1128
+ *
1129
+ * - `referer` : Referer header value. If provided it will take preference
1130
+ * over the referer header value set by
1131
+ * {@link Page.setExtraHTTPHeaders |page.setExtraHTTPHeaders()}.
1132
+ *
1133
+ * `page.goto` will throw an error if:
1134
+ * - there's an SSL error (e.g. in case of self-signed certificates).
1135
+ * - target URL is invalid.
1136
+ * - the timeout is exceeded during navigation.
1137
+ * - the remote server does not respond or is unreachable.
1138
+ * - the main resource failed to load.
1139
+ *
1140
+ * `page.goto` will not throw an error when any valid HTTP status code is
1141
+ * returned by the remote server, including 404 "Not Found" and 500
1142
+ * "Internal Server Error". The status code for such responses can be
1143
+ * retrieved by calling response.status().
1144
+ *
1145
+ * NOTE: `page.goto` either throws an error or returns a main resource
1146
+ * response. The only exceptions are navigation to about:blank or navigation
1147
+ * to the same URL with a different hash, which would succeed and return null.
1148
+ *
1149
+ * NOTE: Headless mode doesn't support navigation to a PDF document. See the
1150
+ * {@link https://bugs.chromium.org/p/chromium/issues/detail?id=761295
1151
+ * | upstream issue}.
1152
+ *
1153
+ * Shortcut for {@link Frame.goto | page.mainFrame().goto(url, options)}.
1154
+ */
820
1155
  async goto(url, options = {}) {
821
1156
  return await this._frameManager.mainFrame().goto(url, options);
822
1157
  }
1158
+ /**
1159
+ * @param options - Navigation parameters which might have the following
1160
+ * properties:
1161
+ * @returns Promise which resolves to the main resource response. In case of
1162
+ * multiple redirects, the navigation will resolve with the response of the
1163
+ * last redirect.
1164
+ * @remarks
1165
+ * The argument `options` might have the following properties:
1166
+ *
1167
+ * - `timeout` : Maximum navigation time in milliseconds, defaults to 30
1168
+ * seconds, pass 0 to disable timeout. The default value can be changed by
1169
+ * using the
1170
+ * {@link Page.setDefaultNavigationTimeout |
1171
+ * page.setDefaultNavigationTimeout(timeout)}
1172
+ * or {@link Page.setDefaultTimeout | page.setDefaultTimeout(timeout)}
1173
+ * methods.
1174
+ *
1175
+ * - `waitUntil`: When to consider navigation succeeded, defaults to `load`.
1176
+ * Given an array of event strings, navigation is considered to be
1177
+ * successful after all events have been fired. Events can be either:<br/>
1178
+ * - `load` : consider navigation to be finished when the load event is fired.<br/>
1179
+ * - `domcontentloaded` : consider navigation to be finished when the
1180
+ * DOMContentLoaded event is fired.<br/>
1181
+ * - `networkidle0` : consider navigation to be finished when there are no
1182
+ * more than 0 network connections for at least `500` ms.<br/>
1183
+ * - `networkidle2` : consider navigation to be finished when there are no
1184
+ * more than 2 network connections for at least `500` ms.
1185
+ */
823
1186
  async reload(options) {
824
1187
  const result = await Promise.all([
825
1188
  this.waitForNavigation(options),
@@ -827,6 +1190,30 @@ class Page extends EventEmitter_js_1.EventEmitter {
827
1190
  ]);
828
1191
  return result[0];
829
1192
  }
1193
+ /**
1194
+ * This resolves when the page navigates to a new URL or reloads. It is useful
1195
+ * when you run code that will indirectly cause the page to navigate. Consider
1196
+ * this example:
1197
+ * ```js
1198
+ * const [response] = await Promise.all([
1199
+ * page.waitForNavigation(), // The promise resolves after navigation has finished
1200
+ * page.click('a.my-link'), // Clicking the link will indirectly cause a navigation
1201
+ * ]);
1202
+ * ```
1203
+ *
1204
+ * @param options - Navigation parameters which might have the following properties:
1205
+ * @returns Promise which resolves to the main resource response. In case of
1206
+ * multiple redirects, the navigation will resolve with the response of the
1207
+ * last redirect. In case of navigation to a different anchor or navigation
1208
+ * due to History API usage, the navigation will resolve with `null`.
1209
+ * @remarks
1210
+ * NOTE: Usage of the
1211
+ * {@link https://developer.mozilla.org/en-US/docs/Web/API/History_API | History API}
1212
+ * to change the URL is considered a navigation.
1213
+ *
1214
+ * Shortcut for
1215
+ * {@link Frame.waitForNavigation | page.mainFrame().waitForNavigation(options)}.
1216
+ */
830
1217
  async waitForNavigation(options = {}) {
831
1218
  return await this._frameManager.mainFrame().waitForNavigation(options);
832
1219
  }
@@ -835,6 +1222,31 @@ class Page extends EventEmitter_js_1.EventEmitter {
835
1222
  this._disconnectPromise = new Promise((fulfill) => this._client.once(Connection_js_1.CDPSessionEmittedEvents.Disconnected, () => fulfill(new Error('Target closed'))));
836
1223
  return this._disconnectPromise;
837
1224
  }
1225
+ /**
1226
+ * @param urlOrPredicate - A URL or predicate to wait for
1227
+ * @param options - Optional waiting parameters
1228
+ * @returns Promise which resolves to the matched response
1229
+ * @example
1230
+ * ```js
1231
+ * const firstResponse = await page.waitForResponse(
1232
+ * 'https://example.com/resource'
1233
+ * );
1234
+ * const finalResponse = await page.waitForResponse(
1235
+ * (response) =>
1236
+ * response.url() === 'https://example.com' && response.status() === 200
1237
+ * );
1238
+ * const finalResponse = await page.waitForResponse(async (response) => {
1239
+ * return (await response.text()).includes('<html>');
1240
+ * });
1241
+ * return finalResponse.ok();
1242
+ * ```
1243
+ * @remarks
1244
+ * Optional Waiting Parameters have:
1245
+ *
1246
+ * - `timeout`: Maximum wait time in milliseconds, defaults to `30` seconds, pass
1247
+ * `0` to disable the timeout. The default value can be changed by using the
1248
+ * {@link Page.setDefaultTimeout} method.
1249
+ */
838
1250
  async waitForRequest(urlOrPredicate, options = {}) {
839
1251
  const { timeout = this._timeoutSettings.timeout() } = options;
840
1252
  return helper_js_1.helper.waitForEvent(this._frameManager.networkManager(), NetworkManager_js_1.NetworkManagerEmittedEvents.Request, (request) => {
@@ -845,6 +1257,31 @@ class Page extends EventEmitter_js_1.EventEmitter {
845
1257
  return false;
846
1258
  }, timeout, this._sessionClosePromise());
847
1259
  }
1260
+ /**
1261
+ * @param urlOrPredicate - A URL or predicate to wait for.
1262
+ * @param options - Optional waiting parameters
1263
+ * @returns Promise which resolves to the matched response.
1264
+ * @example
1265
+ * ```js
1266
+ * const firstResponse = await page.waitForResponse(
1267
+ * 'https://example.com/resource'
1268
+ * );
1269
+ * const finalResponse = await page.waitForResponse(
1270
+ * (response) =>
1271
+ * response.url() === 'https://example.com' && response.status() === 200
1272
+ * );
1273
+ * const finalResponse = await page.waitForResponse(async (response) => {
1274
+ * return (await response.text()).includes('<html>');
1275
+ * });
1276
+ * return finalResponse.ok();
1277
+ * ```
1278
+ * @remarks
1279
+ * Optional Parameter have:
1280
+ *
1281
+ * - `timeout`: Maximum wait time in milliseconds, defaults to `30` seconds,
1282
+ * pass `0` to disable the timeout. The default value can be changed by using
1283
+ * the {@link Page.setDefaultTimeout} method.
1284
+ */
848
1285
  async waitForResponse(urlOrPredicate, options = {}) {
849
1286
  const { timeout = this._timeoutSettings.timeout() } = options;
850
1287
  return helper_js_1.helper.waitForEvent(this._frameManager.networkManager(), NetworkManager_js_1.NetworkManagerEmittedEvents.Response, async (response) => {
@@ -855,9 +1292,113 @@ class Page extends EventEmitter_js_1.EventEmitter {
855
1292
  return false;
856
1293
  }, timeout, this._sessionClosePromise());
857
1294
  }
1295
+ /**
1296
+ * @param options - Optional waiting parameters
1297
+ * @returns Promise which resolves when network is idle
1298
+ */
1299
+ async waitForNetworkIdle(options = {}) {
1300
+ const { idleTime = 500, timeout = this._timeoutSettings.timeout() } = options;
1301
+ const networkManager = this._frameManager.networkManager();
1302
+ let idleResolveCallback;
1303
+ const idlePromise = new Promise((resolve) => {
1304
+ idleResolveCallback = resolve;
1305
+ });
1306
+ let abortRejectCallback;
1307
+ const abortPromise = new Promise((_, reject) => {
1308
+ abortRejectCallback = reject;
1309
+ });
1310
+ let idleTimer;
1311
+ const onIdle = () => idleResolveCallback();
1312
+ const cleanup = () => {
1313
+ idleTimer && clearTimeout(idleTimer);
1314
+ abortRejectCallback(new Error('abort'));
1315
+ };
1316
+ const evaluate = () => {
1317
+ idleTimer && clearTimeout(idleTimer);
1318
+ if (networkManager.numRequestsInProgress() === 0)
1319
+ idleTimer = setTimeout(onIdle, idleTime);
1320
+ };
1321
+ evaluate();
1322
+ const eventHandler = () => {
1323
+ evaluate();
1324
+ return false;
1325
+ };
1326
+ const listenToEvent = (event) => helper_js_1.helper.waitForEvent(networkManager, event, eventHandler, timeout, abortPromise);
1327
+ const eventPromises = [
1328
+ listenToEvent(NetworkManager_js_1.NetworkManagerEmittedEvents.Request),
1329
+ listenToEvent(NetworkManager_js_1.NetworkManagerEmittedEvents.Response),
1330
+ ];
1331
+ await Promise.race([
1332
+ idlePromise,
1333
+ ...eventPromises,
1334
+ this._sessionClosePromise(),
1335
+ ]).then((r) => {
1336
+ cleanup();
1337
+ return r;
1338
+ }, (error) => {
1339
+ cleanup();
1340
+ throw error;
1341
+ });
1342
+ }
1343
+ /**
1344
+ * This method navigate to the previous page in history.
1345
+ * @param options - Navigation parameters
1346
+ * @returns Promise which resolves to the main resource response. In case of
1347
+ * multiple redirects, the navigation will resolve with the response of the
1348
+ * last redirect. If can not go back, resolves to `null`.
1349
+ * @remarks
1350
+ * The argument `options` might have the following properties:
1351
+ *
1352
+ * - `timeout` : Maximum navigation time in milliseconds, defaults to 30
1353
+ * seconds, pass 0 to disable timeout. The default value can be changed by
1354
+ * using the
1355
+ * {@link Page.setDefaultNavigationTimeout
1356
+ * | page.setDefaultNavigationTimeout(timeout)}
1357
+ * or {@link Page.setDefaultTimeout | page.setDefaultTimeout(timeout)}
1358
+ * methods.
1359
+ *
1360
+ * - `waitUntil` : When to consider navigation succeeded, defaults to `load`.
1361
+ * Given an array of event strings, navigation is considered to be
1362
+ * successful after all events have been fired. Events can be either:<br/>
1363
+ * - `load` : consider navigation to be finished when the load event is fired.<br/>
1364
+ * - `domcontentloaded` : consider navigation to be finished when the
1365
+ * DOMContentLoaded event is fired.<br/>
1366
+ * - `networkidle0` : consider navigation to be finished when there are no
1367
+ * more than 0 network connections for at least `500` ms.<br/>
1368
+ * - `networkidle2` : consider navigation to be finished when there are no
1369
+ * more than 2 network connections for at least `500` ms.
1370
+ */
858
1371
  async goBack(options = {}) {
859
1372
  return this._go(-1, options);
860
1373
  }
1374
+ /**
1375
+ * This method navigate to the next page in history.
1376
+ * @param options - Navigation Parameter
1377
+ * @returns Promise which resolves to the main resource response. In case of
1378
+ * multiple redirects, the navigation will resolve with the response of the
1379
+ * last redirect. If can not go forward, resolves to `null`.
1380
+ * @remarks
1381
+ * The argument `options` might have the following properties:
1382
+ *
1383
+ * - `timeout` : Maximum navigation time in milliseconds, defaults to 30
1384
+ * seconds, pass 0 to disable timeout. The default value can be changed by
1385
+ * using the
1386
+ * {@link Page.setDefaultNavigationTimeout
1387
+ * | page.setDefaultNavigationTimeout(timeout)}
1388
+ * or {@link Page.setDefaultTimeout | page.setDefaultTimeout(timeout)}
1389
+ * methods.
1390
+ *
1391
+ * - `waitUntil`: When to consider navigation succeeded, defaults to `load`.
1392
+ * Given an array of event strings, navigation is considered to be
1393
+ * successful after all events have been fired. Events can be either:<br/>
1394
+ * - `load` : consider navigation to be finished when the load event is fired.<br/>
1395
+ * - `domcontentloaded` : consider navigation to be finished when the
1396
+ * DOMContentLoaded event is fired.<br/>
1397
+ * - `networkidle0` : consider navigation to be finished when there are no
1398
+ * more than 0 network connections for at least `500` ms.<br/>
1399
+ * - `networkidle2` : consider navigation to be finished when there are no
1400
+ * more than 2 network connections for at least `500` ms.
1401
+ */
861
1402
  async goForward(options = {}) {
862
1403
  return this._go(+1, options);
863
1404
  }
@@ -872,15 +1413,48 @@ class Page extends EventEmitter_js_1.EventEmitter {
872
1413
  ]);
873
1414
  return result[0];
874
1415
  }
1416
+ /**
1417
+ * Brings page to front (activates tab).
1418
+ */
875
1419
  async bringToFront() {
876
1420
  await this._client.send('Page.bringToFront');
877
1421
  }
1422
+ /**
1423
+ * Emulates given device metrics and user agent. This method is a shortcut for
1424
+ * calling two methods: {@link Page.setUserAgent} and {@link Page.setViewport}
1425
+ * To aid emulation, Puppeteer provides a list of device descriptors that can
1426
+ * be obtained via the {@link Puppeteer.devices} `page.emulate` will resize
1427
+ * the page. A lot of websites don't expect phones to change size, so you
1428
+ * should emulate before navigating to the page.
1429
+ * @example
1430
+ * ```js
1431
+ * const puppeteer = require('puppeteer');
1432
+ * const iPhone = puppeteer.devices['iPhone 6'];
1433
+ * (async () => {
1434
+ * const browser = await puppeteer.launch();
1435
+ * const page = await browser.newPage();
1436
+ * await page.emulate(iPhone);
1437
+ * await page.goto('https://www.google.com');
1438
+ * // other actions...
1439
+ * await browser.close();
1440
+ * })();
1441
+ * ```
1442
+ * @remarks List of all available devices is available in the source code:
1443
+ * {@link https://github.com/puppeteer/puppeteer/blob/main/src/common/DeviceDescriptors.ts | src/common/DeviceDescriptors.ts}.
1444
+ */
878
1445
  async emulate(options) {
879
1446
  await Promise.all([
880
1447
  this.setViewport(options.viewport),
881
1448
  this.setUserAgent(options.userAgent),
882
1449
  ]);
883
1450
  }
1451
+ /**
1452
+ * @param enabled - Whether or not to enable JavaScript on the page.
1453
+ * @returns
1454
+ * @remarks
1455
+ * NOTE: changing this value won't affect scripts that have already been run.
1456
+ * It will take full effect on the next navigation.
1457
+ */
884
1458
  async setJavaScriptEnabled(enabled) {
885
1459
  if (this._javascriptEnabled === enabled)
886
1460
  return;
@@ -889,15 +1463,105 @@ class Page extends EventEmitter_js_1.EventEmitter {
889
1463
  value: !enabled,
890
1464
  });
891
1465
  }
1466
+ /**
1467
+ * Toggles bypassing page's Content-Security-Policy.
1468
+ * @param enabled - sets bypassing of page's Content-Security-Policy.
1469
+ * @remarks
1470
+ * NOTE: CSP bypassing happens at the moment of CSP initialization rather than
1471
+ * evaluation. Usually, this means that `page.setBypassCSP` should be called
1472
+ * before navigating to the domain.
1473
+ */
892
1474
  async setBypassCSP(enabled) {
893
1475
  await this._client.send('Page.setBypassCSP', { enabled });
894
1476
  }
1477
+ /**
1478
+ * @param type - Changes the CSS media type of the page. The only allowed
1479
+ * values are `screen`, `print` and `null`. Passing `null` disables CSS media
1480
+ * emulation.
1481
+ * @example
1482
+ * ```
1483
+ * await page.evaluate(() => matchMedia('screen').matches);
1484
+ * // → true
1485
+ * await page.evaluate(() => matchMedia('print').matches);
1486
+ * // → false
1487
+ *
1488
+ * await page.emulateMediaType('print');
1489
+ * await page.evaluate(() => matchMedia('screen').matches);
1490
+ * // → false
1491
+ * await page.evaluate(() => matchMedia('print').matches);
1492
+ * // → true
1493
+ *
1494
+ * await page.emulateMediaType(null);
1495
+ * await page.evaluate(() => matchMedia('screen').matches);
1496
+ * // → true
1497
+ * await page.evaluate(() => matchMedia('print').matches);
1498
+ * // → false
1499
+ * ```
1500
+ */
895
1501
  async emulateMediaType(type) {
896
1502
  assert_js_1.assert(type === 'screen' || type === 'print' || type === null, 'Unsupported media type: ' + type);
897
1503
  await this._client.send('Emulation.setEmulatedMedia', {
898
1504
  media: type || '',
899
1505
  });
900
1506
  }
1507
+ async emulateCPUThrottling(factor) {
1508
+ assert_js_1.assert(factor === null || factor >= 1, 'Throttling rate should be greater or equal to 1');
1509
+ await this._client.send('Emulation.setCPUThrottlingRate', {
1510
+ rate: factor !== null ? factor : 1,
1511
+ });
1512
+ }
1513
+ /**
1514
+ * @param features - `<?Array<Object>>` Given an array of media feature
1515
+ * objects, emulates CSS media features on the page. Each media feature object
1516
+ * must have the following properties:
1517
+ * @example
1518
+ * ```js
1519
+ * await page.emulateMediaFeatures([
1520
+ * { name: 'prefers-color-scheme', value: 'dark' },
1521
+ * ]);
1522
+ * await page.evaluate(() => matchMedia('(prefers-color-scheme: dark)').matches);
1523
+ * // → true
1524
+ * await page.evaluate(() => matchMedia('(prefers-color-scheme: light)').matches);
1525
+ * // → false
1526
+ *
1527
+ * await page.emulateMediaFeatures([
1528
+ * { name: 'prefers-reduced-motion', value: 'reduce' },
1529
+ * ]);
1530
+ * await page.evaluate(
1531
+ * () => matchMedia('(prefers-reduced-motion: reduce)').matches
1532
+ * );
1533
+ * // → true
1534
+ * await page.evaluate(
1535
+ * () => matchMedia('(prefers-reduced-motion: no-preference)').matches
1536
+ * );
1537
+ * // → false
1538
+ *
1539
+ * await page.emulateMediaFeatures([
1540
+ * { name: 'prefers-color-scheme', value: 'dark' },
1541
+ * { name: 'prefers-reduced-motion', value: 'reduce' },
1542
+ * ]);
1543
+ * await page.evaluate(() => matchMedia('(prefers-color-scheme: dark)').matches);
1544
+ * // → true
1545
+ * await page.evaluate(() => matchMedia('(prefers-color-scheme: light)').matches);
1546
+ * // → false
1547
+ * await page.evaluate(
1548
+ * () => matchMedia('(prefers-reduced-motion: reduce)').matches
1549
+ * );
1550
+ * // → true
1551
+ * await page.evaluate(
1552
+ * () => matchMedia('(prefers-reduced-motion: no-preference)').matches
1553
+ * );
1554
+ * // → false
1555
+ *
1556
+ * await page.emulateMediaFeatures([{ name: 'color-gamut', value: 'p3' }]);
1557
+ * await page.evaluate(() => matchMedia('(color-gamut: srgb)').matches);
1558
+ * // → true
1559
+ * await page.evaluate(() => matchMedia('(color-gamut: p3)').matches);
1560
+ * // → true
1561
+ * await page.evaluate(() => matchMedia('(color-gamut: rec2020)').matches);
1562
+ * // → false
1563
+ * ```
1564
+ */
901
1565
  async emulateMediaFeatures(features) {
902
1566
  if (features === null)
903
1567
  await this._client.send('Emulation.setEmulatedMedia', { features: null });
@@ -912,6 +1576,12 @@ class Page extends EventEmitter_js_1.EventEmitter {
912
1576
  });
913
1577
  }
914
1578
  }
1579
+ /**
1580
+ * @param timezoneId - Changes the timezone of the page. See
1581
+ * {@link https://source.chromium.org/chromium/chromium/deps/icu.git/+/faee8bc70570192d82d2978a71e2a615788597d1:source/data/misc/metaZones.txt | ICU’s metaZones.txt}
1582
+ * for a list of supported timezone IDs. Passing
1583
+ * `null` disables timezone emulation.
1584
+ */
915
1585
  async emulateTimezone(timezoneId) {
916
1586
  try {
917
1587
  await this._client.send('Emulation.setTimezoneOverride', {
@@ -941,8 +1611,6 @@ class Page extends EventEmitter_js_1.EventEmitter {
941
1611
  * ```
942
1612
  *
943
1613
  * @param overrides - Mock idle state. If not set, clears idle overrides
944
- * @param isUserActive - Mock isUserActive
945
- * @param isScreenUnlocked - Mock isScreenUnlocked
946
1614
  */
947
1615
  async emulateIdleState(overrides) {
948
1616
  if (overrides) {
@@ -1001,12 +1669,70 @@ class Page extends EventEmitter_js_1.EventEmitter {
1001
1669
  throw error;
1002
1670
  }
1003
1671
  }
1672
+ /**
1673
+ * `page.setViewport` will resize the page. A lot of websites don't expect
1674
+ * phones to change size, so you should set the viewport before navigating to
1675
+ * the page.
1676
+ *
1677
+ * In the case of multiple pages in a single browser, each page can have its
1678
+ * own viewport size.
1679
+ * @example
1680
+ * ```js
1681
+ * const page = await browser.newPage();
1682
+ * await page.setViewport({
1683
+ * width: 640,
1684
+ * height: 480,
1685
+ * deviceScaleFactor: 1,
1686
+ * });
1687
+ * await page.goto('https://example.com');
1688
+ * ```
1689
+ *
1690
+ * @param viewport -
1691
+ * @remarks
1692
+ * Argument viewport have following properties:
1693
+ *
1694
+ * - `width`: page width in pixels. required
1695
+ *
1696
+ * - `height`: page height in pixels. required
1697
+ *
1698
+ * - `deviceScaleFactor`: Specify device scale factor (can be thought of as
1699
+ * DPR). Defaults to `1`.
1700
+ *
1701
+ * - `isMobile`: Whether the meta viewport tag is taken into account. Defaults
1702
+ * to `false`.
1703
+ *
1704
+ * - `hasTouch`: Specifies if viewport supports touch events. Defaults to `false`
1705
+ *
1706
+ * - `isLandScape`: Specifies if viewport is in landscape mode. Defaults to false.
1707
+ *
1708
+ * NOTE: in certain cases, setting viewport will reload the page in order to
1709
+ * set the isMobile or hasTouch properties.
1710
+ */
1004
1711
  async setViewport(viewport) {
1005
1712
  const needsReload = await this._emulationManager.emulateViewport(viewport);
1006
1713
  this._viewport = viewport;
1007
1714
  if (needsReload)
1008
1715
  await this.reload();
1009
1716
  }
1717
+ /**
1718
+ * @returns
1719
+ *
1720
+ * - `width`: page's width in pixels
1721
+ *
1722
+ * - `height`: page's height in pixels
1723
+ *
1724
+ * - `deviceScalarFactor`: Specify device scale factor (can be though of as
1725
+ * dpr). Defaults to `1`.
1726
+ *
1727
+ * - `isMobile`: Whether the meta viewport tag is taken into account. Defaults
1728
+ * to `false`.
1729
+ *
1730
+ * - `hasTouch`: Specifies if viewport supports touch events. Defaults to
1731
+ * `false`.
1732
+ *
1733
+ * - `isLandScape`: Specifies if viewport is in landscape mode. Defaults to
1734
+ * `false`.
1735
+ */
1010
1736
  viewport() {
1011
1737
  return this._viewport;
1012
1738
  }
@@ -1061,22 +1787,100 @@ class Page extends EventEmitter_js_1.EventEmitter {
1061
1787
  async evaluate(pageFunction, ...args) {
1062
1788
  return this._frameManager.mainFrame().evaluate(pageFunction, ...args);
1063
1789
  }
1790
+ /**
1791
+ * Adds a function which would be invoked in one of the following scenarios:
1792
+ *
1793
+ * - whenever the page is navigated
1794
+ *
1795
+ * - whenever the child frame is attached or navigated. In this case, the
1796
+ * function is invoked in the context of the newly attached frame.
1797
+ *
1798
+ * The function is invoked after the document was created but before any of
1799
+ * its scripts were run. This is useful to amend the JavaScript environment,
1800
+ * e.g. to seed `Math.random`.
1801
+ * @param pageFunction - Function to be evaluated in browser context
1802
+ * @param args - Arguments to pass to `pageFunction`
1803
+ * @example
1804
+ * An example of overriding the navigator.languages property before the page loads:
1805
+ * ```js
1806
+ * // preload.js
1807
+ *
1808
+ * // overwrite the `languages` property to use a custom getter
1809
+ * Object.defineProperty(navigator, 'languages', {
1810
+ * get: function () {
1811
+ * return ['en-US', 'en', 'bn'];
1812
+ * },
1813
+ * });
1814
+ *
1815
+ * // In your puppeteer script, assuming the preload.js file is
1816
+ * in same folder of our script
1817
+ * const preloadFile = fs.readFileSync('./preload.js', 'utf8');
1818
+ * await page.evaluateOnNewDocument(preloadFile);
1819
+ * ```
1820
+ */
1064
1821
  async evaluateOnNewDocument(pageFunction, ...args) {
1065
1822
  const source = helper_js_1.helper.evaluationString(pageFunction, ...args);
1066
1823
  await this._client.send('Page.addScriptToEvaluateOnNewDocument', {
1067
1824
  source,
1068
1825
  });
1069
1826
  }
1827
+ /**
1828
+ * Toggles ignoring cache for each request based on the enabled state. By
1829
+ * default, caching is enabled.
1830
+ * @param enabled - sets the `enabled` state of cache
1831
+ */
1070
1832
  async setCacheEnabled(enabled = true) {
1071
1833
  await this._frameManager.networkManager().setCacheEnabled(enabled);
1072
1834
  }
1835
+ /**
1836
+ * @remarks
1837
+ * Options object which might have the following properties:
1838
+ *
1839
+ * - `path` : The file path to save the image to. The screenshot type
1840
+ * will be inferred from file extension. If `path` is a relative path, then
1841
+ * it is resolved relative to
1842
+ * {@link https://nodejs.org/api/process.html#process_process_cwd
1843
+ * | current working directory}.
1844
+ * If no path is provided, the image won't be saved to the disk.
1845
+ *
1846
+ * - `type` : Specify screenshot type, can be either `jpeg` or `png`.
1847
+ * Defaults to 'png'.
1848
+ *
1849
+ * - `quality` : The quality of the image, between 0-100. Not
1850
+ * applicable to `png` images.
1851
+ *
1852
+ * - `fullPage` : When true, takes a screenshot of the full
1853
+ * scrollable page. Defaults to `false`
1854
+ *
1855
+ * - `clip` : An object which specifies clipping region of the page.
1856
+ * Should have the following fields:<br/>
1857
+ * - `x` : x-coordinate of top-left corner of clip area.<br/>
1858
+ * - `y` : y-coordinate of top-left corner of clip area.<br/>
1859
+ * - `width` : width of clipping area.<br/>
1860
+ * - `height` : height of clipping area.
1861
+ *
1862
+ * - `omitBackground` : Hides default white background and allows
1863
+ * capturing screenshots with transparency. Defaults to `false`
1864
+ *
1865
+ * - `encoding` : The encoding of the image, can be either base64 or
1866
+ * binary. Defaults to `binary`.
1867
+ *
1868
+ *
1869
+ * NOTE: Screenshots take at least 1/6 second on OS X. See
1870
+ * {@link https://crbug.com/741689} for discussion.
1871
+ * @returns Promise which resolves to buffer or a base64 string (depending on
1872
+ * the value of `encoding`) with captured screenshot.
1873
+ */
1073
1874
  async screenshot(options = {}) {
1074
1875
  let screenshotType = null;
1075
1876
  // options.type takes precedence over inferring the type from options.path
1076
1877
  // because it may be a 0-length file with no extension created beforehand
1077
1878
  // (i.e. as a temp file).
1078
1879
  if (options.type) {
1079
- assert_js_1.assert(options.type === 'png' || options.type === 'jpeg', 'Unknown options.type value: ' + options.type);
1880
+ const type = options.type;
1881
+ if (type !== 'png' && type !== 'jpeg' && type !== 'webp') {
1882
+ assert_js_1.assertNever(type, 'Unknown options.type value: ' + type);
1883
+ }
1080
1884
  screenshotType = options.type;
1081
1885
  }
1082
1886
  else if (options.path) {
@@ -1088,6 +1892,8 @@ class Page extends EventEmitter_js_1.EventEmitter {
1088
1892
  screenshotType = 'png';
1089
1893
  else if (extension === 'jpg' || extension === 'jpeg')
1090
1894
  screenshotType = 'jpeg';
1895
+ else if (extension === 'webp')
1896
+ screenshotType = 'webp';
1091
1897
  assert_js_1.assert(screenshotType, `Unsupported screenshot type for extension \`.${extension}\``);
1092
1898
  }
1093
1899
  if (!screenshotType)
@@ -1127,8 +1933,8 @@ class Page extends EventEmitter_js_1.EventEmitter {
1127
1933
  typeof captureBeyondViewport === 'boolean' ? captureBeyondViewport : true;
1128
1934
  if (options.fullPage) {
1129
1935
  const metrics = await this._client.send('Page.getLayoutMetrics');
1130
- const width = Math.ceil(metrics.contentSize.width);
1131
- const height = Math.ceil(metrics.contentSize.height);
1936
+ // Fallback to `contentSize` in case of using Firefox.
1937
+ const { width, height } = metrics.cssContentSize || metrics.contentSize;
1132
1938
  // Overwrite clip for full page.
1133
1939
  clip = { x: 0, y: 0, width, height, scale: 1 };
1134
1940
  if (!captureBeyondViewport) {
@@ -1145,7 +1951,7 @@ class Page extends EventEmitter_js_1.EventEmitter {
1145
1951
  });
1146
1952
  }
1147
1953
  }
1148
- const shouldSetDefaultBackground = options.omitBackground && format === 'png';
1954
+ const shouldSetDefaultBackground = options.omitBackground && (format === 'png' || format === 'webp');
1149
1955
  if (shouldSetDefaultBackground) {
1150
1956
  await this._setTransparentBackgroundColor();
1151
1957
  }
@@ -1183,7 +1989,7 @@ class Page extends EventEmitter_js_1.EventEmitter {
1183
1989
  * Generatees a PDF of the page with the `print` CSS media type.
1184
1990
  * @remarks
1185
1991
  *
1186
- * IMPORTANT: PDF generation is only supported in Chrome headless mode.
1992
+ * NOTE: PDF generation is only supported in Chrome headless mode.
1187
1993
  *
1188
1994
  * To generate a PDF with the `screen` media type, call
1189
1995
  * {@link Page.emulateMediaType | `page.emulateMediaType('screen')`} before
@@ -1197,8 +2003,8 @@ class Page extends EventEmitter_js_1.EventEmitter {
1197
2003
  *
1198
2004
  * @param options - options for generating the PDF.
1199
2005
  */
1200
- async pdf(options = {}) {
1201
- const { scale = 1, displayHeaderFooter = false, headerTemplate = '', footerTemplate = '', printBackground = false, landscape = false, pageRanges = '', preferCSSPageSize = false, margin = {}, path = null, omitBackground = false, } = options;
2006
+ async createPDFStream(options = {}) {
2007
+ const { scale = 1, displayHeaderFooter = false, headerTemplate = '', footerTemplate = '', printBackground = false, landscape = false, pageRanges = '', preferCSSPageSize = false, margin = {}, omitBackground = false, timeout = 30000, } = options;
1202
2008
  let paperWidth = 8.5;
1203
2009
  let paperHeight = 11;
1204
2010
  if (options.format) {
@@ -1219,7 +2025,7 @@ class Page extends EventEmitter_js_1.EventEmitter {
1219
2025
  if (omitBackground) {
1220
2026
  await this._setTransparentBackgroundColor();
1221
2027
  }
1222
- const result = await this._client.send('Page.printToPDF', {
2028
+ const printCommandPromise = this._client.send('Page.printToPDF', {
1223
2029
  transferMode: 'ReturnAsStream',
1224
2030
  landscape,
1225
2031
  displayHeaderFooter,
@@ -1236,11 +2042,26 @@ class Page extends EventEmitter_js_1.EventEmitter {
1236
2042
  pageRanges,
1237
2043
  preferCSSPageSize,
1238
2044
  });
2045
+ const result = await helper_js_1.helper.waitWithTimeout(printCommandPromise, 'Page.printToPDF', timeout);
1239
2046
  if (omitBackground) {
1240
2047
  await this._resetDefaultBackgroundColor();
1241
2048
  }
1242
- return await helper_js_1.helper.readProtocolStream(this._client, result.stream, path);
2049
+ return helper_js_1.helper.getReadableFromProtocolStream(this._client, result.stream);
1243
2050
  }
2051
+ /**
2052
+ * @param options -
2053
+ * @returns
2054
+ */
2055
+ async pdf(options = {}) {
2056
+ const { path = undefined } = options;
2057
+ const readable = await this.createPDFStream(options);
2058
+ return await helper_js_1.helper.getReadableAsBuffer(readable, path);
2059
+ }
2060
+ /**
2061
+ * @returns The page's title
2062
+ * @remarks
2063
+ * Shortcut for {@link Frame.title | page.mainFrame().title()}.
2064
+ */
1244
2065
  async title() {
1245
2066
  return this.mainFrame().title();
1246
2067
  }
@@ -1257,27 +2078,136 @@ class Page extends EventEmitter_js_1.EventEmitter {
1257
2078
  await this._target._isClosedPromise;
1258
2079
  }
1259
2080
  }
2081
+ /**
2082
+ * Indicates that the page has been closed.
2083
+ * @returns
2084
+ */
1260
2085
  isClosed() {
1261
2086
  return this._closed;
1262
2087
  }
1263
2088
  get mouse() {
1264
2089
  return this._mouse;
1265
2090
  }
2091
+ /**
2092
+ * This method fetches an element with `selector`, scrolls it into view if
2093
+ * needed, and then uses {@link Page.mouse} to click in the center of the
2094
+ * element. If there's no element matching `selector`, the method throws an
2095
+ * error.
2096
+ * @remarks Bear in mind that if `click()` triggers a navigation event and
2097
+ * there's a separate `page.waitForNavigation()` promise to be resolved, you
2098
+ * may end up with a race condition that yields unexpected results. The
2099
+ * correct pattern for click and wait for navigation is the following:
2100
+ * ```js
2101
+ * const [response] = await Promise.all([
2102
+ * page.waitForNavigation(waitOptions),
2103
+ * page.click(selector, clickOptions),
2104
+ * ]);
2105
+ * ```
2106
+ * Shortcut for {@link Frame.click | page.mainFrame().click(selector[, options]) }.
2107
+ * @param selector - A `selector` to search for element to click. If there are
2108
+ * multiple elements satisfying the `selector`, the first will be clicked
2109
+ * @param options - `Object`
2110
+ * @returns Promise which resolves when the element matching `selector` is
2111
+ * successfully clicked. The Promise will be rejected if there is no element
2112
+ * matching `selector`.
2113
+ */
1266
2114
  click(selector, options = {}) {
1267
2115
  return this.mainFrame().click(selector, options);
1268
2116
  }
2117
+ /**
2118
+ * This method fetches an element with `selector` and focuses it. If there's no
2119
+ * element matching `selector`, the method throws an error.
2120
+ * @param selector - A
2121
+ * {@link https://developer.mozilla.org/en-US/docs/Web/CSS/CSS_Selectors | selector }
2122
+ * of an element to focus. If there are multiple elements satisfying the
2123
+ * selector, the first will be focused.
2124
+ * @returns Promise which resolves when the element matching selector is
2125
+ * successfully focused. The promise will be rejected if there is no element
2126
+ * matching selector.
2127
+ * @remarks
2128
+ * Shortcut for {@link Frame.focus | page.mainFrame().focus(selector)}.
2129
+ */
1269
2130
  focus(selector) {
1270
2131
  return this.mainFrame().focus(selector);
1271
2132
  }
2133
+ /**
2134
+ * This method fetches an element with `selector`, scrolls it into view if
2135
+ * needed, and then uses {@link Page.mouse} to hover over the center of the element.
2136
+ * If there's no element matching `selector`, the method throws an error.
2137
+ * @param selector - A
2138
+ * {@link https://developer.mozilla.org/en-US/docs/Web/CSS/CSS_Selectors | selector}
2139
+ * to search for element to hover. If there are multiple elements satisfying
2140
+ * the selector, the first will be hovered.
2141
+ * @returns Promise which resolves when the element matching `selector` is
2142
+ * successfully hovered. Promise gets rejected if there's no element matching
2143
+ * `selector`.
2144
+ * @remarks
2145
+ * Shortcut for {@link Page.hover | page.mainFrame().hover(selector)}.
2146
+ */
1272
2147
  hover(selector) {
1273
2148
  return this.mainFrame().hover(selector);
1274
2149
  }
2150
+ /**
2151
+ * Triggers a `change` and `input` event once all the provided options have been
2152
+ * selected. If there's no `<select>` element matching `selector`, the method
2153
+ * throws an error.
2154
+ *
2155
+ * @example
2156
+ * ```js
2157
+ * page.select('select#colors', 'blue'); // single selection
2158
+ * page.select('select#colors', 'red', 'green', 'blue'); // multiple selections
2159
+ * ```
2160
+ * @param selector - A
2161
+ * {@link https://developer.mozilla.org/en-US/docs/Web/CSS/CSS_Selectors | Selector}
2162
+ * to query the page for
2163
+ * @param values - Values of options to select. If the `<select>` has the
2164
+ * `multiple` attribute, all values are considered, otherwise only the first one
2165
+ * is taken into account.
2166
+ * @returns
2167
+ *
2168
+ * @remarks
2169
+ * Shortcut for {@link Frame.select | page.mainFrame().select()}
2170
+ */
1275
2171
  select(selector, ...values) {
1276
2172
  return this.mainFrame().select(selector, ...values);
1277
2173
  }
2174
+ /**
2175
+ * This method fetches an element with `selector`, scrolls it into view if
2176
+ * needed, and then uses {@link Page.touchscreen} to tap in the center of the element.
2177
+ * If there's no element matching `selector`, the method throws an error.
2178
+ * @param selector - A
2179
+ * {@link https://developer.mozilla.org/en-US/docs/Web/CSS/CSS_Selectors | Selector}
2180
+ * to search for element to tap. If there are multiple elements satisfying the
2181
+ * selector, the first will be tapped.
2182
+ * @returns
2183
+ * @remarks
2184
+ * Shortcut for {@link Frame.tap | page.mainFrame().tap(selector)}.
2185
+ */
1278
2186
  tap(selector) {
1279
2187
  return this.mainFrame().tap(selector);
1280
2188
  }
2189
+ /**
2190
+ * Sends a `keydown`, `keypress/input`, and `keyup` event for each character
2191
+ * in the text.
2192
+ *
2193
+ * To press a special key, like `Control` or `ArrowDown`, use {@link Keyboard.press}.
2194
+ * @example
2195
+ * ```
2196
+ * await page.type('#mytextarea', 'Hello');
2197
+ * // Types instantly
2198
+ * await page.type('#mytextarea', 'World', { delay: 100 });
2199
+ * // Types slower, like a user
2200
+ * ```
2201
+ * @param selector - A
2202
+ * {@link https://developer.mozilla.org/en-US/docs/Web/CSS/CSS_Selectors | selector}
2203
+ * of an element to type into. If there are multiple elements satisfying the
2204
+ * selector, the first will be used.
2205
+ * @param text - A text to type into a focused element.
2206
+ * @param options - have property `delay` which is the Time to wait between
2207
+ * key presses in milliseconds. Defaults to `0`.
2208
+ * @returns
2209
+ * @remarks
2210
+ */
1281
2211
  type(selector, text, options) {
1282
2212
  return this.mainFrame().type(selector, text, options);
1283
2213
  }
@@ -1331,12 +2261,174 @@ class Page extends EventEmitter_js_1.EventEmitter {
1331
2261
  waitForTimeout(milliseconds) {
1332
2262
  return this.mainFrame().waitForTimeout(milliseconds);
1333
2263
  }
2264
+ /**
2265
+ * Wait for the `selector` to appear in page. If at the moment of calling the
2266
+ * method the `selector` already exists, the method will return immediately. If
2267
+ * the `selector` doesn't appear after the `timeout` milliseconds of waiting, the
2268
+ * function will throw.
2269
+ *
2270
+ * This method works across navigations:
2271
+ * ```js
2272
+ * const puppeteer = require('puppeteer');
2273
+ * (async () => {
2274
+ * const browser = await puppeteer.launch();
2275
+ * const page = await browser.newPage();
2276
+ * let currentURL;
2277
+ * page
2278
+ * .waitForSelector('img')
2279
+ * .then(() => console.log('First URL with image: ' + currentURL));
2280
+ * for (currentURL of [
2281
+ * 'https://example.com',
2282
+ * 'https://google.com',
2283
+ * 'https://bbc.com',
2284
+ * ]) {
2285
+ * await page.goto(currentURL);
2286
+ * }
2287
+ * await browser.close();
2288
+ * })();
2289
+ * ```
2290
+ * @param selector - A
2291
+ * {@link https://developer.mozilla.org/en-US/docs/Web/CSS/CSS_Selectors | selector}
2292
+ * of an element to wait for
2293
+ * @param options - Optional waiting parameters
2294
+ * @returns Promise which resolves when element specified by selector string
2295
+ * is added to DOM. Resolves to `null` if waiting for hidden: `true` and
2296
+ * selector is not found in DOM.
2297
+ * @remarks
2298
+ * The optional Parameter in Arguments `options` are :
2299
+ *
2300
+ * - `Visible`: A boolean wait for element to be present in DOM and to be
2301
+ * visible, i.e. to not have `display: none` or `visibility: hidden` CSS
2302
+ * properties. Defaults to `false`.
2303
+ *
2304
+ * - `hidden`: ait for element to not be found in the DOM or to be hidden,
2305
+ * i.e. have `display: none` or `visibility: hidden` CSS properties. Defaults to
2306
+ * `false`.
2307
+ *
2308
+ * - `timeout`: maximum time to wait for in milliseconds. Defaults to `30000`
2309
+ * (30 seconds). Pass `0` to disable timeout. The default value can be changed
2310
+ * by using the {@link Page.setDefaultTimeout} method.
2311
+ */
1334
2312
  waitForSelector(selector, options = {}) {
1335
2313
  return this.mainFrame().waitForSelector(selector, options);
1336
2314
  }
2315
+ /**
2316
+ * Wait for the `xpath` to appear in page. If at the moment of calling the
2317
+ * method the `xpath` already exists, the method will return immediately. If
2318
+ * the `xpath` doesn't appear after the `timeout` milliseconds of waiting, the
2319
+ * function will throw.
2320
+ *
2321
+ * This method works across navigation
2322
+ * ```js
2323
+ * const puppeteer = require('puppeteer');
2324
+ * (async () => {
2325
+ * const browser = await puppeteer.launch();
2326
+ * const page = await browser.newPage();
2327
+ * let currentURL;
2328
+ * page
2329
+ * .waitForXPath('//img')
2330
+ * .then(() => console.log('First URL with image: ' + currentURL));
2331
+ * for (currentURL of [
2332
+ * 'https://example.com',
2333
+ * 'https://google.com',
2334
+ * 'https://bbc.com',
2335
+ * ]) {
2336
+ * await page.goto(currentURL);
2337
+ * }
2338
+ * await browser.close();
2339
+ * })();
2340
+ * ```
2341
+ * @param xpath - A
2342
+ * {@link https://developer.mozilla.org/en-US/docs/Web/XPath | xpath} of an
2343
+ * element to wait for
2344
+ * @param options - Optional waiting parameters
2345
+ * @returns Promise which resolves when element specified by xpath string is
2346
+ * added to DOM. Resolves to `null` if waiting for `hidden: true` and xpath is
2347
+ * not found in DOM.
2348
+ * @remarks
2349
+ * The optional Argument `options` have properties:
2350
+ *
2351
+ * - `visible`: A boolean to wait for element to be present in DOM and to be
2352
+ * visible, i.e. to not have `display: none` or `visibility: hidden` CSS
2353
+ * properties. Defaults to `false`.
2354
+ *
2355
+ * - `hidden`: A boolean wait for element to not be found in the DOM or to be
2356
+ * hidden, i.e. have `display: none` or `visibility: hidden` CSS properties.
2357
+ * Defaults to `false`.
2358
+ *
2359
+ * - `timeout`: A number which is maximum time to wait for in milliseconds.
2360
+ * Defaults to `30000` (30 seconds). Pass `0` to disable timeout. The default
2361
+ * value can be changed by using the {@link Page.setDefaultTimeout} method.
2362
+ */
1337
2363
  waitForXPath(xpath, options = {}) {
1338
2364
  return this.mainFrame().waitForXPath(xpath, options);
1339
2365
  }
2366
+ /**
2367
+ * The `waitForFunction` can be used to observe viewport size change:
2368
+ *
2369
+ * ```
2370
+ * const puppeteer = require('puppeteer');
2371
+ * (async () => {
2372
+ * const browser = await puppeteer.launch();
2373
+ * const page = await browser.newPage();
2374
+ * const watchDog = page.waitForFunction('window.innerWidth < 100');
2375
+ * await page.setViewport({ width: 50, height: 50 });
2376
+ * await watchDog;
2377
+ * await browser.close();
2378
+ * })();
2379
+ * ```
2380
+ * To pass arguments from node.js to the predicate of `page.waitForFunction` function:
2381
+ * ```
2382
+ * const selector = '.foo';
2383
+ * await page.waitForFunction(
2384
+ * (selector) => !!document.querySelector(selector),
2385
+ * {},
2386
+ * selector
2387
+ * );
2388
+ * ```
2389
+ * The predicate of `page.waitForFunction` can be asynchronous too:
2390
+ * ```
2391
+ * const username = 'github-username';
2392
+ * await page.waitForFunction(
2393
+ * async (username) => {
2394
+ * const githubResponse = await fetch(
2395
+ * `https://api.github.com/users/${username}`
2396
+ * );
2397
+ * const githubUser = await githubResponse.json();
2398
+ * // show the avatar
2399
+ * const img = document.createElement('img');
2400
+ * img.src = githubUser.avatar_url;
2401
+ * // wait 3 seconds
2402
+ * await new Promise((resolve, reject) => setTimeout(resolve, 3000));
2403
+ * img.remove();
2404
+ * },
2405
+ * {},
2406
+ * username
2407
+ * );
2408
+ * ```
2409
+ * @param pageFunction - Function to be evaluated in browser context
2410
+ * @param options - Optional waiting parameters
2411
+ * @param args - Arguments to pass to `pageFunction`
2412
+ * @returns Promise which resolves when the `pageFunction` returns a truthy
2413
+ * value. It resolves to a JSHandle of the truthy value.
2414
+ *
2415
+ * The optional waiting parameter can be:
2416
+ *
2417
+ * - `Polling`: An interval at which the `pageFunction` is executed, defaults to
2418
+ * `raf`. If `polling` is a number, then it is treated as an interval in
2419
+ * milliseconds at which the function would be executed. If polling is a
2420
+ * string, then it can be one of the following values:<br/>
2421
+ * - `raf`: to constantly execute `pageFunction` in `requestAnimationFrame`
2422
+ * callback. This is the tightest polling mode which is suitable to
2423
+ * observe styling changes.<br/>
2424
+ * - `mutation`: to execute pageFunction on every DOM mutation.
2425
+ *
2426
+ * - `timeout`: maximum time to wait for in milliseconds. Defaults to `30000`
2427
+ * (30 seconds). Pass `0` to disable timeout. The default value can be changed
2428
+ * by using the
2429
+ * {@link Page.setDefaultTimeout | page.setDefaultTimeout(timeout)} method.
2430
+ *
2431
+ */
1340
2432
  waitForFunction(pageFunction, options = {}, ...args) {
1341
2433
  return this.mainFrame().waitForFunction(pageFunction, options, ...args);
1342
2434
  }