'Pupeteer execute command in Devtools Console

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')



Solution 1:[1]

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();
})();

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1