Well.., I am new to puppeteer and electron too.
I have a basic puppeteer code working as below :
const puppeteer = require('puppeteer');
(async () =>
{
const browser = await puppeteer.launch({ headless: false });
const page = await browser.newPage();
await page.setViewport({ width: 1366, height: 768});
await page.goto('https://www.google.co.in', {waitUntil: 'networkidle2'});
})();
That's great. Now i do not wants to open a browser whenever my electron app starts. Rather i want to open it on a particular event and within a javascript function. Which will be called whenever i want. As below :
global.RunCommand = function(param)
{
const browser = await puppeteer.launch({ headless: false });
const page = await browser.newPage();
await page.setViewport({ width: 1366, height: 768});
await page.goto('https://www.google.co.in', {waitUntil: 'networkidle2'});
return 'Done : ' + param;
}
which throws :
const browser = await puppeteer.launch({ headless: false });
^^^^^^^^^
SyntaxError: Unexpected identifier
at createScript (vm.js:80:10)
at Object.runInThisContext (vm.js:139:10)
at Module._compile (module.js:606:28)
at Object.Module._extensions..js (module.js:653:10)
at Module.load (module.js:561:32)
at tryModuleLoad (module.js:504:12)
at Function.Module._load (module.js:496:3)
Any help will be appreciated and thanks in advance.
pupeeteeris not anelectronproject