Puppeteer

Puppeteer - How can I get the current page (application/pdf) as a buffer or file?

泄露秘密 提交于 2019-12-11 06:01:47
问题 Using Puppeteer (https://github.com/GoogleChrome/puppeteer), I have a page that's a application/pdf . With headless: false , the page is loaded though the Chromium PDF viewer, but I want to use headless. How can I download the original .pdf file or use as a blob with another library, such as (pdf-parse https://www.npmjs.com/package/pdf-parse)? 回答1: Since Puppeteer does not currently support navigation to a PDF document in headless mode via page.goto() due to the upstream issue, you can use

Converting a raw cookie to be accepted by puppeteer

て烟熏妆下的殇ゞ 提交于 2019-12-11 05:36:45
问题 I want to pass session from passport.js to puppeteer. I used var cookies = req.cookies; in order to get the cookies value. I console.logged it and it is something like this: { 'connect.sid': 's:qX4ZrttrjydtrjkgsdghsdghrewynZj4Ew2OUh.tTSILkcvgsegsegsegsr99gmW5 0XLcJefM' } I thought that it would be as easy as to pass this value to puppeteer. But puppeteer has a page.setCookie() function that its format is this: page.setCookie(...cookies) ...cookies <...Object> name <string> required value

Puppeteer chrome allow multiple file download

爱⌒轻易说出口 提交于 2019-12-11 05:32:18
问题 I am trying scrape one site will multiple pdf files. But after downloading the first one, chrome asks me to allow the site to download multiple files. Can we allow this while launching the browser? This is the code which works once I allow manually and downloads all the files. for(selector of selectors){ await this.currentPage._client.send('Page.setDownloadBehavior', { behavior: 'allow', downloadPath: downloadFilePath }); await this.currentPage.waitFor(1000); await this.currentPage.evaluate

jasmine not working with puppeteer

笑着哭i 提交于 2019-12-11 05:17:46
问题 I'm trying to run a simple test in jasmine using puppeteer, however I can't get puppeteer to work when i use it in my test script: const puppeteer = require('puppeteer'); describe("Jasmine puppeteer", function() { let browser; let page; beforeAll(() => { browser = await puppeteer.launch({headless: false}); page = await browser.newPage(); await page.goto('chrome://newtab'); await page.screenshot({path: 'a.png'}); }) it("jasmine puppeteer", () => { expect(await page.title()).toBe(""); done(); }

node.js async/await or generic-pool causes infinite loop?

杀马特。学长 韩版系。学妹 提交于 2019-12-11 05:16:56
问题 I was trying to create an automation script for work, it is supposed to use multiple puppeteer instances to process input strings simultaneously. the task queue and number of puppeteer instances are controlled by the package generic-pool, strangely, when i run the script on ubuntu or debian, it seems that it fells into an infinite loop. tries to run infinite number of puppeteer instances. while when run on windows, the output was normal. const puppeteer = require('puppeteer'); const

Is it possible to click every element on a page with dynamic content?

心已入冬 提交于 2019-12-11 05:14:29
问题 Is it possible with puppeteer to go to a website, test if every content on the page is clickable/links working and all this with dynamic content, so I can automate my UI-Testing? The problem is, that the content is changing and not every element has an id but I still want every element checked for an page. 回答1: Yes, in general it is possible to click on any element on the page. Even elements without an ID or class that identifies them, have a selector. It might just be more complicated to get

How to collect several Json responses after I made page.click event?

喜夏-厌秋 提交于 2019-12-11 04:29:57
问题 I have two pages. On First page I make the click '#btnSearch' and the Second pages loads several JSON files as response. I need to collect the data of those JSON files into array results . My problem is that results are empty . await page.goto(url, { waitUntil: 'load'); await page.click('#btnSearch'); const results = []; await page.on('response', async (response) => { if (response.url() && response.status() == 200) { console.log('XHR response received'); results.push(await response.json()); }

Puppeteer: wait for request to finish after dropdown selection

北城余情 提交于 2019-12-11 02:09:06
问题 I am writing a test for my React application. I have two dropdowns. Once a selection is made in the first one, a fetch request is trigged and the data from that fetch request is used to populate the second dropdown. My test looks like this: test("fruit dropdown becomes enabled when food type fruit is selected", async () => { await page.select('[data-testid="food"]', "fruit"); // this makes a selection in the drop down and fires a request // I should wait for request to finish before doing

Unhandled promise rejection (rejection id: 1): Error: kill ESRCH

倖福魔咒の 提交于 2019-12-11 01:29:34
问题 I've made some research on the Web and SOF, but found nothing really helpful on that error. I installed Node and Puppeteer with Windows 10 Ubuntu Bash, but didn't manage to make it work, yet I manage to make it work on Windows without Bash on an other machine. My command is : node index.js My index.js tries to take a screenshot of a page : const puppeteer = require('puppeteer'); async function run() { const browser = await puppeteer.launch(); const page = await browser.newPage(); await page

Setting specific chrome flags in puppeteer (enable and disable)

寵の児 提交于 2019-12-11 00:55:42
问题 I'm trying to add specific flags of chrome (flags that are found in "chrome://flags/") to the running of my browser in the tests. The flags I'm trying to enable are: "#enable-webgl-draft-extensions" "#shared-array-buffer" and to disable: "#enable-asm-webassembly" In the regular chrome command line it looks like this: "--flag-switches-begin --enable-webgl-draft-extensions --enable-features=SharedArrayBuffer --disable-features=AsmJsToWebAssembly --flag-switches-end" If i add these criteria in