我想在 pptr 使用稳定的 chrome 版本,所以我搜索https://omahaproxy.appspot.com/来查找 chromium 版本。
但构建 902210 不在 chromium 浏览器快照中(https://commondatastorage.googleapis.com/chromium-browser-snapshots/index.html)
还有其他方法可以找到稳定的铬构建吗?
我想使用 3D 画布截取网页的屏幕截图,如下所示:
import {createServer} from 'http'
import puppeteer from 'puppeteer'
const url = "https://webglfundamentals.org/webgl/webgl-load-obj-w-extents.html";
async function main() {
const browser = await puppeteer.launch({
args: [
"--no-sandbox",
"--use-gl=swiftshader",
"--enable-webgl",
],
headless: true,
dumpio: true,
defaultViewport: { width: 400, height: 300 },
});
const page = await browser.newPage();
await page.goto(url);
await page.waitForNetworkIdle();
await page.waitForSelector("#canvas");
const screenshot = await page.screenshot();
console.log(screenshot);
Run Code Online (Sandbox Code Playgroud)
在我的 Ubuntu 机器上本地运行代码工作正常,生成此图像:

在 Docker 容器( Ubuntu + Node.js + Chrome )中运行代码不起作用。它会截取屏幕截图,但 3D 画布不会渲染。
[end of stack trace]
[0927/180308.980024:ERROR:gpu_process_host.cc(961)] GPU process …Run Code Online (Sandbox Code Playgroud) 我在 Puppeteer 方面遇到了一些问题,我想提取一个项目列表,并在 headless 为 FALSE 时成功,但在为 TRUE 时则不然。
首先,我想在映射之前获取这些元素。
这是我的脚本,也许你可以复制它,它非常基本。
const chalk = require("chalk");
const baseUrl = "https://www.interencheres.com/recherche/lots?search=";
const searchTerm = "Apple";
const searchUrl = baseUrl + searchTerm;
(async () => {
const browser = await puppeteer.launch({
headless: false,
ignoreHTTPSErrors: true,
args: [`--window-size=1920,1080`],
defaultViewport: {
width: 1920,
height: 1080,
},
});
const page = await browser.newPage();
// Begin navigation
console.log(chalk.yellow("Beginning navigation."));
await page.goto(searchUrl);
// Await List of elements;
console.log(chalk.yellow("Wait for Network Idle..."));
await page.waitForNetworkIdle();
// get Items
const findElements …Run Code Online (Sandbox Code Playgroud) 我使用 Puppeteer 在 headful 模式下截取全尺寸屏幕截图,因为我大部分时间都需要与浏览器交互。它运行完美,但我注意到一些奇怪的事情:当调用屏幕截图时,它会重新加载页面,因此我在捕获中获得的内容并不总是我在浏览器中看到的内容。
例如,我们以这个 URL为例。如果我想显示埃菲尔铁塔,我需要单击幻灯片放映。到目前为止没有问题。但是,一旦截取屏幕截图,页面就会刷新并返回到沙发上的女人的初始图片......我不知道是什么导致了这种行为。
这是我的代码:
const puppeteer = require('puppeteer');
args=['--window-size=1920,1080'];
const browser=await puppeteer.launch({ headless: false, defaultViewport: null, args);
const page=(await browser.pages())[0];
await page.goto('https://url.com');
await page.waitForTimeout(10000); // 10 sec timeframe to allow navigation
await page.screenshot({path: 'test.png', quality: 100, fullPage: true});
await browser.close();
Run Code Online (Sandbox Code Playgroud)
我在 Debian 10 Linux 服务器上运行最新版本的 Puppeteer (13.1.1)。测试了很多组合、不同的参数、计时器、分辨率等,但均无济于事。有什么建议么?
我正在使用 puppeteer 执行一些操作并拍摄屏幕截图。整个过程有多重身份验证,首先是 Gmail 登录,然后 SSO 重定向到 Microsoft,然后我们从它们进入应用程序。我面临的问题是,当我设置浏览器 - headless : false 时,一切正常,但是当我设置 headless: true 时,Gmail 开始要求验证码,有时它说浏览器不安全。
\n我已经尝试解决这个问题很长一段时间了,但我完全盲目了。我通过互联网阅读并发现了很多选项,例如设置用户代理、添加首选项等,但它们都不起作用。
\n这是我的简单代码和屏幕截图。
\n// puppeteer-extra is a drop-in replacement for puppeteer,\n// it augments the installed puppeteer with plugin functionality\nconst puppeteer = require(\'puppeteer-extra\');\n//puppeteer.use(require(\'puppeteer-extra-plugin-stealth\')());\n\n// add stealth plugin and use defaults (all evasion techniques)\nconst StealthPlugin = require(\'puppeteer-extra-plugin-stealth\');\nconsole.log(StealthPlugin.availableEvasions);\npuppeteer.use(StealthPlugin());\n//const RecaptchaPlugin = require(\'puppeteer-extra-plugin-recaptcha\')\n\n\n//const puppeteer = require(\'puppeteer\')\n\n// puppeteer usage as normal\npuppeteer.launch({ headless: true, executablePath: \'/Applications/Google Chrome.app/Contents/MacOS/Google Chrome\', setUserAgent: \'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like …Run Code Online (Sandbox Code Playgroud) 当我尝试编译shopware 6时
./bin/build-storefront.sh
我收到一条错误消息,提示 Chromium 下载无法完成。
npm ERR! code 1
npm ERR! path /home/username/vendor/shopware/storefront/Resources/app/storefront/node_modules/puppeteer
npm ERR! command failed
npm ERR! command sh -c node install.js
npm ERR! ERROR: Failed to set up Chromium r950341! Set "PUPPETEER_SKIP_DOWNLOAD" env variable to skip download.
npm ERR! [Error: EINVAL: invalid argument, realpath '/home/username/vendor/shopware/storefront/Resources/app/storefront/node_modules/puppeteer/.local-chromium/linux-950341'] {
npm ERR! errno: -22,
npm ERR! code: 'EINVAL',
npm ERR! syscall: 'realpath',
npm ERR! path: '/home/username/vendor/shopware/storefront/Resources/app/storefront/node_modules/puppeteer/.local-chromium/linux-950341'
npm ERR! }
npm ERR! A complete log of this run can be found …Run Code Online (Sandbox Code Playgroud) Puppeteer 无法在谷歌云中工作!
镀铬错误如图所示。
我已经在这里实现了建议:Puppeteer error on Heroku: Could not find Chromium
我还尝试将我的 puppeteer 版本从 19.x 降级到 18.x 和 17.x,但没有成功。
我会尝试使用剧作家,除非这里有人知道如何解决这个问题......
编辑:我尝试使用 puppeteer-chromium-resolver 而不是 puppeteer,但是现在我完全无法在节点运行时 16 和 18 上部署我的云功能。
编辑2:我放弃了 puppeteer-chromium-resolver,转而使用 chrome-aws-lambda,并添加了以下代码片段并部署到 Google 云函数:
const bundledChromium = require('chrome-aws-lambda');
const playwright = require('playwright-core');
(async () => {
const browser = await Promise.resolve(bundledChromium.executablePath).then(
(executablePath) => {
console.log("executablePath: ", executablePath);
if (!executablePath) {
// local execution
return playwright.chromium.launch({});
}
return playwright.chromium.launch({ executablePath });
}
);
})()
Run Code Online (Sandbox Code Playgroud)
该语句console.log("executablePath: ", executablePath);打印“/tmp/chromium” …
const bot = require("puppeteer");
const fs = require("fs");
const botConfiguration ={
headless:false,
executablePath:"C:/Program Files/Google/Chrome/Application/chrome.exe",
userDataDir: "C:/Users/bot/AppData/Local/Google/Chrome/User Data/",
args: ['--profile-directory=Profile 28']
};
async function runBot() {
const chromeBrowser = await bot.launch(botConfiguration)
const chromeBrowserPage = await chromeBrowser.newPage()
await chromeBrowserPage.goto("https://www.google.com/")
};
runBot();
Run Code Online (Sandbox Code Playgroud)
Puppeteer 旧的 Headless 弃用警告:
在不久的将来,headless: trueChrome 将默认使用新的 Headless 模式,而不是旧的 Headless 实现。有关更多信息,请参阅https://developer.chrome.com/articles/new-headless/。考虑尽早选择加入headless: "new"如果您遇到任何错误,请向https://github.com/puppeteer/puppeteer/issues/new/choosepuppeteer.launch()
报告。
我不想在我的终端中看到这个错误............
Puppeteer 旧的 Headless 弃用警告:
automation headless headless-browser google-chrome-headless puppeteer
我有一个节点脚本,可以将网页转换为PDF文档.用户输入一些内容,PHP构建一个HTML页面,然后在节点脚本(运行Puppeteer,使用稍微修改的示例脚本版本)中将其转换为PDF.
但是,当我exec的 PHP中的命令来运行节点脚本时,出现以下错误:
(node:14832) UnhandledPromiseRejectionWarning: Error: Failed to launch chrome!
[0424/165455.239499:ERROR:icu_util.cc(133)] Invalid file descriptor to ICU data received.
[0424/165455.239717:FATAL:content_main_delegate.cc(53)] Check failed: false.
#0 0x55f27f255b0c base::debug::StackTrace::StackTrace()
#1 0x55f27f26e780 logging::LogMessage::~LogMessage()
#2 0x55f27d5f7d23 content::ContentMainDelegate::TerminateForFatalInitializationError()
#3 0x55f27ef90deb content::ContentMainRunnerImpl::Initialize()
#4 0x55f27ef9ab72 service_manager::Main()
#5 0x55f27ef8ff14 content::ContentMain()
#6 0x55f28309f9b9 headless::(anonymous namespace)::RunContentMain()
#7 0x55f28309fa42 headless::HeadlessBrowserMain()
#8 0x55f27ef97f9d headless::HeadlessShellMain()
#9 0x55f27d5f61ac ChromeMain
#10 0x7efcaad45c05 __libc_start_main
#11 0x55f27d5f602a _start
Run Code Online (Sandbox Code Playgroud)
PHP正在与apache用户一起运行.但是,如果我与我的用户运行相同的脚本,它可以完美地工作.当我在使用su - apache -c 'node ...'它的终端中执行时再次抛出上述错误.
是什么导致错误?与apache用户权限相关的东西?我跟着所有麻烦的导游,但此刻我没有运气.
可以使用puppeteer调整浏览器窗口的大小吗?我知道有page.setViewport,但是有什么类似的东西browser.setViewport吗?如果您运行的是无头版本,听起来似乎没有什么区别,但是如果您实际显示的是窗口,这可能会很有用,我想执行以下操作:
const puppeteer = require("puppeteer");
(async () => {
let browser = await puppeteer.launch({
headless: false
});
await browser.setViewport({
width: 100,
height: 100,
});
})();
Run Code Online (Sandbox Code Playgroud) puppeteer ×10
node.js ×3
chromium ×2
javascript ×2
apache ×1
automation ×1
centos7 ×1
docker ×1
headless ×1
npm ×1
php ×1
shopware ×1
shopware6 ×1
web-scraping ×1
webgl ×1