HyeonJun Jeon

[Fix] Enable headless mode

......@@ -11,8 +11,14 @@ async function login(id, pw) {
try {
//for visibility, headless: false
const browser = await puppeteer.launch({
headless: false,
args: ["--window-size=1920,1080"],
headless: true,
args: [
"--window-size=1920x1080",
"--start-maximized",
"--no-sandbox",
"--disable-dev-shm-usage",
"--lang=ko",
],
});
const page = await browser.newPage();
......@@ -40,11 +46,12 @@ async function login(id, pw) {
return false;
} else {
// 내 강의실
let selector =
"#visual > div > div.xn-main-login-container > div:nth-child(2) > div.xn-main-link-wrap.xn-main-lms-link-wrap > a";
await page.waitForSelector(selector);
await Promise.all([page.click(selector), page.waitForNavigation()]);
// let selector =
// "#visual > div > div.xn-main-login-container > div:nth-child(2) > div.xn-main-link-wrap.xn-main-lms-link-wrap > a";
// await page.waitForSelector(selector);
// await Promise.all([page.click(selector), page.waitForNavigation()]);
await page.goto("https://khcanvas.khu.ac.kr/");
return page;
}
} catch (err) {
......@@ -55,7 +62,7 @@ async function login(id, pw) {
//function that get your peed for your Ecampus calendar
async function getPeed(page) {
selector = "#global_nav_calendar_link > div.menu-item-icon-container > svg";
await page.waitForSelector(selector);
await page.waitForSelector(selector, { timeout: 1000 });
await Promise.all([page.click(selector), page.waitForNavigation()]);
selector = "#calendar-feed > button";
......
......@@ -7,9 +7,14 @@ router.post("/", async (req, res) => {
console.log(`listened /login ${req.body.id} ${req.body.pw}`);
const page = await login(req.body.id, req.body.pw);
if (page) {
const peed = await getPeed(page);
res.send(peed);
} else res.send("failed");
try {
const peed = await getPeed(page);
res.send(peed);
} catch (e) {
console.log(e);
res.send("error");
}
} else res.send("login failed");
});
module.exports = router;
......
......@@ -34,6 +34,7 @@ const Debug = () => {
//result = login(state.input1, state.input2);
break;
case "server":
setState({ ...state, output: "loading..." });
axios
.post("http://localhost:3001/login/", {
id: state.input1,
......