2

So I have an line which I can just paste manually into the Devtools Console in a browser. Is there any way to make pupeteer execute it? After searching I havent found anything, sorry if this has been answered already, I am quite new.

For those who care its an Line to buy an listing of an Item, Example:

BuyMarketListing('listing', '3555030760772417847', 730, '2', '24716958303')

  • Why would you need to run it in the console *specifically* when a huge core concept of Puppeteer is to allow you to run any arbitrary JavaScript you want/need directly…? – esqew Jan 26 '22 at 20:31
  • Does this answer your question? [How to execute a javascript code in puppeteer](https://stackoverflow.com/questions/58610018/how-to-execute-a-javascript-code-in-puppeteer) – esqew Jan 26 '22 at 20:31
  • I cant get this line to get executed thats the problem – Bruh item market action Jan 26 '22 at 20:35
  • Then why not make your question about that and include your code as a [mre], per [ask]? – esqew Jan 26 '22 at 20:36

1 Answers1

2

It looks like you're looking for page.evaluate(). Here is a link to the Puppeteer's documentation for it. You can pass in a string or an anonymous function containing the lines you want to evaluate in the page.

const puppeteer = require('puppeteer');

(async () => {
  const browser = await puppeteer.launch();
  const page = await browser.newPage();
  await page.goto('https://example.com');

  await page.evaluate(() => { insert lines here }); // page.evaluate() should run the lines in the browser console

  await browser.close();
})();
shaun
  • 66
  • 2
  • 6