HyeonJun Jeon

[Fix] Enable headless mode

...@@ -11,8 +11,14 @@ async function login(id, pw) { ...@@ -11,8 +11,14 @@ async function login(id, pw) {
11 try { 11 try {
12 //for visibility, headless: false 12 //for visibility, headless: false
13 const browser = await puppeteer.launch({ 13 const browser = await puppeteer.launch({
14 - headless: false, 14 + headless: true,
15 - args: ["--window-size=1920,1080"], 15 + args: [
16 + "--window-size=1920x1080",
17 + "--start-maximized",
18 + "--no-sandbox",
19 + "--disable-dev-shm-usage",
20 + "--lang=ko",
21 + ],
16 }); 22 });
17 23
18 const page = await browser.newPage(); 24 const page = await browser.newPage();
...@@ -40,11 +46,12 @@ async function login(id, pw) { ...@@ -40,11 +46,12 @@ async function login(id, pw) {
40 return false; 46 return false;
41 } else { 47 } else {
42 // 내 강의실 48 // 내 강의실
43 - let selector =
44 - "#visual > div > div.xn-main-login-container > div:nth-child(2) > div.xn-main-link-wrap.xn-main-lms-link-wrap > a";
45 - await page.waitForSelector(selector);
46 - await Promise.all([page.click(selector), page.waitForNavigation()]);
47 49
50 + // let selector =
51 + // "#visual > div > div.xn-main-login-container > div:nth-child(2) > div.xn-main-link-wrap.xn-main-lms-link-wrap > a";
52 + // await page.waitForSelector(selector);
53 + // await Promise.all([page.click(selector), page.waitForNavigation()]);
54 + await page.goto("https://khcanvas.khu.ac.kr/");
48 return page; 55 return page;
49 } 56 }
50 } catch (err) { 57 } catch (err) {
...@@ -55,7 +62,7 @@ async function login(id, pw) { ...@@ -55,7 +62,7 @@ async function login(id, pw) {
55 //function that get your peed for your Ecampus calendar 62 //function that get your peed for your Ecampus calendar
56 async function getPeed(page) { 63 async function getPeed(page) {
57 selector = "#global_nav_calendar_link > div.menu-item-icon-container > svg"; 64 selector = "#global_nav_calendar_link > div.menu-item-icon-container > svg";
58 - await page.waitForSelector(selector); 65 + await page.waitForSelector(selector, { timeout: 1000 });
59 await Promise.all([page.click(selector), page.waitForNavigation()]); 66 await Promise.all([page.click(selector), page.waitForNavigation()]);
60 67
61 selector = "#calendar-feed > button"; 68 selector = "#calendar-feed > button";
......
...@@ -7,9 +7,14 @@ router.post("/", async (req, res) => { ...@@ -7,9 +7,14 @@ router.post("/", async (req, res) => {
7 console.log(`listened /login ${req.body.id} ${req.body.pw}`); 7 console.log(`listened /login ${req.body.id} ${req.body.pw}`);
8 const page = await login(req.body.id, req.body.pw); 8 const page = await login(req.body.id, req.body.pw);
9 if (page) { 9 if (page) {
10 + try {
10 const peed = await getPeed(page); 11 const peed = await getPeed(page);
11 res.send(peed); 12 res.send(peed);
12 - } else res.send("failed"); 13 + } catch (e) {
14 + console.log(e);
15 + res.send("error");
16 + }
17 + } else res.send("login failed");
13 }); 18 });
14 19
15 module.exports = router; 20 module.exports = router;
......
...@@ -34,6 +34,7 @@ const Debug = () => { ...@@ -34,6 +34,7 @@ const Debug = () => {
34 //result = login(state.input1, state.input2); 34 //result = login(state.input1, state.input2);
35 break; 35 break;
36 case "server": 36 case "server":
37 + setState({ ...state, output: "loading..." });
37 axios 38 axios
38 .post("http://localhost:3001/login/", { 39 .post("http://localhost:3001/login/", {
39 id: state.input1, 40 id: state.input1,
......