diff --git a/scrape.sh b/scrape.sh index 4b86f99..2142a69 100755 --- a/scrape.sh +++ b/scrape.sh @@ -29,6 +29,8 @@ function usage { makes the scraper include past events. Please note that this might take a while depending on the number of past events. + --no-headless The scraper will not run in headless mode. + NOTE: Events and pages needs to be public. Private events or pages are not yet supported. diff --git a/src/logic.js b/src/logic.js index 1c0f6f9..9022bba 100644 --- a/src/logic.js +++ b/src/logic.js @@ -77,6 +77,7 @@ const parse_args = (args) => { const get_upcoming_events = !pathOr(false, ['skip-upcoming-events'], argv); const get_past_events = pathOr(false, ['past-events'], argv); + const headless = pathOr(true, ['headless'], argv); return { page_ids: [ @@ -90,6 +91,7 @@ const parse_args = (args) => { image_directory, get_upcoming_events, get_past_events, + headless, }; }; @@ -244,9 +246,9 @@ const map_event = ({ node: event }) => { }; }; -const open_browser = async () => { +const open_browser = async ({ headless }) => { const browser = await puppeteer.launch({ - headless: true, + headless, args: ['--disable-dev-shm-usage'], }); return browser; diff --git a/src/scrape.js b/src/scrape.js index 6ae98ee..014a3fb 100644 --- a/src/scrape.js +++ b/src/scrape.js @@ -19,6 +19,7 @@ const { images, output, page_ids, + headless, } = parse_args(process.argv.slice(2)); (async () => { @@ -27,7 +28,7 @@ const { } const previous_events = await read_previous_events(event_file); - const browser = await open_browser(); + const browser = await open_browser({ headless }); let events = []; diff --git a/tests/parse_args.test.js b/tests/parse_args.test.js index ba3cb1d..9b706af 100644 --- a/tests/parse_args.test.js +++ b/tests/parse_args.test.js @@ -127,4 +127,14 @@ describe('test parse args', () => { const res = parse_args(['--past-events']); expect(res.get_past_events).toEqual(true); }); + + it('parses no-headless option to true', () => { + const res = parse_args(['']); + expect(res.headless).toBe(true); + }); + + it('parses no-headless option to false', () => { + const res = parse_args(['--no-headless']); + expect(res.headless).toBe(false); + }); });