1

I'm receiving an error that says "puppeteer is not defined" when it is clearly in the only javaScript file.

How do i get the JavaScript/single page html project to recognize the puppeteer module? I have already looked into this potential answer;[Nodejs. Proper way to include modules, however it does not help.

(The goal is to launch the html page, enter a url from booking.com, click the button, and have the scraped hotel name, rating, etc returned in the console)

app.js

function main()
{
    var Url = document.getElementById('inputUrl').value

    const puppeteer = require('puppeteer');

    let bookingUrl = Url;
    (async () => {
        const browser = await puppeteer.launch({ headless: true });
        const page = await browser.newPage();
        await page.goto(bookingUrl);
        await page.waitForSelector('div.sr_property_block[data-hotelid]');
        let hotelData = await page.evaluate(() => {
...
...
...
}

index.html

<!DOCTYPE html>
 <html lang="en">
    <head>
        <meta charset="utf-8">
        <script src="app.js" type="text/javascript"></script> 
        <meta name="description" content="">
        <link rel="stylesheet" href="">
    </head>
    <body>
        <input id = "inputUrl" type="text" placeholder = "type url here"/>
        <button id = "button" button onclick="main();"> click</button>
    </body>
</html>
IscA
  • 59
  • 8
  • You need a server. You cannot run puppeteer on the client-side. – Thomas Dondorf Apr 20 '20 at 14:15
  • Does this answer your question? [How to make Puppeteer work with a ReactJS application on the client-side](https://stackoverflow.com/questions/55031823/how-to-make-puppeteer-work-with-a-reactjs-application-on-the-client-side) – Thomas Dondorf Apr 20 '20 at 14:15

1 Answers1

1

Puppeteer is a library that requires a server (like node.js), you can't run it on the client side.

Or Assayag
  • 5,662
  • 13
  • 57
  • 93