Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Error: Evaluation failed: Invalid arguments: should be exactly one string. | Puppeteer .evaluate() error

So this is the first time I've used puppeteer for testing purposes. But I've run into a strange error when running the

what I'm trying to do is run this function in the page, however

const puppeteer = require('puppeteer');   
let browser, page,
//evaluates to file://C:/Users/chris/Google Drive/code projects/text translation sheet/test/src/index.html
    htmlFilepath = "file://" + path.resolve(__dirname, "src/index.html");
browser = await puppeteer.launch();
page = await browser.newPage();
await page.goto(htmlFilepath);   
page.exposeFunction(getMaxWordsInContentArea.name, getMaxWordsInContentArea)
      
const lastWordThatFit = await page.evaluate(function(){
          
    const el = document.querySelector('.line__target-language-text')
    const elContainer = el.parent;
    const lastFitWordIndex = getMaxWordsInContentArea(el,elContainer,["Call", "me", "Ishmael.", "Some", "years", "ago—never", "mind", "how", "long", "precisely—having", "little", "or", "no", "money", "in", "my", "purse,", "and", "nothing", "particular", "to", "interest", "me", "on", "shore,", "I", "thought", "I", "would", "sail", "about", "a", "little", "and", "see", "the", "watery", "part", "of", "the", "world.", "It", "is", "a", "way", "I", "have", "of", "driving", "off", "the", "spleen", "and", "regulating", "the", "circulation."])  
                    
    return lastFitWordIndex
});

Anybody see anything wrong with this or have familiarity with this error?

like image 338
LeviathanTheDapper Avatar asked Oct 19 '25 13:10

LeviathanTheDapper


1 Answers

Forgot to include the await in front of page.exposeFunction(getMaxWordsInContentArea.name, getMaxWordsInContentArea).

Shoutout to @ZenMonkey for pushing me to dig deeper.

like image 172
LeviathanTheDapper Avatar answered Oct 21 '25 02:10

LeviathanTheDapper



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!