public class BidiPage extends Page
_timeoutSettings, inflight, isDragging, LOGGER, requestHandlers| 限定符和类型 | 方法和说明 | ||
|---|---|---|---|
protected String |
_screenshot(ScreenshotOptions options) |
||
Accessibility |
accessibility() |
||
void |
authenticate(Credentials credentials)
为HTTP authentication 提供认证凭据 。
|
||
void |
bringToFront()
相当于多个tab时,切换到某个tab。
|
||
BidiBrowser |
browser()
返回页面隶属的浏览器
|
||
BidiBrowserContext |
browserContext()
获取页面所属的浏览器上下文。
|
||
void |
close(boolean runBeforeUnload) |
||
List<Cookie> |
cookies(String... urls)
根据提供的URL列表获取Cookies
如果未指定 URL,则此方法返回当前页面 URL 的 cookie。
|
||
Coverage |
coverage() |
||
CDPSession |
createCDPSession()
创建附加到页面的 Chrome Devtools 协议会话。
|
||
void |
deleteCookie(DeleteCookiesRequest... cookies)
删除指定的cookies
|
||
void |
emulate(Device device)
模拟各种设备打开浏览器
所有录制内容均为 WebM 格式,使用 VP9 视频编解码器。
|
||
void |
emulateCPUThrottling(double factor)
启用 CPU 限制以模拟慢速 CPU。
|
||
void |
emulateIdleState(IdleOverridesState.Overrides overrides)
模拟空闲状态。
|
||
void |
emulateMediaFeatures(List<MediaFeature> features)
模拟媒体特征
|
||
void |
emulateMediaType(MediaType type)
改变页面的css媒体类型。
|
||
void |
emulateNetworkConditions(NetworkConditions networkConditions)
模拟网络条件
这不会影响 WebSocket 和 WebRTC PeerConnections(请参阅这里 )。
|
||
void |
emulateTimezone(String timezoneId)
更改页面的时区,传null将禁用将时区仿真
voidemulateVisionDeficiency(VisionDeficiency type)
模拟页面上给定的视力障碍,不同视力障碍,截图有不同效果
| ||
NewDocumentScriptEvaluation |
evaluateOnNewDocument(String pptrFunction,
EvaluateType type,
Object... args)
在新dom产生之际执行给定的javascript
当你的js代码为函数时,type=
EvaluateType.FUNCTION
当你的js代码为字符串时,type=EvaluateType.STRING |
||
void |
exposeFunction(String name,
BindingFunction pptrFunction)
该方法在页面的 window 对象上添加一个名为 name 的函数。
|
||
AwaitableResult<FileChooser> |
fileChooserWaitFor()
创建并返回一个可等待的文件选择器结果
当需要拦截文件选择器对话框时,此方法将非常有用
|
||
BidiFrame |
focusedFrame() |
||
List<BidiFrame> |
frames()
附加到页面的所有框架的数组。
|
||
static BidiPage |
from(BidiBrowserContext browserContext,
BrowsingContext browsingContext) |
||
int |
getDefaultNavigationTimeout() |
||
int |
getDefaultTimeout() |
||
Response |
goBack(WaitForOptions options)
导航到页面历史的前一个页面
options 导航配置,可选值:
otimeout 跳转等待时间,单位是毫秒, 默认是30秒, 传 0 表示无限等待。
|
||
Response |
goForward(WaitForOptions options)
导航到页面历史的后一个页面。
|
||
boolean |
isClosed()
表示页面是否被关闭。
|
||
boolean |
isDragInterceptionEnabled()
我们不再支持拦截拖动有效负载。
|
||
boolean |
isJavaScriptEnabled() |
||
boolean |
isServiceWorkerBypassed() |
||
Keyboard |
keyboard()
虚拟键盘
|
||
BidiFrame |
mainFrame()
页面的主框架。
|
||
Metrics |
metrics()
获取性能指标
本方法通过向目标客户端发送“Performance.getMetrics”请求来获取当前的性能指标
接收到的响应将被转换成GetMetricsResponse对象,然后用于构建并返回一个Metrics对象
Metrics对象:
Timestamp :获取指标样本时的时间戳。
|
||
Mouse |
mouse() |
||
byte[] |
pdf(PDFOptions options)
生成当前页面的pdf格式,带着 pring css media。
|
||
byte[] |
pdf(PDFOptions options,
LengthUnit lengthUnit)
生成当前页面的pdf格式,带着 pring css media。
|
||
void |
pdf(String path)
生成当前页面的pdf格式,带着 pring css media。
|
||
BidiJSHandle |
queryObjects(JSHandle prototypeHandle)
此方法遍历js堆栈,找到所有带有指定原型的对象
|
||
BidiResponse |
reload(WaitForOptions options)
重新加载页面
|
||
void |
removeExposedFunction(String name)
该方法从页面的 window 对象中删除先前通过 Page.exposeFunction() 添加的名为 name 的函数。
|
||
void |
removeScriptToEvaluateOnNewDocument(String identifier)
删除通过 Page.evaluateOnNewDocument 注入页面的脚本。
|
||
void |
setBypassCSP(boolean enabled)
切换绕过页面的内容安全策略。
|
||
void |
setBypassServiceWorker(boolean bypass)
切换忽略每个请求的 Service Worker。
|
||
void |
setCacheEnabled(boolean enabled)
根据启用状态切换忽略每个请求的缓存。
|
||
void |
setCookie(CookieParam... cookies) |
||
void |
setDefaultNavigationTimeout(int timeout)
|
||
void |
setDefaultTimeout(int timeout) |
||
void |
setDragInterception(boolean enabled)
我们不再支持拦截拖动有效负载。
|
||
void |
setExtraHTTPHeaders(Map<String,String> headers)
当前页面发起的每个请求都会带上这些请求头
注意 此方法不保证请求头的顺序
|
||
void |
setGeolocation(GeolocationOptions options)
设置页面的地理位置
考虑使用
BrowserContext.overridePermissions(String, WebPermission...) |
||
void |
setJavaScriptEnabled(boolean enabled)
是否在页面上启用 JavaScript。
|
||
void |
setOfflineMode(boolean enabled)
将网络连接设置为离线。
|
||
void |
setRequestInterception(boolean enable)
启用请求拦截器,会激活 request.abort, request.continue 和 request.respond 方法。
|
||
void |
setUserAgent(String userAgent,
UserAgentMetadata userAgentMetadata)
给页面设置userAgent
|
||
void |
setViewport(Viewport viewport)
如果是一个浏览器多个页面的情况,每个页面都可以有单独的viewport
注意 在大部分情况下,改变 viewport 会重新加载页面以设置 isMobile 或者 hasTouch
|
||
Target |
target()
创建此页面的目标。
|
||
Touchscreen |
touchscreen()
触控屏幕
|
||
Tracing |
tracing() |
||
Viewport |
viewport()
获取Viewport,Viewport各个参数的含义:
width 宽度,单位是像素
height 高度,单位是像素
deviceScaleFactor 定义设备缩放, (类似于 dpr)。
|
||
DeviceRequestPrompt |
waitForDevicePrompt(int timeout)
此方法通常与从 API(例如 WebBluetooth)触发设备请求的操作结合使用。
|
||
List<WebWorker> |
workers()
该方法返回所有与页面关联的 WebWorkers
|
$, $$, $$eval, $$eval, $eval, $eval, addScriptTag, addStyleTag, click, click, close, content, convertPrintParameterToInches, cookies, deleteCookie, evaluate, evaluateHandle, evaluateHandle, evaluateOnNewDocument, focus, goBack, goForward, goTo, goTo, hover, isDragging, normalizeRectangle, off, on, reload, roundRectangle, screencast, screenshot, screenshot, select, setContent, setContent, setDragging, setUserAgent, stopScreencast, tap, title, type, type, url, waitForDevicePrompt, waitForFrame, waitForFrame, waitForFrame, waitForFunction, waitForFunction, waitForFunction, waitForFunction, waitForNavigation, waitForNavigation, waitForNavigation, waitForNetworkIdle, waitForRequest, waitForRequest, waitForResponse, waitForResponse, waitForResponse, waitForResponse, waitForSelector, waitForSelectordisposeSymbol, emit, listenerCount, once, removeAllListeners, removeListenerpublic static BidiPage from(BidiBrowserContext browserContext, BrowsingContext browsingContext)
public void setUserAgent(String userAgent, UserAgentMetadata userAgentMetadata)
PagesetUserAgent 在类中 PageuserAgent - 此页面中使用的特定用户代理public void setBypassCSP(boolean enabled)
Page注意:CSP 绕过发生在 CSP 初始化时而不是评估时。通常,这意味着应在导航到域之前调用 page.setBypassCSP。
setBypassCSP 在类中 Pageenabled - 是否绕过public BidiJSHandle queryObjects(JSHandle prototypeHandle) throws com.fasterxml.jackson.core.JsonProcessingException
PagequeryObjects 在类中 PageprototypeHandle - 原型处理器com.fasterxml.jackson.core.JsonProcessingException - Json解析异常public BidiBrowser browser()
Pagepublic BidiBrowserContext browserContext()
PagebrowserContext 在类中 Pagepublic BidiFrame focusedFrame() throws com.fasterxml.jackson.core.JsonProcessingException
com.fasterxml.jackson.core.JsonProcessingExceptionpublic BidiResponse reload(WaitForOptions options)
Pagereload 在类中 Pageoptions - 与$Page.goTo(String, GoToOptions)中的options是一样的配置public void setDefaultNavigationTimeout(int timeout)
PagePage.goTo(String)
$Page.goTo(String, GoToOptions)
$Page.goBack(WaitForOptions)
$Page.goForward(WaitForOptions)
$Page.reload(WaitForOptions)
$Page.setContent(String)
$Page.waitForNavigation()setDefaultNavigationTimeout 在类中 Pagetimeout - 超时时间public void setDefaultTimeout(int timeout)
setDefaultTimeout 在类中 Pagepublic int getDefaultTimeout()
getDefaultTimeout 在类中 Pagepublic int getDefaultNavigationTimeout()
getDefaultNavigationTimeout 在类中 Pagepublic boolean isJavaScriptEnabled()
isJavaScriptEnabled 在类中 Pagepublic void setGeolocation(GeolocationOptions options)
Page
考虑使用 BrowserContext.overridePermissions(String, WebPermission...) 授予页面读取其地理位置的权限。
setGeolocation 在类中 Pageoptions - 地理位置具体信息public void setJavaScriptEnabled(boolean enabled)
PagesetJavaScriptEnabled 在类中 Pageenabled - 是否启用public void emulateMediaType(MediaType type)
PageemulateMediaType 在类中 Pagetype - css媒体类型public void emulateCPUThrottling(double factor)
PageemulateCPUThrottling 在类中 Pagefactor - 减速系数(1 表示无油门,2 表示 2 倍减速,等等)。public void emulateMediaFeatures(List<MediaFeature> features)
PageemulateMediaFeatures 在类中 Pagefeatures - 给定一组媒体特性对象,在页面上模拟 CSS 媒体特性,每个媒体特性对象的name必须符合正则表达式 :
^(?:prefers-(?:color-scheme|reduced-motion)|color-gamut)$"public void emulateTimezone(String timezoneId)
PageemulateTimezone 在类中 PagetimezoneId - 时区idpublic void emulateIdleState(IdleOverridesState.Overrides overrides)
PageemulateIdleState 在类中 Pageoverrides - 模拟空闲状态。如果未设置,则清除空闲覆盖public void emulateVisionDeficiency(VisionDeficiency type)
PageemulateVisionDeficiency 在类中 Pagetype - 视力障碍类型public void setViewport(Viewport viewport) throws ExecutionException, InterruptedException
Page注意 在大部分情况下,改变 viewport 会重新加载页面以设置 isMobile 或者 hasTouch
setViewport 在类中 Pageviewport - 设置的视图ExecutionExceptionInterruptedExceptionpublic Viewport viewport()
Pagepublic byte[] pdf(PDFOptions options) throws IOException
Page注意 目前仅支持无头模式的 Chrome
pdf 在类中 Pageoptions - 选项IOException - IO异常public void pdf(String path) throws IOException
Page注意 目前仅支持无头模式的 Chrome
pdf 在类中 Pagepath - pdf存放的路径IOException - IO异常public byte[] pdf(PDFOptions options, LengthUnit lengthUnit) throws IOException
Page注意 目前仅支持无头模式的 Chrome
pdf 在类中 Pageoptions - 选项lengthUnit - 单位IOException - IO异常protected String _screenshot(ScreenshotOptions options) throws IOException
_screenshot 在类中 PageIOExceptionpublic CDPSession createCDPSession()
PagecreateCDPSession 在类中 Pagepublic void bringToFront()
PagebringToFront 在类中 Pagepublic NewDocumentScriptEvaluation evaluateOnNewDocument(String pptrFunction, EvaluateType type, Object... args) throws com.fasterxml.jackson.core.JsonProcessingException
Page当你的js代码为函数时,type=EvaluateType.FUNCTION
当你的js代码为字符串时,type=EvaluateType.STRING
evaluateOnNewDocument 在类中 PagepptrFunction - js代码type - 一般为PageEvaluateType#FUNCTIONargs - 当你js代码是函数时,js函数的参数com.fasterxml.jackson.core.JsonProcessingException - json异常public void removeScriptToEvaluateOnNewDocument(String identifier)
PageremoveScriptToEvaluateOnNewDocument 在类中 Pageidentifier - 脚本标识符public void exposeFunction(String name, BindingFunction pptrFunction)
Page调用时,该函数会执行 pptrFunction,结果是 pptrFunction 的返回值。
exposeFunction 在类中 Pagename - 窗口对象上的函数名称pptrFunction - 将在 Puppeteer 上下文中调用的回调函数。public boolean isDragInterceptionEnabled()
PageisDragInterceptionEnabled 在类中 Pagepublic void setCacheEnabled(boolean enabled)
PagesetCacheEnabled 在类中 Pageenabled - 设置缓存的 enabled 状态public List<Cookie> cookies(String... urls)
Page如果未指定 URL,则此方法返回当前页面 URL 的 cookie。如果指定了 URL,则仅返回这些 URL 的 cookie。
public boolean isServiceWorkerBypassed()
isServiceWorkerBypassed 在类中 Pagepublic AwaitableResult<FileChooser> fileChooserWaitFor()
PagefileChooserWaitFor 在类中 Pagepublic void setRequestInterception(boolean enable)
Page一旦启用请求拦截,每个请求都将停止,除非它继续,响应或中止
setRequestInterception 在类中 Pageenable - 是否启用请求拦截器public void setExtraHTTPHeaders(Map<String,String> headers)
PagesetExtraHTTPHeaders 在类中 Pageheaders - 每个 HTTP 请求都会带上这些请求头。值必须是字符串public void authenticate(Credentials credentials)
Page传 null 禁用认证。
将在后台打开请求拦截以实现身份验证。这可能会影响性能。
authenticate 在类中 Pagecredentials - 验证信息public void setDragInterception(boolean enabled)
PagesetDragInterception 在类中 Pageenabled - 是否启用public void setBypassServiceWorker(boolean bypass)
PagesetBypassServiceWorker 在类中 Pagebypass - 是否忽略public void setOfflineMode(boolean enabled)
Page它不会改变 Page.emulateNetworkConditions() 中使用的参数
setOfflineMode 在类中 Pageenabled - 设置 true, 启用离线模式。public void emulateNetworkConditions(NetworkConditions networkConditions)
Page这不会影响 WebSocket 和 WebRTC PeerConnections(请参阅这里 )。
要将页面设置为离线,你可以使用 Page.setOfflineMode()。
通过导入 PredefinedNetworkConditions 可以使用预定义网络条件列表。
emulateNetworkConditions 在类中 PagenetworkConditions - 传递 null 将禁用网络条件模拟。public void setCookie(CookieParam... cookies)
public void deleteCookie(DeleteCookiesRequest... cookies)
PagedeleteCookie 在类中 Pagecookies - 待删除的cookies请求列表,每个元素包含待删除的cookie信息public Response goBack(WaitForOptions options)
Pageoptions 导航配置,可选值:
otimeout 跳转等待时间,单位是毫秒, 默认是30秒, 传 0 表示无限等待。可以通过page.setDefaultNavigationTimeout(timeout)方法修改默认值
owaitUntil 满足什么条件认为页面跳转完成,默认是load事件触发时。指定事件数组,那么所有事件触发后才认为是跳转完成。事件包括:
oload - 页面的load事件触发时 odomcontentloaded - 页面的DOMContentLoaded事件触发时 onetworkidle0 - 不再有网络连接时触发(至少500毫秒后) onetworkidle2 - 只有2个网络连接时触发(至少500毫秒后)
public Response goForward(WaitForOptions options)
Pageotimeout 跳转等待时间,单位是毫秒, 默认是30秒, 传 0 表示无限等待。可以通过page.setDefaultNavigationTimeout(timeout)方法修改默认值
owaitUntil 满足什么条件认为页面跳转完成,默认是load事件触发时。指定事件数组,那么所有事件触发后才认为是跳转完成。事件包括:
oload - 页面的load事件触发时 odomcontentloaded - 页面的DOMContentLoaded事件触发时 onetworkidle0 - 不再有网络连接时触发(至少500毫秒后) onetworkidle2 - 只有2个网络连接时触发(至少500毫秒后)
public DeviceRequestPrompt waitForDevicePrompt(int timeout)
Page提醒
必须在发送设备请求之前调用此函数。它不会返回当前活动的设备提示。
waitForDevicePrompt 在类中 Pagetimeout - 超时时间,默认是30spublic void removeExposedFunction(String name)
PageremoveExposedFunction 在类中 Pagename - 要删除的函数名称public Metrics metrics() throws com.fasterxml.jackson.core.JsonProcessingException
Page本方法通过向目标客户端发送“Performance.getMetrics”请求来获取当前的性能指标
接收到的响应将被转换成GetMetricsResponse对象,然后用于构建并返回一个Metrics对象
Metrics对象:
Timestamp :获取指标样本时的时间戳。 Documents:页面中的文档数。 ¥Documents : Number of documents in the page. Frames:页面中的帧数。 JSEventListeners:页面中的事件数。 Nodes :页面中 DOM 节点的数量。 LayoutCount:完整或部分页面布局的总数。 RecalcStyleCount:页面样式重新计算的总数。 LayoutDuration:所有页面布局的总持续时间。 RecalcStyleDuration:所有页面样式重新计算的总持续时间。 ScriptDuration :JavaScript 执行的总持续时间。 TaskDuration :浏览器执行的所有任务的总持续时间。 JSHeapUsedSize:使用的 JavaScript 堆大小。 JSHeapTotalSize:JavaScript 堆总大小。
所有时间戳都是单调时间:自过去任意点以来单调增加的时间(以秒为单位)。
public Touchscreen touchscreen()
Pagetouchscreen 在类中 Pagepublic Accessibility accessibility()
accessibility 在类中 PageCopyright © 2020–2025. All rights reserved.