简体   繁体   中英

I wonder if I can run puppeteer on the webbrowser?

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. :(

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM