-3

I made test.js and testweb.html.

this is test.js

const main = async () => {
    console.log("main!");
};

async function test(){
    const puppeteer = require('puppeteer');
    let page;
    const browser = await puppeteer.launch({
       headless : false
    });
   page = await browser.newPage();
   await page.goto('https://www.google.com/', {waitUntil:'networkidle2'});
   console.log("test()!");
}
main();

this is testweb.html

<!DOCTYPE html>
<html>
<head>
    <title>test web page</title>
</head>
<body>
<input type="button" title="login" alt="login" value="subject" class="btn" id="log.login" onclick = "test()">
<script type="text/javascript" language="javascript" src ="./test.js"></script>
</body>

When running the html code, the following error occurs :Uncaught (in promise) ReferenceError: require is not defined

It's difficult for me to solve this. If you can solve this problem, please let me know the solution. :(

hanrabong
  • 1
  • 1
  • It seems that you need more programming experience before doing stuff like this. There is so much wrong with this question. I can point you towards Ajax for requests https://www.w3schools.com/xml/ajax_intro.asp or use the jQuery equivalent. To solve this question we would need to write you a whole programming lesson which makes this unanswerable. – Jonathan Nielsen May 08 '20 at 10:09
  • 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 May 08 '20 at 10:33

1 Answers1

1

Unfortunately puppeteer is designed to be run on your computer with node.js. I would recommend digging into some example projects to get a grasp what you can do with the package. Reference: https://github.com/checkly/puppeteer-examples

jasonandmonte
  • 1,869
  • 2
  • 15
  • 24