summaryrefslogtreecommitdiff
path: root/src/handlers/launchUserSession.js
diff options
context:
space:
mode:
authoreug-vs <eug-vs@keemail.me>2020-11-14 21:27:59 +0300
committereug-vs <eug-vs@keemail.me>2020-11-14 21:35:22 +0300
commit25633772f607a61cbb4a18f34c523d007dbc2c6b (patch)
treebb50ff4394778beff87e4e6d6ade03f455e8483a /src/handlers/launchUserSession.js
parent61b16a068ac2bb4d8576d9a8aeb0f3f572587eed (diff)
downloadbsu-fantom-25633772f607a61cbb4a18f34c523d007dbc2c6b.tar.gz
feat: use multiple contexts of one browser
Diffstat (limited to 'src/handlers/launchUserSession.js')
-rw-r--r--src/handlers/launchUserSession.js32
1 files changed, 14 insertions, 18 deletions
diff --git a/src/handlers/launchUserSession.js b/src/handlers/launchUserSession.js
index 44f2193..5e490e0 100644
--- a/src/handlers/launchUserSession.js
+++ b/src/handlers/launchUserSession.js
@@ -1,27 +1,23 @@
-const puppeteer = require('puppeteer');
const { clickElementBySelector } = require('./utils.js');
const { EDUFPMI_URL } = process.env;
-const launchUserSession = (user, headless = true) => puppeteer.launch({
- headless,
- args: ['--no-sandbox']
-}).then(async browser => {
- const { username, password } = user;
- const page = await browser.newPage();
+const launchUserSession = async (user, browser) => {
+ const { username, password } = user;
+ const page = await browser.newPage();
- // Login
- await page.goto(EDUFPMI_URL, { waitUntil: 'domcontentloaded' });
- await page.type('input#username', username);
- await page.type('input#password', password);
- await Promise.all([
- clickElementBySelector(page, 'button#loginbtn'),
- page.waitForNavigation()
- ]);
- console.log(`Logged in as ${username}`);
+ // Login
+ await page.goto(EDUFPMI_URL, { waitUntil: 'domcontentloaded' });
+ await page.type('input#username', username);
+ await page.type('input#password', password);
+ await Promise.all([
+ clickElementBySelector(page, 'button#loginbtn'),
+ page.waitForNavigation()
+ ]);
+ console.log(`Logged in as ${username}`);
- return browser;
- });
+ return page;
+};
module.exports = launchUserSession;