Puppeteer

Overriding showOpenFilePicker with Puppeteer

蹲街弑〆低调 提交于 2021-01-24 09:54:18
问题 As illustrated in here here, Puppeteer allows to override Javascript functions. I want to override showOpenFilePicker function. That is, when the showOpenFilePicker invoked by the web page. I want to run another function before the showOpenFilePicker. const puppeteer = require("puppeteer"); (async () => { const browser = await puppeteer.launch({ headless: false }); const page = await browser.newPage(); await page.evaluateOnNewDocument(() => { Object.defineProperty(HTMLCanvasElement.prototype,

Overriding showOpenFilePicker with Puppeteer

懵懂的女人 提交于 2021-01-24 09:54:13
问题 As illustrated in here here, Puppeteer allows to override Javascript functions. I want to override showOpenFilePicker function. That is, when the showOpenFilePicker invoked by the web page. I want to run another function before the showOpenFilePicker. const puppeteer = require("puppeteer"); (async () => { const browser = await puppeteer.launch({ headless: false }); const page = await browser.newPage(); await page.evaluateOnNewDocument(() => { Object.defineProperty(HTMLCanvasElement.prototype,

Overriding showOpenFilePicker with Puppeteer

萝らか妹 提交于 2021-01-24 09:53:58
问题 As illustrated in here here, Puppeteer allows to override Javascript functions. I want to override showOpenFilePicker function. That is, when the showOpenFilePicker invoked by the web page. I want to run another function before the showOpenFilePicker. const puppeteer = require("puppeteer"); (async () => { const browser = await puppeteer.launch({ headless: false }); const page = await browser.newPage(); await page.evaluateOnNewDocument(() => { Object.defineProperty(HTMLCanvasElement.prototype,

Handling events from puppeteer's page context outside evaluate method

℡╲_俬逩灬. 提交于 2021-01-24 09:47:23
问题 My goal is to open puppeteer-chromium instance as a child process in nodejs environment and listen to all clicks that user will make in a way that these events are accessible from parent process. So I think stream of events is needed but I have no idea how to send them from evaluate method (process object is not accessible in that context - 'process is undefined' in logs of chromium). Currently I'm trying to add click listener inside page's context but is there any way to obtain those events

Puppeteer C#: Connecting to Running Chrome Instance

别等时光非礼了梦想. 提交于 2021-01-24 07:09:46
问题 I am currently running PuppeteerSharp v1.19.0 to launch a browser and scrape web pages. The need has come up to be able to connect to an existing chrome instance and automate tasks. How can I achieve this one PuppeteerSharp? Via the following, I'm able to launch Chrome instead of Chromium with PuppeteersSharp but I haven't found how I'm able to connect to an existing instance of Chrome. All help is appreciated. using PuppeteerSharp; new BrowserFetcher().DownloadAsync(BrowserFetcher

Puppeteer C#: Connecting to Running Chrome Instance

两盒软妹~` 提交于 2021-01-24 07:05:55
问题 I am currently running PuppeteerSharp v1.19.0 to launch a browser and scrape web pages. The need has come up to be able to connect to an existing chrome instance and automate tasks. How can I achieve this one PuppeteerSharp? Via the following, I'm able to launch Chrome instead of Chromium with PuppeteersSharp but I haven't found how I'm able to connect to an existing instance of Chrome. All help is appreciated. using PuppeteerSharp; new BrowserFetcher().DownloadAsync(BrowserFetcher

抓取网页生成 PDF

我的未来我决定 提交于 2021-01-22 23:41:43
看到自己喜欢的在线文档,是不是总想保存下来慢慢学习。可是苦于没有现成的工具,这里我来介绍两个 JS 类库,只需要简单封装一下,从此想抓哪里抓哪里。 一、使用 Phantomjs 1.简单使用 1 const phantom = require('phantom' ); 2 (async function () { 3 const instance = await phantom.create(); 4 const page = await instance.createPage(); 5 await page.on('onResourceRequested', function (requestData) { 6 console.info('Requesting' , requestData.url); 7 }); 8 const status = await page.open('http://jartto.wang' ); 9 await page.render('jarttoTest.pdf' ); 10 await instance.exit(); 11 })(); 上面是一个完整的示例,我们来看看最核心的部分,不妨放大一下: 1 page.open(address, function (status) { 2 if (status !== 'success' ) { 3

puppeteer: How to wait for pages in SPA's?

折月煮酒 提交于 2021-01-22 05:23:07
问题 I am trying to navigate through an SPA with puppeteer, the problem I am facing here is that I am unable to wait for the page to load then proceed with my program. I fill a form and then click submit, depending on the contents of the form, different pages can be loaded so I can't use page.waitFor(Selector) as there can be many different pages depending on the input. I tried using waitUntil: load, networkidle2, networkidle0, domcontentloaded but all of them trigger before the elements are

How to await inside setInterval in JS?

风流意气都作罢 提交于 2021-01-21 03:55:25
问题 I have a code segment that looks like this: async function autoScroll(page, maxDate = null) { await page.evaluate(async () => { await new Promise(async (resolve, reject) => { try { const scrollHeight = document.body.scrollHeight; let lastScrollTop = 0; const interval = setInterval(async () => { window.scrollBy(0, scrollHeight); const scrollTop = document.documentElement.scrollTop; let lastDate = null; if (maxDate) { const html = new XMLSerializer().serializeToString(document.doctype) +

How to await inside setInterval in JS?

孤街醉人 提交于 2021-01-21 03:53:05
问题 I have a code segment that looks like this: async function autoScroll(page, maxDate = null) { await page.evaluate(async () => { await new Promise(async (resolve, reject) => { try { const scrollHeight = document.body.scrollHeight; let lastScrollTop = 0; const interval = setInterval(async () => { window.scrollBy(0, scrollHeight); const scrollTop = document.documentElement.scrollTop; let lastDate = null; if (maxDate) { const html = new XMLSerializer().serializeToString(document.doctype) +