{"id":13804434,"url":"https://github.com/fanyong920/jvppeteer","last_synced_at":"2025-12-27T13:29:31.732Z","repository":{"id":38348221,"uuid":"246532147","full_name":"fanyong920/jvppeteer","owner":"fanyong920","description":"Java API For Chrome and Firefox","archived":false,"fork":false,"pushed_at":"2025-04-02T07:16:47.000Z","size":2337,"stargazers_count":758,"open_issues_count":5,"forks_count":160,"subscribers_count":19,"default_branch":"master","last_synced_at":"2025-04-06T08:09:25.376Z","etag":null,"topics":["chrome","chrome-headless","crawler","java","jvppeteer","puppeteer","scraper"],"latest_commit_sha":null,"homepage":"","language":"Java","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/fanyong920.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2020-03-11T09:45:16.000Z","updated_at":"2025-04-02T07:16:50.000Z","dependencies_parsed_at":"2024-01-07T09:39:53.824Z","dependency_job_id":"23149bc3-71cb-4cc7-90eb-67f5971a4c72","html_url":"https://github.com/fanyong920/jvppeteer","commit_stats":{"total_commits":244,"total_committers":11,"mean_commits":"22.181818181818183","dds":0.3278688524590164,"last_synced_commit":"8926db2952ab718132d7ecc32f5b7c9a8e451878"},"previous_names":[],"tags_count":35,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fanyong920%2Fjvppeteer","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fanyong920%2Fjvppeteer/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fanyong920%2Fjvppeteer/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fanyong920%2Fjvppeteer/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/fanyong920","download_url":"https://codeload.github.com/fanyong920/jvppeteer/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248710399,"owners_count":21149185,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["chrome","chrome-headless","crawler","java","jvppeteer","puppeteer","scraper"],"created_at":"2024-08-04T01:00:47.773Z","updated_at":"2025-12-27T13:29:31.723Z","avatar_url":"https://github.com/fanyong920.png","language":"Java","funding_links":[],"categories":["Chrome DevTools Protocol"],"sub_categories":["Libraries for driving the protocol (or a layer above)"],"readme":"# Jvppeteer\r\n\u003cp style=\"text-align:left\"\u003e\r\n \u003ca\u003e\u003cimg alt=\"Maven Central\" src=\"https://img.shields.io/maven-central/v/io.github.fanyong920/jvppeteer\"\u003e\u003c/a\u003e\r\n    \u003ca href=\"https://sonarcloud.io/dashboard?id=fanyong920_jvppeteer\"\u003e\u003cimg alt=\"Quality Gate Status\" src=\"https://sonarcloud.io/api/project_badges/measure?project=fanyong920_jvppeteer\u0026metric=alert_status\" style=\"max-width:100%;\"\u003e\u003c/a\u003e\r\n\u003c/p\u003e\r\n\r\n# Java API For Chrome and Firefox\r\n\r\nJvppeteer 通过 [DevTools](https://chromedevtools.github.io/devtools-protocol/)  and [WebDriver-bidi](https://pptr.nodejs.cn/webdriver-bidi) 控制 Chrome for Testing（下面简称 Chrome）或 Firefox。 默认情况下，以  headless （无 UI）模式运行，也可以通过配置运行'有UI'模式。\r\n\r\n目前，Jvppeteer 控制 Chrome 仅支持通过 [DevTools](https://chromedevtools.github.io/devtools-protocol/) 、控制 Firefox 仅支持 [WebDriver-bidi](https://pptr.nodejs.cn/webdriver-bidi)  。[WebDriver-bidi](https://pptr.nodejs.cn/webdriver-bidi) 并不支持所有函数，不支持的功能 会抛出 UnsupportedOperationException,  [WebDriver-bidi](https://pptr.nodejs.cn/webdriver-bidi) 支持的函数查看： [WebDriver BiDi 支持](https://pptr.nodejs.cn/webdriver-bidi)\r\n\r\n\r\n你可以在浏览器中手动执行的绝大多数操作都可以使用 Jvppeteer 来完成！ 下面是一些示例：\r\n\r\n- 生成页面 PDF。\r\n- 抓取 SPA（单页应用）并生成预渲染内容（即“SSR”（服务器端渲染））。\r\n- 自动提交表单，进行 UI 测试，键盘输入等。\r\n- 创建一个时时更新的自动化测试环境。 使用最新的 JavaScript 和浏览器功能直接在最新版本的 Chrome 中执行测试。\r\n- 捕获网站的 [timeline trace](https://developers.google.com/web/tools/chrome-devtools/evaluate-performance/reference)，用来帮助分析性能问题。\r\n- 测试浏览器扩展。\r\n\r\n## 开始使用\r\n\r\n### 一、以下是使用依赖管理工具（如 maven 或 gradle）的简要指南。\r\n\r\n#### Maven\r\n要使用 maven,请将此依赖添加到pom.xml文件中：\r\n\r\n```xml\r\n\u003cdependency\u003e\r\n  \u003cgroupId\u003eio.github.fanyong920\u003c/groupId\u003e\r\n  \u003cartifactId\u003ejvppeteer\u003c/artifactId\u003e\r\n  \u003cversion\u003e3.6.0\u003c/version\u003e\r\n\u003c/dependency\u003e\r\n```\r\n\r\n#### Gradle\r\n\r\n要使用 Gradle，请将 Maven 中央存储库添加到您的存储库列表中:\r\n\r\n```\r\nmavenCentral（）\r\n```\r\n\r\n然后，您可以将最新版本添加到您的构建中。\r\n\r\n```xml\r\ncompile \"io.github.fanyong920:jvppeteer:3.6.0\"\r\n```\r\n\r\n#### Logging\r\n\r\n该库使用 [SLF4J](https://www.slf4j.org/) 进行日志记录，并且不附带任何默认日志记录实现。\r\n\r\n调试程序将日志级别设置为 Debug。\r\n\r\n#### 独立 jar\r\n\r\n如果您不使用任何依赖项管理工具，则可以在[此处](https://github.com/fanyong920/jvppeteer/releases/latest)找到最新的独立 jar 。\r\n\r\n### 二、快速开始\r\n\r\n#### 1、下载浏览器\r\n\r\n从2.0.0版本开始，Jvppeteer与 [Chrome ](https://googlechromelabs.github.io/chrome-for-testing/#stable) 配合使用， [Chrome ](https://googlechromelabs.github.io/chrome-for-testing/#stable) 使用的是新的无头模式，旧的无头模式现在是一个名为 [chrome-headless-shell](https://developer.chrome.com/blog/chrome-headless-shell) 的独立程序。无论你使用 [Chrome](https://googlechromelabs.github.io/chrome-for-testing/#stable) 还是 [chrome-headless-shell](https://developer.chrome.com/blog/chrome-headless-shell) ，你只要将 headless 设置为 true， Jvppeteer 会自动匹配新的无头模式和旧的无头模式.\r\n\r\n在此版本之前，Jvppeteer 下载并与 Chromium 配合使用。\r\n\r\n#### 2、支持的浏览器版本列表\r\n\r\n每个 Jvppeteer 版本都有一个绑定的浏览器版本，最好采用绑定的浏览器版本使用 Jvppeteer。\r\n\r\n下表提供了 Jvppeteer 版本与绑定的浏览器版本之间的映射。如果没有列出完全匹配的 Jvppeteer 版本，则支持的浏览器版本是紧接在前的版本：\r\n\r\n| 3.5.0- 3.6.0 | [Chrome for Testing](https://googlechromelabs.github.io/chrome-for-testing/#stable) 142.0.7444.175  \u0026 Firefox stable_145.0.1 |\r\n|:------------:| :----------------------------------------------------------: |\r\n| 3.4.0-3.4.2  | [Chrome for Testing](https://googlechromelabs.github.io/chrome-for-testing/#stable) 137.0.7151.119  \u0026 Firefox stable_139.0.4 |\r\n| 3.3.6-3.3.9  | [Chrome for Testing](https://googlechromelabs.github.io/chrome-for-testing/#stable) 135.0.7049.42  \u0026 Firefox stable_137.0 |\r\n| 3.3.0--3.3.5 | [Chrome for Testing](https://googlechromelabs.github.io/chrome-for-testing/#stable) 133.0.6943.98  \u0026 Firefox stable_135.0 |\r\n| 3.0.0--3.2.0 | [Chrome for Testing](https://googlechromelabs.github.io/chrome-for-testing/#stable) 131.0.6778.87  \u0026 Firefox stable_133.0 |\r\n| 2.2.0--2.2.5 | [Chrome for Testing](https://googlechromelabs.github.io/chrome-for-testing/#stable) 130.0.6723.58 |\r\n|    2.1.2     | [Chrome for Testing](https://googlechromelabs.github.io/chrome-for-testing/#stable) 128.0.6613.137 |\r\n|    2.1.1     | [Chrome for Testing](https://googlechromelabs.github.io/chrome-for-testing/#stable) 128.0.6613.137 |\r\n|    2.1.0     | [Chrome for Testing](https://googlechromelabs.github.io/chrome-for-testing/#stable) 128.0.6613.137 |\r\n|    2.0.0     | [Chrome for Testing](https://googlechromelabs.github.io/chrome-for-testing/#stable) 128.0.6613.137 |\r\n|    1.1.6     |                       Chromium 722234                        |\r\n|    1.1.5     |                       Chromium 722234                        |\r\n|    1.1.4     |                       Chromium 722234                        |\r\n|    1.1.3     |                       Chromium 722234                        |\r\n|    1.1.2     |                       Chromium 722234                        |\r\n\r\n#### 1、页面打印PDF\r\n\r\n要打印 PDF，请使用 Page.pdf() 。手动在浏览器按Ctrl+P可以预览 PDF，弹出的窗口就是 PDF 样式，把各个选项点一下，看一下预览效果 然后再回来写代码。\r\n\r\n```java\r\n    //pdf必须配置headless = true\r\n    launchOptions.setHeadless(true);\r\n    ArrayList\u003cString\u003e args = new ArrayList\u003c\u003e();//添加一些额外的启动参数\r\n    args.add(\"--no-sandbox\");//pdf必须添加这个参数,不然无法打印，具体看这里https://github.com/puppeteer/puppeteer/issues/12470\r\n    launchOptions.setArgs(args);\r\n    Browser cdpBrowser = Puppeteer.launch(launchOptions);\r\n    Page page = cdpBrowser.newPage();\r\n    GoToOptions goToOptions = new GoToOptions();\r\n    goToOptions.setWaitUntil(Collections.singletonList(PuppeteerLifeCycle.NETWORKIDLE));\r\n    page.goTo(\"https://www.baidu.com/?tn=68018901_16_pg\",goToOptions);\r\n    PDFOptions pdfOptions = new PDFOptions();\r\n    pdfOptions.setPath(\"baidu.pdf\");\r\n    pdfOptions.setOutline(true);//生成大纲\r\n    pdfOptions.setFormat(PaperFormats.a4);//A4大小\r\n    pdfOptions.setPrintBackground(true);//打印背景图形，百度一下这个蓝色按钮就显示出来了\r\n    pdfOptions.setPreferCSSPageSize(false);\r\n    pdfOptions.setScale(1.1);//缩放比例1.1\r\n    page.pdf(pdfOptions);\r\n    //关闭浏览器\r\n    cdpBrowser.close();\r\n```\r\n\r\n默认情况下，Page.pdf() 等待字体加载。\r\n\r\n#### 2、页面截图\r\n\r\n要捕获屏幕截图，请使用 Page.screenshot()。\r\n\r\n```java\r\n\t@Test\r\n    public void test3() throws Exception {\r\n        Browser cdpBrowser = Puppeteer.launch(launchOptions);\r\n        Page page = cdpBrowser.newPage();\r\n        page.goTo(\"https://www.baidu.com/?tn=68018901_16_pg\");\r\n        ScreenshotOptions screenshotOptions = new ScreenshotOptions();\r\n        screenshotOptions.setPath(\"baidu.png\");\r\n        screenshotOptions.setOmitBackground(true);\r\n        //全屏截图\r\n        screenshotOptions.setFullPage(true);\r\n        //截图的更多\r\n        screenshotOptions.setCaptureBeyondViewport(true);\r\n        page.screenshot(screenshotOptions);\r\n        cdpBrowser.close();\r\n    }\r\n\r\n    @Test\r\n    public void test4() throws Exception {\r\n        Browser cdpBrowser = Puppeteer.launch(launchOptions);\r\n        Page page = cdpBrowser.newPage();\r\n        page.goTo(\"https://www.baidu.com/?tn=68018901_16_pg\");\r\n        ScreenshotOptions screenshotOptions = new ScreenshotOptions();\r\n        screenshotOptions.setPath(\"baidu.png\");\r\n        //指定图片类型，path指定的名称中的后缀便不起作用了\r\n        screenshotOptions.setType(ImageType.JPEG);\r\n        //jpg可以设置这个选项\r\n        screenshotOptions.setQuality(80.00);\r\n        //全屏截图\r\n        screenshotOptions.setFullPage(true);\r\n        page.screenshot(screenshotOptions);\r\n        cdpBrowser.close();\r\n    }\r\n\r\n    @Test\r\n    public void test5() throws Exception {\r\n        Browser cdpBrowser = Puppeteer.launch(launchOptions);\r\n        Page page = cdpBrowser.newPage();\r\n        page.goTo(\"https://www.baidu.com/?tn=68018901_16_pg\");\r\n        ScreenshotOptions screenshotOptions = new ScreenshotOptions();\r\n        screenshotOptions.setPath(\"baidu.jpeg\");\r\n        //指定图片类型，path指定的名称中的后缀便不起作用了\r\n        screenshotOptions.setType(ImageType.WEBP);\r\n        //jpg可以设置这个选项\r\n        screenshotOptions.setQuality(80.00);\r\n        //全屏截图\r\n        screenshotOptions.setFullPage(true);\r\n        page.screenshot(screenshotOptions);\r\n        cdpBrowser.close();\r\n    }\r\n```\r\n\r\n\r\n\r\n#### **更多的例子请看项目内的example文件夹** 点击[这里](https://github.com/fanyong920/jvppeteer/tree/master/example/src/main/java/com/ruiyun/example)，是入门级别的例子，对如何使用 Jvppeteer 有很大帮助。或者看看[本项目的WIKI](https://github.com/fanyong920/jvppeteer/wiki)。\r\n\r\n### 三、遇到问题怎么办\r\n\r\n如果你在 Linux 上安装 Chrome 并运行 遇到麻烦，或者在某个场景中遇到麻烦，可以 在 [Puppeteer(Node.js)](https://github.com/puppeteer/puppeteer) 库中的 [Troubleshooting](https://pptr.dev/troubleshooting) 寻找答案，也可以在其 issues 中寻找一些解决问题的思路，或者google baidu puppeteer的解决方案，再应用到你的问题上。\r\n\r\n### 四、资源\r\n\r\n1. [Puppeteer中文文档](https://pptr.nodejs.cn/) : 更加详细的 API 文档 ，多看看了解一下\r\n2. [DevTools Protocol](https://chromedevtools.github.io/devtools-protocol/) ：CDP 协议\r\n3. [本项目的WIKI](https://github.com/fanyong920/jvppeteer/wiki): 目前写有一些内容，后续有想到新的，会持续更新\r\n4. [命令行启动参数大全](https://github.com/GoogleChrome/chrome-launcher/blob/d6be1f3250ef7ff7648ae58c4e92e48509bdbe7c/src/flags.ts#L67)\r\n\r\n### 五、执照\r\n\r\n此仓库中找到的所有内容均已获得 Apache 许可。有关详细信息，请参见`LICENSE`文件\r\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffanyong920%2Fjvppeteer","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ffanyong920%2Fjvppeteer","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffanyong920%2Fjvppeteer/lists"}