如何使用puppeteer自动执行Amazon Connect CCP登录? [英] How to use puppeteer to automante Amazon Connect CCP login?

查看:194
本文介绍了如何使用puppeteer自动执行Amazon Connect CCP登录?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用puppeteer来自动化我们在Amazon Connect中的代理的登录过程,但是我无法让puppeteer完成加载CCP登录页面.参见下面的代码:

const browser = await puppeteer.launch();

const page = await browser.newPage();
const url = 'https://ccalderon-reinvent.awsapps.com/connect/ccp#/';

await page.goto(url, {waitUntil: 'domcontentloaded'});

console.log(await page.content());

// console.log('waiting for username input');

// await page.waitForSelector('#wdc_username');

await browser.close();

我永远都看不到页面的内容,它超时了.难道我做错了什么?如果我使用{headless:false}启动浏览器,我将看到页面永远无法完成加载.

请注意,相同的代码在 https://www.github.com/login 上也能正常工作因此它必须特定于Connect的CCP的源代码.

解决方案

如果您是未来的人,并且无缘无故地遇到puppeteer的问题,请尝试先降级puppeteer的版本,看看问题是否仍然存在.


这似乎是Chromium开发版本73.0.3679.0的错误,错误日志说它无法以某种方式加载特定脚本,但我们仍然可以手动加载脚本.

解决方案:

使用Puppeteer 1.11.0版解决了此问题.但是,如果要使用puppeteer版本1.12.2但具有不同的Chrome版本,则可以使用executablePath参数.

以下是木偶戏中使用的各个版本(此时是答案),

  • 铬73.0.3679.0-木偶v1.12.2
  • 铬72.0.3582.0-木偶v1.11.0
  • 铬71.0.3563.0-木偶v1.9.0
  • 铬70.0.3508.0-木偶v1.7.0
  • 铬69.0.3494.0-Puppeteer v1.6.2

我检查了本地安装的chrome,它正确加载了页面,

$(which google-chrome) --version
Google Chrome 72.0.3626.119

注意:操纵up的团队在其文档中建议专门使用代码随附的镶边(很可能是最新的开发人员版本),而不要使用其他修订版本.

我还对代码进行了一些编辑,以在完成所有网络请求并且username输入为可见时完成加载.

const puppeteer = require("puppeteer");
(async () => {
  const browser = await puppeteer.launch({
    headless: false,
    executablePath: "/usr/bin/google-chrome"
  });

  const page = await browser.newPage();
  const url = "https://ccalderon-reinvent.awsapps.com/connect/ccp#/";

  await page.goto(url, { waitUntil: "networkidle0" });

  console.log("waiting for username input");
  await page.waitForSelector("#wdc_username", { visible: true });

  await page.screenshot({ path: "example.png" });
  await browser.close();
})();

可以通过多种方式获得特定的修订号,一种是检查puppeteer软件包的package.json. 1.11.0的网址是

https://github.com/GoogleChrome/puppeteer/blob/v1.11.0/package.json

如果您希望自动化下载chrome版本,可以使用browserFetcher获取特定版本.

const browserFetcher = puppeteer.createBrowserFetcher();
const revisionInfo = await browserFetcher.download('609904'); // chrome 72 is 609904
const browser = await puppeteer.launch({executablePath: revisionInfo.executablePath})

结果:

I'm trying use puppeteer to automate the login process for our agents in Amazon Connect however I can't get puppeteer to finish loading the CCP login page. See code below:

const browser = await puppeteer.launch();

const page = await browser.newPage();
const url = 'https://ccalderon-reinvent.awsapps.com/connect/ccp#/';

await page.goto(url, {waitUntil: 'domcontentloaded'});

console.log(await page.content());

// console.log('waiting for username input');

// await page.waitForSelector('#wdc_username');

await browser.close();

I can never see the content of the page, it times out. Am I doing something wrong? If I launch the browser with { headless: false } I can see the page never finishes loading.

Please note the same code works fine with https://www.github.com/login so it must be something specific to the source code of Connect's CCP.

解决方案

In case you are from future and having problem with puppeteer for no reason, try to downgrade the puppeteer version first and see if the issue persists.


This seems like a bug with Chromium Development Version 73.0.3679.0, The error log said it could not load specific script somehow, but we could still load the script manually.

The Solution:

Using Puppeteer version 1.11.0 solved this issue. But if you want to use puppeteer version 1.12.2 but with a different chromium revision, you can use the executablePath argument.

Here are the respective versions used on puppeteer (at this point of answer),

  • Chromium 73.0.3679.0 - Puppeteer v1.12.2
  • Chromium 72.0.3582.0 - Puppeteer v1.11.0
  • Chromium 71.0.3563.0 - Puppeteer v1.9.0
  • Chromium 70.0.3508.0 - Puppeteer v1.7.0
  • Chromium 69.0.3494.0 - Puppeteer v1.6.2

I checked my locally installed chrome,which was loading the page correctly,

$(which google-chrome) --version
Google Chrome 72.0.3626.119

Note: The puppeteer team suggested on their doc to specifically use the chrome provided with the code (most likely the latest developer version) instead of using different revisions.

Also I edited the code a little bit to finish loading when all network requests is done and the username input is visible.

const puppeteer = require("puppeteer");
(async () => {
  const browser = await puppeteer.launch({
    headless: false,
    executablePath: "/usr/bin/google-chrome"
  });

  const page = await browser.newPage();
  const url = "https://ccalderon-reinvent.awsapps.com/connect/ccp#/";

  await page.goto(url, { waitUntil: "networkidle0" });

  console.log("waiting for username input");
  await page.waitForSelector("#wdc_username", { visible: true });

  await page.screenshot({ path: "example.png" });
  await browser.close();
})();

The specific revision number can be obtained in many ways, one is to check the package.json of puppeteer package. The url for 1.11.0 is,

https://github.com/GoogleChrome/puppeteer/blob/v1.11.0/package.json

If you like to automate the chrome revision downloading, you can use browserFetcher to fetch specific revision.

const browserFetcher = puppeteer.createBrowserFetcher();
const revisionInfo = await browserFetcher.download('609904'); // chrome 72 is 609904
const browser = await puppeteer.launch({executablePath: revisionInfo.executablePath})

Result:

这篇关于如何使用puppeteer自动执行Amazon Connect CCP登录?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆