I am exporting test function this way: export default test;
const puppeteer = require('puppeteer');
async function test() {
const browser = await puppeteer.launch();
const page = await browser.newPage();
await page.goto('https://example.com');
// Get the "viewport" of the page, as reported by the page.
const dimensions = await page.evaluate(() => {
return {
width: document.documentElement.clientWidth,
height: document.documentElement.clientHeight,
deviceScaleFactor: window.devicePixelRatio
};
});
console.log('Dimensions:', dimensions);
await browser.close();
};
I am importing above example.js file by import test from './example'. In that I am getting error Uncaught Error: Cannot find module 'ws'
at webpackMissingModule (WebSocketTransport.js:16)
at Object../node_modules/puppeteer/lib/WebSocketTransport.js
I installed ws, but still the same error.
Looks like it is because I am trying to bundle puppeteer to use in a web application. How can I solve this?